• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15
16import mindspore.context as context
17import mindspore.nn as nn
18from mindspore.common.api import ms_function
19from mindspore.ops import operations as P
20
21context.set_context(device_target="Ascend")
22
23
24class Net(nn.Cell):
25    def __init__(self):
26        super(Net, self).__init__()
27        self.matmul = P.MatMul(transpose_b=True)
28        self.bias_add = P.BiasAdd()
29
30    @ms_function
31    def construct(self, x, w, b):
32        return self.bias_add(self.matmul(x, w), b)
33
34# def test_net():
35#     x = np.random.randn(32, 2048).astype(np.float16)
36#     w = np.random.randn(1001, 2048).astype(np.float16)
37#     b = np.random.randn(1001).astype(np.float16)
38#     FullConnection = Net()
39#     output = FullConnection(Tensor(x), Tensor(w), Tensor(b))
40#     print(output.asnumpy())
41