|
|
@@ -13,10 +13,11 @@ |
|
|
# limitations under the License. |
|
|
# limitations under the License. |
|
|
# ============================================================================ |
|
|
# ============================================================================ |
|
|
"""thor_ops""" |
|
|
"""thor_ops""" |
|
|
import mindspore as ms |
|
|
|
|
|
from mindspore.ops import prim_attr_register, PrimitiveWithInfer |
|
|
from mindspore.ops import prim_attr_register, PrimitiveWithInfer |
|
|
from mindspore.ops.composite import multitype_ops as C |
|
|
from mindspore.ops.composite import multitype_ops as C |
|
|
|
|
|
|
|
|
|
|
|
import mindspore as ms |
|
|
|
|
|
|
|
|
__all__ = ["CusBatchMatMul", |
|
|
__all__ = ["CusBatchMatMul", |
|
|
"CusCholeskyTrsm", |
|
|
"CusCholeskyTrsm", |
|
|
"CusFusedAbsMax1", |
|
|
"CusFusedAbsMax1", |
|
|
@@ -33,12 +34,31 @@ __all__ = ["CusBatchMatMul", |
|
|
|
|
|
|
|
|
class CusBatchMatMul(PrimitiveWithInfer): |
|
|
class CusBatchMatMul(PrimitiveWithInfer): |
|
|
"""CusBatchMatMul definition""" |
|
|
"""CusBatchMatMul definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Multiplies matrix `a` by matrix `b` in batch. |
|
|
|
|
|
|
|
|
|
|
|
The rank of input tensors must be `3`. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The first tensor to be multiplied. The shape of the tensor is :math:`(N, D, D)`. If |
|
|
|
|
|
- **input_y** (Tensor) - The second tensor to be multiplied. The shape of the tensor is :math:`(N, D, D)`. If |
|
|
|
|
|
`transpose_b` is True. |
|
|
|
|
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N, D, D)`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32) |
|
|
|
|
|
>>> input_y = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32) |
|
|
|
|
|
>>> cus_batch_matmul = P.CusBatchMatMul() |
|
|
|
|
|
>>> output = cus_batch_matmul(input_x, input_y) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusBatchMatMul""" |
|
|
"""init CusBatchMatMul""" |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.batch_matmul_impl import CusBatchMatMul |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x1, x2, out, dout): |
|
|
def bprop(x1, x2, out, dout): |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
@@ -54,12 +74,30 @@ class CusBatchMatMul(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusCholeskyTrsm(PrimitiveWithInfer): |
|
|
class CusCholeskyTrsm(PrimitiveWithInfer): |
|
|
"""CusCholeskyTrsm definition""" |
|
|
"""CusCholeskyTrsm definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
L * LT = A. |
|
|
|
|
|
LT * (LT)^-1 = I. |
|
|
|
|
|
return (LT)^-1. |
|
|
|
|
|
Only compute the res of the diag part of input matrix with dim 128. |
|
|
|
|
|
The rank of input tensors must be `2`. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The first tensor to be multiplied. The shape of the tensor is :math:`(N, N)`. |
|
|
|
|
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N // Split_dim, Split_dim, Split_dim)`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float32) |
|
|
|
|
|
>>> cus_choleskytrsm = P.CusCholeskyTrsm() |
|
|
|
|
|
>>> output = matmul(input_x) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusCholeskyTrsm""" |
|
|
"""init CusCholeskyTrsm""" |
|
|
self.init_prim_io_names(inputs=['x1'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.cholesky_trsm_impl import CusCholeskyTrsm |
|
|
def infer_shape(self, data1_shape): |
|
|
def infer_shape(self, data1_shape): |
|
|
ll = [] |
|
|
ll = [] |
|
|
m, _ = data1_shape |
|
|
m, _ = data1_shape |
|
|
@@ -75,13 +113,28 @@ class CusCholeskyTrsm(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusFusedAbsMax1(PrimitiveWithInfer): |
|
|
class CusFusedAbsMax1(PrimitiveWithInfer): |
|
|
"""CusFusedAbsMax1 definition""" |
|
|
"""CusFusedAbsMax1 definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Compute the abs max of Tensor input. |
|
|
|
|
|
|
|
|
|
|
|
The rank of input tensors must be `4` or `2`. |
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The first tensor to be multiplied. The shape of the tensor is :math:`(N0, M0, N1, M1)` |
|
|
|
|
|
or math:`(32, 64)`. |
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(32, 64)` or math:`(1, )`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[1, 3]), mindspore.float32) |
|
|
|
|
|
>>> cus_fused_abs_max1 = P.CusFusedAbsMax1() |
|
|
|
|
|
>>> output = cus_fused_abs_max1(input_x) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self, origin_shape=[-1, -1]): |
|
|
def __init__(self, origin_shape=[-1, -1]): |
|
|
"""init CusFusedAbsMax1""" |
|
|
"""init CusFusedAbsMax1""" |
|
|
self.init_prim_io_names(inputs=['x1'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1'], outputs=['y']) |
|
|
self.origin_shape = origin_shape |
|
|
self.origin_shape = origin_shape |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.fused_abs_max1_impl import CusFusedAbsMax1 |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x, out, dout): |
|
|
def bprop(x, out, dout): |
|
|
return (C.zeros_like(x),) |
|
|
return (C.zeros_like(x),) |
|
|
@@ -102,6 +155,21 @@ class CusFusedAbsMax1(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusImg2Col(PrimitiveWithInfer): |
|
|
class CusImg2Col(PrimitiveWithInfer): |
|
|
"""CusImg2Col definition""" |
|
|
"""CusImg2Col definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Img2col the feature map and the result in reorganized in NC1HWC0. |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
- **strides** (listInt) - the stride of the ops. |
|
|
|
|
|
- **ksizes** (listInt) - the kernel size of the ops. |
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The shape of the tensor is :math:`(N, C, H, W)`. |
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N * H_O * W_O, C1 * K_W * K_H * C0)`. |
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[32, 3, 224, 224]), mindspore.float16) |
|
|
|
|
|
>>> cusimg2col = P.CusImg2Col() |
|
|
|
|
|
>>> output = cusimg2col(input_x) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self, ksizes, strides, dilates=(1, 1, 1, 1), mode="NC1HWC0"): |
|
|
def __init__(self, ksizes, strides, dilates=(1, 1, 1, 1), mode="NC1HWC0"): |
|
|
@@ -111,7 +179,7 @@ class CusImg2Col(PrimitiveWithInfer): |
|
|
self.strides = strides |
|
|
self.strides = strides |
|
|
self.dilates = dilates |
|
|
self.dilates = dilates |
|
|
self.mode = mode |
|
|
self.mode = mode |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.img2col_impl import CusImg2Col |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x, out, dout): |
|
|
def bprop(x, out, dout): |
|
|
return (C.zeros_like(x),) |
|
|
return (C.zeros_like(x),) |
|
|
@@ -136,12 +204,30 @@ class CusImg2Col(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusMatMulCubeDenseLeft(PrimitiveWithInfer): |
|
|
class CusMatMulCubeDenseLeft(PrimitiveWithInfer): |
|
|
"""CusMatMulCube definition""" |
|
|
"""CusMatMulCube definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Multiplies matrix `a` by matrix `b`. |
|
|
|
|
|
|
|
|
|
|
|
The rank of input_x1 must be `4`, the fractal format of the normal matrix. |
|
|
|
|
|
The rank of input_x2 must be `2`. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x1** (Tensor) - The first tensor to be multiplied. |
|
|
|
|
|
The shape of the tensor is :math:`(N0, M0, N1, M1)`. |
|
|
|
|
|
- **input_x2** (Tensor) - The second tensor to be multiplied. The shape of the tensor is :math:`(M, C)`. |
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N, C)`. |
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) |
|
|
|
|
|
>>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16) |
|
|
|
|
|
>>> matmulcubedenseleft = P.CusMatMulCubeDenseLeft() |
|
|
|
|
|
>>> output = matmulcubedenseleft(input_x, input_y) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusMatMulCubeDenseLeft""" |
|
|
"""init CusMatMulCubeDenseLeft""" |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.matmul_cube_dense_left_impl import CusMatMulCubeDenseLeft |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x1, x2, out, dout): |
|
|
def bprop(x1, x2, out, dout): |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
@@ -157,12 +243,32 @@ class CusMatMulCubeDenseLeft(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusMatMulCubeFraczRightMul(PrimitiveWithInfer): |
|
|
class CusMatMulCubeFraczRightMul(PrimitiveWithInfer): |
|
|
"""CusMatMulCubeFraczRightMul definition""" |
|
|
"""CusMatMulCubeFraczRightMul definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Multiplies matrix `a` by matrix `b` and muls the result by scalar `c`. |
|
|
|
|
|
|
|
|
|
|
|
The rank of input_x1 tensors must be `2`. |
|
|
|
|
|
The rank of input_x2 tensors must be `4`. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x1** (Tensor) - The first tensor to be multiplied. The shape of the tensor is :math:`(N, C)`. |
|
|
|
|
|
- **input_x2** (Tensor) - The second tensor to be multiplied. |
|
|
|
|
|
The shape of the tensor is :math:`(C1, M1, C0, M0)`. |
|
|
|
|
|
- **input_x3** (Tensor) - The third tensor to be multiplied. The shape of the tensor if :math`(1, )`. |
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N, M)`. |
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x1 = Tensor(np.ones(shape=[256, 256]), mindspore.float16) |
|
|
|
|
|
>>> input_x2 = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) |
|
|
|
|
|
>>> input_x3 = Tensor(np.ones(shape=[1, ]), mindspore.float16) |
|
|
|
|
|
>>> cusmatmulfraczrightmul = P.CusMatMulCubeFraczRightMul() |
|
|
|
|
|
>>> output = cusmatmulfraczrightmul(input_x1, input_x2, input_x3) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusMatMulCubeFraczRightMul""" |
|
|
"""init CusMatMulCubeFraczRightMul""" |
|
|
self.init_prim_io_names(inputs=['x1', 'x2', 'x3'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1', 'x2', 'x3'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.matmul_cube_fracz_right_mul_impl import CusMatMulCubeFraczRightMul |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x1, x2, x3, out, dout): |
|
|
def bprop(x1, x2, x3, out, dout): |
|
|
return (C.zeros_like(x1), C.zeros_like(x2), C.zeros_like(x3)) |
|
|
return (C.zeros_like(x1), C.zeros_like(x2), C.zeros_like(x3)) |
|
|
@@ -178,6 +284,30 @@ class CusMatMulCubeFraczRightMul(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusMatMulCube(PrimitiveWithInfer): |
|
|
class CusMatMulCube(PrimitiveWithInfer): |
|
|
"""CusMatMulCube definition""" |
|
|
"""CusMatMulCube definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Multiplies matrix `a` by matrix `b`. |
|
|
|
|
|
|
|
|
|
|
|
The rank of input tensors must be `2`. |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
transpose_a (bool): If True, `a` is transposed before multiplication. Default: False. |
|
|
|
|
|
transpose_b (bool): If True, `b` is transposed before multiplication. Default: False. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The first tensor to be multiplied. The shape of the tensor is :math:`(N, C)`. If |
|
|
|
|
|
`transpose_a` is True, its shape should be :math:`(N, C)` after transposing. |
|
|
|
|
|
- **input_y** (Tensor) - The second tensor to be multiplied. The shape of the tensor is :math:`(C, M)`. If |
|
|
|
|
|
`transpose_b` is True, its shape should be :math:`(C, M)` after transpose. |
|
|
|
|
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N, M)`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float16) |
|
|
|
|
|
>>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16) |
|
|
|
|
|
>>> cusmatmulcube = P.CusMatMulCube() |
|
|
|
|
|
>>> output = matmul(input_x, input_y) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self, transpose_a=False, transpose_b=False): |
|
|
def __init__(self, transpose_a=False, transpose_b=False): |
|
|
@@ -185,7 +315,7 @@ class CusMatMulCube(PrimitiveWithInfer): |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
self.transpose_a = transpose_a |
|
|
self.transpose_a = transpose_a |
|
|
self.transpose_b = transpose_b |
|
|
self.transpose_b = transpose_b |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.matmul_cube_impl import CusMatMulCube |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x1, x2, out, dout): |
|
|
def bprop(x1, x2, out, dout): |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
@@ -213,12 +343,27 @@ class CusMatMulCube(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusMatrixCombine(PrimitiveWithInfer): |
|
|
class CusMatrixCombine(PrimitiveWithInfer): |
|
|
"""CusMatrixCombine definition""" |
|
|
"""CusMatrixCombine definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
move the batch matrix to result matrix diag part. |
|
|
|
|
|
The rank of input tensors must be `3`. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The shape of the tensor is :math:`(N, D, D)`. |
|
|
|
|
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N * D, N * D)`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32) |
|
|
|
|
|
>>> cusmatrixcombine = P.CusMatrixCombine() |
|
|
|
|
|
>>> output = cusmatrixcombine(input_x) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusMatrixCombine""" |
|
|
"""init CusMatrixCombine""" |
|
|
self.init_prim_io_names(inputs=['x'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.matrix_combine_impl import CusMatrixCombine |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x, out, dout): |
|
|
def bprop(x, out, dout): |
|
|
return (C.zeros_like(x),) |
|
|
return (C.zeros_like(x),) |
|
|
@@ -237,12 +382,28 @@ class CusMatrixCombine(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusTranspose02314(PrimitiveWithInfer): |
|
|
class CusTranspose02314(PrimitiveWithInfer): |
|
|
"""CusTranspose02314 definition""" |
|
|
"""CusTranspose02314 definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Permute input tensor with perm (0, 2, 3, 1, 4) |
|
|
|
|
|
|
|
|
|
|
|
The rank of input tensors must be `5` with format NC1HWC0. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The shape of the tensor is :math:`(N, C1, H, W, C0)`. |
|
|
|
|
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N, H, W, C1, C0)`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[32, 1, 224, 224, 16]), mindspore.float16) |
|
|
|
|
|
>>> custranspose02314 = P.CusTranspose02314() |
|
|
|
|
|
>>> output = custranspose02314(input_x) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusTranspose02314""" |
|
|
"""init CusTranspose02314""" |
|
|
self.init_prim_io_names(inputs=['x1'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.transpose02314_impl import CusTranspose02314 |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x, out, dout): |
|
|
def bprop(x, out, dout): |
|
|
return (C.zeros_like(x),) |
|
|
return (C.zeros_like(x),) |
|
|
@@ -263,12 +424,32 @@ class CusTranspose02314(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusMatMulCubeDenseRight(PrimitiveWithInfer): |
|
|
class CusMatMulCubeDenseRight(PrimitiveWithInfer): |
|
|
"""CusMatMulCubeDenseRight definition""" |
|
|
"""CusMatMulCubeDenseRight definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Multiplies matrix `a` by matrix `b`. |
|
|
|
|
|
|
|
|
|
|
|
The rank of input_x1 tensor must be `2`. |
|
|
|
|
|
The rank of input_x2 tensor must be `4`. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x** (Tensor) - The first tensor to be multiplied. The shape of the tensor is :math:`(N, C)`. |
|
|
|
|
|
- **input_y** (Tensor) - The second tensor to be multiplied. |
|
|
|
|
|
The shape of the tensor is :math:`(C1, M1, M0, C0)`. |
|
|
|
|
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N, M)`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float16) |
|
|
|
|
|
>>> input_y = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) |
|
|
|
|
|
>>> cusmatmulcubedenseright = P.CusMatMulCubeDenseRight() |
|
|
|
|
|
>>> output = cusmatmulcubedenseright(input_x, input_y) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusMatMulCubeDenseRight""" |
|
|
"""init CusMatMulCubeDenseRight""" |
|
|
self.init_prim_io_names(inputs=['x1', 'x2', 'x3'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1', 'x2', 'x3'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.matmul_cube_dense_right_impl import CusMatMulCubeDenseRight |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x1, x2, x3, out, dout): |
|
|
def bprop(x1, x2, x3, out, dout): |
|
|
return (C.zeros_like(x1), C.zeros_like(x2), C.zeros_like(x3)) |
|
|
return (C.zeros_like(x1), C.zeros_like(x2), C.zeros_like(x3)) |
|
|
@@ -284,12 +465,32 @@ class CusMatMulCubeDenseRight(PrimitiveWithInfer): |
|
|
|
|
|
|
|
|
class CusMatMulCubeFraczLeftCast(PrimitiveWithInfer): |
|
|
class CusMatMulCubeFraczLeftCast(PrimitiveWithInfer): |
|
|
"""CusMatMulCubeFraczLeftCast definition""" |
|
|
"""CusMatMulCubeFraczLeftCast definition""" |
|
|
|
|
|
""" |
|
|
|
|
|
Multiplies matrix `a` by matrix `b`. |
|
|
|
|
|
|
|
|
|
|
|
The rank of input_x1 tensor must be `4`. |
|
|
|
|
|
The rank of input_x2 tensors must be `2`. |
|
|
|
|
|
|
|
|
|
|
|
Inputs: |
|
|
|
|
|
- **input_x1** (Tensor) - The first tensor to be multiplied. |
|
|
|
|
|
The shape of the tensor is :math:`(C1, N1, N0, C0)`. |
|
|
|
|
|
- **input_x2** (Tensor) - The second tensor to be multiplied. The shape of the tensor is :math:`(C, M)`. |
|
|
|
|
|
|
|
|
|
|
|
Outputs: |
|
|
|
|
|
Tensor, the shape of the output tensor is :math:`(N, M)`. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
|
|
>>> input_x = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) |
|
|
|
|
|
>>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16) |
|
|
|
|
|
>>> cusmatmulcubefraczleftcast = P.CusMatMulCubeFraczLeftCast() |
|
|
|
|
|
>>> output = cusmatmulcubefraczleftcast(input_x, input_y) |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
@prim_attr_register |
|
|
@prim_attr_register |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
"""init CusMatMulCubeFraczLeftCast""" |
|
|
"""init CusMatMulCubeFraczLeftCast""" |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y']) |
|
|
|
|
|
|
|
|
|
|
|
from mindspore.ops._op_impl._custom_op.matmul_cube_fracz_left_cast_impl import CusMatMulCubeFraczLeftCast |
|
|
def get_bprop(self): |
|
|
def get_bprop(self): |
|
|
def bprop(x1, x2, out, dout): |
|
|
def bprop(x1, x2, out, dout): |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
return (C.zeros_like(x1), C.zeros_like(x2)) |
|
|
|