parent
8e36a4451e
commit
1d0aef57d4
@ -1,126 +0,0 @@
|
|||||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
# ============================================================================
|
|
||||||
"""learning rate generator"""
|
|
||||||
import math
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
|
|
||||||
def linear_warmup_lr(current_step, warmup_steps, base_lr, init_lr):
|
|
||||||
"""linear_warmup_lr"""
|
|
||||||
lr_inc = (float(base_lr) - float(init_lr)) / float(warmup_steps)
|
|
||||||
lr = float(init_lr) + lr_inc * current_step
|
|
||||||
return lr
|
|
||||||
|
|
||||||
|
|
||||||
def cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0, num_periods=0.5):
|
|
||||||
"""linear_warmup_lr"""
|
|
||||||
base_lr = lr
|
|
||||||
warmup_init_lr = 0
|
|
||||||
total_steps = int(max_epoch * steps_per_epoch)
|
|
||||||
warmup_steps = int(warmup_epochs * steps_per_epoch)
|
|
||||||
decay_steps = total_steps - warmup_steps
|
|
||||||
lr_each_step = []
|
|
||||||
for i in range(total_steps):
|
|
||||||
if i < warmup_steps:
|
|
||||||
lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr)
|
|
||||||
else:
|
|
||||||
# linear_decay = (total_steps - i) / decay_steps
|
|
||||||
cosine_decay = 0.5 * (1 + math.cos(math.pi * i / decay_steps))
|
|
||||||
decayed = cosine_decay
|
|
||||||
lr = base_lr * decayed
|
|
||||||
lr_each_step.append(lr)
|
|
||||||
return np.array(lr_each_step).astype(np.float32)
|
|
||||||
|
|
||||||
|
|
||||||
def warmup_cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0, num_periods=0.5):
|
|
||||||
"""warmup_cosine_annealing_lr"""
|
|
||||||
base_lr = lr
|
|
||||||
warmup_init_lr = 0
|
|
||||||
total_steps = int(max_epoch * steps_per_epoch * 0.99)
|
|
||||||
warmup_steps = int(warmup_epochs * steps_per_epoch)
|
|
||||||
decay_steps = total_steps - warmup_steps
|
|
||||||
lr_each_step = []
|
|
||||||
for i in range(total_steps):
|
|
||||||
if i < warmup_steps:
|
|
||||||
lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr)
|
|
||||||
else:
|
|
||||||
linear_decay = (total_steps - i) / decay_steps
|
|
||||||
cosine_decay = 0.5 * (1 + math.cos(math.pi * 2 * num_periods * i / decay_steps))
|
|
||||||
decayed = linear_decay * cosine_decay
|
|
||||||
lr = base_lr * decayed + 0.000005
|
|
||||||
lr_each_step.append(lr)
|
|
||||||
return np.array(lr_each_step).astype(np.float32)
|
|
||||||
|
|
||||||
|
|
||||||
def get_lr(global_step, lr_init, lr_end, lr_max, warmup_epochs, total_epochs, steps_per_epoch, lr_decay_mode):
|
|
||||||
"""
|
|
||||||
generate learning rate array
|
|
||||||
|
|
||||||
Args:
|
|
||||||
global_step(int): total steps of the training
|
|
||||||
lr_init(float): init learning rate
|
|
||||||
lr_end(float): end learning rate
|
|
||||||
lr_max(float): max learning rate
|
|
||||||
warmup_epochs(int): number of warmup epochs
|
|
||||||
total_epochs(int): total epoch of training
|
|
||||||
steps_per_epoch(int): steps of one epoch
|
|
||||||
lr_decay_mode(string): learning rate decay mode, including steps, poly or default
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
np.array, learning rate array
|
|
||||||
"""
|
|
||||||
lr_each_step = []
|
|
||||||
total_steps = steps_per_epoch * total_epochs
|
|
||||||
warmup_steps = steps_per_epoch * warmup_epochs
|
|
||||||
if lr_decay_mode == 'steps':
|
|
||||||
decay_epoch_index = [0.3 * total_steps, 0.6 * total_steps, 0.8 * total_steps]
|
|
||||||
for i in range(total_steps):
|
|
||||||
if i < decay_epoch_index[0]:
|
|
||||||
lr = lr_max
|
|
||||||
elif i < decay_epoch_index[1]:
|
|
||||||
lr = lr_max * 0.1
|
|
||||||
elif i < decay_epoch_index[2]:
|
|
||||||
lr = lr_max * 0.01
|
|
||||||
else:
|
|
||||||
lr = lr_max * 0.001
|
|
||||||
lr_each_step.append(lr)
|
|
||||||
elif lr_decay_mode == 'poly':
|
|
||||||
if warmup_steps != 0:
|
|
||||||
inc_each_step = (float(lr_max) - float(lr_init)) / float(warmup_steps)
|
|
||||||
else:
|
|
||||||
inc_each_step = 0
|
|
||||||
for i in range(total_steps):
|
|
||||||
if i < warmup_steps:
|
|
||||||
lr = float(lr_init) + inc_each_step * float(i)
|
|
||||||
else:
|
|
||||||
base = (1.0 - (float(i) - float(warmup_steps)) / (float(total_steps) - float(warmup_steps)))
|
|
||||||
lr = float(lr_max) * base * base
|
|
||||||
if lr < 0.0:
|
|
||||||
lr = 0.0
|
|
||||||
lr_each_step.append(lr)
|
|
||||||
else:
|
|
||||||
for i in range(total_steps):
|
|
||||||
if i < warmup_steps:
|
|
||||||
lr = lr_init + (lr_max - lr_init) * i / warmup_steps
|
|
||||||
else:
|
|
||||||
lr = lr_max - (lr_max - lr_end) * (i - warmup_steps) / (total_steps - warmup_steps)
|
|
||||||
lr_each_step.append(lr)
|
|
||||||
|
|
||||||
current_step = global_step
|
|
||||||
lr_each_step = np.array(lr_each_step).astype(np.float32)
|
|
||||||
learning_rate = lr_each_step[current_step:]
|
|
||||||
|
|
||||||
return learning_rate
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,76 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""batch_matmul_impl"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusBatchMatMul",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "batchmatmul.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusBatchMatMul",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 1,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x2",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
def CusBatchMatMul(input_x1, input_x2, output, transpose_a=False, transpose_b=True, kernel_name="batchmatmul"):
|
||||||
|
"""CusBatchMatMul"""
|
||||||
|
return
|
@ -0,0 +1,64 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""CusCholeskyTrsm"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusCholeskyTrsm",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "choleskytrsm.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusCholeskyTrsm",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
def CusCholeskyTrsm(input_x, output, kernel_name):
|
||||||
|
"""CusCholeskyTrsm"""
|
||||||
|
return
|
@ -0,0 +1,69 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""CusFusedAbsMax1"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusFusedAbsMax1",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "fusedabsmax1.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusFusedAbsMax1",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
{
|
||||||
|
"name": "origin_shape",
|
||||||
|
"param_type": "required",
|
||||||
|
"type": "listInt",
|
||||||
|
"value": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
def CusFusedAbsMax1(input_x, output, origin_shape=None, kernel_name="fused_abs_max1"):
|
||||||
|
"""CusFusedAbsMax1"""
|
||||||
|
return
|
@ -0,0 +1,87 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""CusImg2ColNC1HWC0"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusImg2ColNC1HWC0",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "img2colnc1hwc0.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusImg2ColNC1HWC0",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
{
|
||||||
|
"name": "ksizes",
|
||||||
|
"param_type": "required",
|
||||||
|
"type": "listInt",
|
||||||
|
"value": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "strides",
|
||||||
|
"param_type": "required",
|
||||||
|
"type": "listInt",
|
||||||
|
"value": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "dilates",
|
||||||
|
"param_type": "required",
|
||||||
|
"type": "listInt",
|
||||||
|
"value": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "padding",
|
||||||
|
"param_type": "required",
|
||||||
|
"type": "str",
|
||||||
|
"value": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"NC1HWC0"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FRACTAL_NZ"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
def CusImg2ColNC1HWC0(input_x, output, ksizes, strides, dilates, padding, kernel_name="img2col"):
|
||||||
|
"""CusImg2ColNC1HWC0"""
|
||||||
|
return
|
@ -0,0 +1,101 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License == distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
matmul
|
||||||
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
from topi.cce import util
|
||||||
|
|
||||||
|
# General limitation of the size for input shape: 2**31
|
||||||
|
SHAPE_SIZE_LIMIT = 2147483648
|
||||||
|
NoneType = type(None)
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusMatMulCubeDenseLeft",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "matmulcubedenseleft.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusMatMulCubeDenseLeft",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 1,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FRACTAL_NZ"
|
||||||
|
],
|
||||||
|
"name": "x2",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 2,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x3",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "optional",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FRACTAL_NZ"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
@util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str)
|
||||||
|
def CusMatMulCubeDenseLeft(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False,
|
||||||
|
kernel_name="matmulcube"):
|
||||||
|
"""CusMatMulCubeDenseLeft"""
|
||||||
|
return
|
@ -0,0 +1,102 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License == distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
matmul
|
||||||
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
from topi.cce import util
|
||||||
|
|
||||||
|
# General limitation of the size for input shape: 2**31
|
||||||
|
SHAPE_SIZE_LIMIT = 2147483648
|
||||||
|
NoneType = type(None)
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusMatMulCubeFraczLeftCast",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "matmulcubefraczleftcast.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusMatMulCubeFraczLeftCast",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 1,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FracZ"
|
||||||
|
],
|
||||||
|
"name": "x2",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 2,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x3",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "optional",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FracZ"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
# pylint: disable=locally-disabled,too-many-arguments, too-many-locals, too-many-statements
|
||||||
|
@util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str)
|
||||||
|
def CusMatMulCubeFraczLeftCast(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False,
|
||||||
|
kernel_name="CusMatMulCubeFraczLeftCast"):
|
||||||
|
"""CusMatMulCubeFraczLeftCast"""
|
||||||
|
return
|
@ -0,0 +1,113 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License == distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
matmul
|
||||||
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
|
||||||
|
# General limitation of the size for input shape: 2**31
|
||||||
|
SHAPE_SIZE_LIMIT = 2147483648
|
||||||
|
NoneType = type(None)
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusMatMulCubeFraczRightMul",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "matmulcubefraczrightmul.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusMatMulCubeFraczRightMul",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FracZ"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 1,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x2",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 2,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x3",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 3,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x4",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "optional",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FracZ"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
def CusMatMulCubeFraczRightMul(input_x1, input_x2, input_x3, bias=None, output_y={}, trans_a=False, trans_b=False,
|
||||||
|
kernel_name="matmulcube"):
|
||||||
|
"""CusMatMulCubeFraczRightMul"""
|
||||||
|
return
|
@ -0,0 +1,114 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License == distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
matmul
|
||||||
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
from topi.cce import util
|
||||||
|
|
||||||
|
# General limitation of the size for input shape: 2**31
|
||||||
|
SHAPE_SIZE_LIMIT = 2147483648
|
||||||
|
NoneType = type(None)
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusMatMulCube",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "matmulcube.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusMatMulCube",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
{
|
||||||
|
"name": "transpose_a",
|
||||||
|
"param_type": "required",
|
||||||
|
"type": "bool",
|
||||||
|
"value": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "transpose_b",
|
||||||
|
"param_type": "required",
|
||||||
|
"type": "bool",
|
||||||
|
"value": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FRACTAL_NZ"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 1,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FRACTAL_NZ"
|
||||||
|
],
|
||||||
|
"name": "x2",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 2,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x3",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "optional",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"FRACTAL_NZ"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
# pylint: disable=locally-disabled,too-many-arguments, too-many-locals, too-many-statements
|
||||||
|
@util.check_input_type(dict, dict, (dict, NoneType), dict, bool, bool, str)
|
||||||
|
def CusMatMulCube(input_x1, input_x2, bias=None, output_y={}, trans_a=False, trans_b=False, kernel_name="matmulcube"):
|
||||||
|
"""CusMatMulCube"""
|
||||||
|
return
|
@ -0,0 +1,63 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""CusMatrixCombine"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusMatrixCombine",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "matrixcombine.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusMatrixCombine",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float32"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
def CusMatrixCombine(input_x, output, kernel_name="matrix_combine"):
|
||||||
|
"""CusMatrixCombine"""
|
||||||
|
return
|
@ -0,0 +1,63 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""CusTranspose02314"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register("""{
|
||||||
|
"op_name": "CusTranspose02314",
|
||||||
|
"imply_type": "TBE",
|
||||||
|
"fusion_type": "OPAQUE",
|
||||||
|
"async_flag": false,
|
||||||
|
"binfile_name": "transpose02314.so",
|
||||||
|
"compute_cost": 10,
|
||||||
|
"kernel_name": "CusTranspose02314",
|
||||||
|
"partial_flag": true,
|
||||||
|
"attr": [
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"NC1HWC0"
|
||||||
|
],
|
||||||
|
"name": "x1",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"dtype": [
|
||||||
|
"float16"
|
||||||
|
],
|
||||||
|
"format": [
|
||||||
|
"DefaultFormat"
|
||||||
|
],
|
||||||
|
"name": "y",
|
||||||
|
"need_compile": false,
|
||||||
|
"param_type": "required",
|
||||||
|
"shape": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}""")
|
||||||
|
def CusTranspose02314(input_x, output, kernel_name="transpose021354"):
|
||||||
|
"""CusTranspose02314"""
|
||||||
|
return
|
@ -0,0 +1,248 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# ============================================================================
|
||||||
|
"""thor_ops"""
|
||||||
|
import mindspore as ms
|
||||||
|
from mindspore.ops import prim_attr_register, PrimitiveWithInfer
|
||||||
|
from mindspore.ops.composite import multitype_ops as C
|
||||||
|
|
||||||
|
|
||||||
|
class CusBatchMatMul(PrimitiveWithInfer):
|
||||||
|
"""CusMatMulCube definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self):
|
||||||
|
"""init CusMatMulCube"""
|
||||||
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y'])
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x1, x2, out, dout):
|
||||||
|
return (C.zeros_like(x1), C.zeros_like(x2))
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape, data2_shape):
|
||||||
|
return data1_shape
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype, data2_dtype):
|
||||||
|
return data1_dtype
|
||||||
|
|
||||||
|
|
||||||
|
class CusCholeskyTrsm(PrimitiveWithInfer):
|
||||||
|
"""CusCholeskyTrsm definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self):
|
||||||
|
"""init CusCholeskyTrsm"""
|
||||||
|
self.init_prim_io_names(inputs=['x1'], outputs=['y'])
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape):
|
||||||
|
ll = []
|
||||||
|
m, _ = data1_shape
|
||||||
|
if m >= 128:
|
||||||
|
ll = [m // 128, 128, 128]
|
||||||
|
else:
|
||||||
|
ll = [1, 64, 64]
|
||||||
|
return ll
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype):
|
||||||
|
return data1_dtype
|
||||||
|
|
||||||
|
|
||||||
|
class CusFusedAbsMax1(PrimitiveWithInfer):
|
||||||
|
"""CusCholeskyTrsm definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self, origin_shape=[-1, -1]):
|
||||||
|
"""init CusCholeskyTrsm"""
|
||||||
|
self.init_prim_io_names(inputs=['x1'], outputs=['y'])
|
||||||
|
self.origin_shape = origin_shape
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x, out, dout):
|
||||||
|
return (C.zeros_like(x),)
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape):
|
||||||
|
ll = []
|
||||||
|
if len(data1_shape) == 2:
|
||||||
|
ll = [1,]
|
||||||
|
else:
|
||||||
|
ll = [32, 64]
|
||||||
|
return ll
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype):
|
||||||
|
return data1_dtype
|
||||||
|
|
||||||
|
|
||||||
|
class CusImg2Col(PrimitiveWithInfer):
|
||||||
|
"""CusImg2Col definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self, ksizes, strides, dilates=(1, 1, 1, 1), mode="NC1HWC0"):
|
||||||
|
"""init CusImg2Col"""
|
||||||
|
self.init_prim_io_names(inputs=['x1'], outputs=['y'])
|
||||||
|
self.ksizes = ksizes
|
||||||
|
self.strides = strides
|
||||||
|
self.dilates = dilates
|
||||||
|
self.mode = mode
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x, out, dout):
|
||||||
|
return (C.zeros_like(x),)
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape):
|
||||||
|
bs, c, h, w = data1_shape
|
||||||
|
_, stride_h, stride_w, _ = self.strides
|
||||||
|
_, k_w, k_h, _ = self.ksizes
|
||||||
|
# assert m == n
|
||||||
|
c0 = 16
|
||||||
|
c1 = c // 16
|
||||||
|
if c1 == 0:
|
||||||
|
c1 = 1
|
||||||
|
shape = [bs * int(h // stride_h) * int(w // stride_w), k_w * k_h * c1 * c0]
|
||||||
|
return shape
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype):
|
||||||
|
return data1_dtype
|
||||||
|
|
||||||
|
|
||||||
|
class CusMatMulCubeDenseLeft(PrimitiveWithInfer):
|
||||||
|
"""CusMatMulCube definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self):
|
||||||
|
"""init CusMatMulCube"""
|
||||||
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y'])
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x1, x2, out, dout):
|
||||||
|
return (C.zeros_like(x1), C.zeros_like(x2))
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape, data2_shape):
|
||||||
|
return data2_shape
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype, data2_dtype):
|
||||||
|
return ms.common.dtype.tensor_type(getattr(ms, "float16"))
|
||||||
|
|
||||||
|
|
||||||
|
class CusMatMulCubeFraczRightMul(PrimitiveWithInfer):
|
||||||
|
"""CusMatMulCubeFraczRightMul definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self):
|
||||||
|
"""init CusMatMulCubeFraczRightMul"""
|
||||||
|
self.init_prim_io_names(inputs=['x1', 'x2', 'x3'], outputs=['y'])
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x1, x2, x3, out, dout):
|
||||||
|
return (C.zeros_like(x1), C.zeros_like(x2), C.zeros_like(x3))
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape, data2_shape, data3_shape):
|
||||||
|
return data1_shape
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype, data2_dtype, data3_dtype):
|
||||||
|
return ms.common.dtype.tensor_type(getattr(ms, "float32"))
|
||||||
|
|
||||||
|
|
||||||
|
class CusMatMulCube(PrimitiveWithInfer):
|
||||||
|
"""CusMatMulCube definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self, transpose_a=False, transpose_b=False):
|
||||||
|
"""init CusMatMulCube"""
|
||||||
|
self.init_prim_io_names(inputs=['x1', 'x2'], outputs=['y'])
|
||||||
|
self.transpose_a = transpose_a
|
||||||
|
self.transpose_b = transpose_b
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x1, x2, out, dout):
|
||||||
|
return (C.zeros_like(x1), C.zeros_like(x2))
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape, data2_shape):
|
||||||
|
# shape = [1, data1_shape[1], data2_shape[2], 16, 16]
|
||||||
|
# return shape
|
||||||
|
if self.transpose_a:
|
||||||
|
k1, m = data1_shape
|
||||||
|
else:
|
||||||
|
m, k1 = data1_shape
|
||||||
|
if self.transpose_b:
|
||||||
|
n, k2 = data2_shape
|
||||||
|
else:
|
||||||
|
k2, n = data2_shape
|
||||||
|
assert k1 == k2
|
||||||
|
shape = [m, n]
|
||||||
|
return shape
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype, data2_dtype):
|
||||||
|
return ms.common.dtype.tensor_type(getattr(ms, "float32"))
|
||||||
|
|
||||||
|
|
||||||
|
class CusMatrixCombine(PrimitiveWithInfer):
|
||||||
|
"""CusMatMulCube definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self):
|
||||||
|
"""init CusMatMulCube"""
|
||||||
|
self.init_prim_io_names(inputs=['x'], outputs=['y'])
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x, out, dout):
|
||||||
|
return (C.zeros_like(x),)
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data_shape):
|
||||||
|
a, b, c = data_shape
|
||||||
|
shape = [a * b, a * c]
|
||||||
|
|
||||||
|
return shape
|
||||||
|
|
||||||
|
def infer_dtype(self, data_dtype):
|
||||||
|
return data_dtype
|
||||||
|
|
||||||
|
|
||||||
|
class CusTranspose02314(PrimitiveWithInfer):
|
||||||
|
"""CusTranspose02314 definition"""
|
||||||
|
|
||||||
|
@prim_attr_register
|
||||||
|
def __init__(self):
|
||||||
|
"""init CusTranspose02314"""
|
||||||
|
self.init_prim_io_names(inputs=['x1'], outputs=['y'])
|
||||||
|
|
||||||
|
def get_bprop(self):
|
||||||
|
def bprop(x, out, dout):
|
||||||
|
return (C.zeros_like(x),)
|
||||||
|
|
||||||
|
return bprop
|
||||||
|
|
||||||
|
def infer_shape(self, data1_shape):
|
||||||
|
assert len(data1_shape) == 4
|
||||||
|
n, c, h, w = data1_shape
|
||||||
|
c0 = 16
|
||||||
|
c1 = c // 16
|
||||||
|
shape = (n * h * w, c1 * c0)
|
||||||
|
return shape
|
||||||
|
|
||||||
|
def infer_dtype(self, data1_dtype):
|
||||||
|
return data1_dtype
|
Loading…
Reference in new issue