Mindspore调用ascendc算子无法获取原地计算的值
收藏回复举报
Mindspore调用ascendc算子无法获取原地计算的值
发表于2024-09-05 17:04:05
0 查看

1.  系统环境 

硬件环境(Ascend/GPU/CPU): Ascend910

MindSpore版本:2.3.1

执行模式(PyNative/ Graph):不限

Python版本:不限

操作系统平台:Linux 

 

2.  报错信息 

2.1 问题描述及报错

在使用mindspore的2.3.1版本调用ascendc算子时,该算子是原地计算的算子,算子定义如下:

this->Input("x")
    .ParamType(REQUIRED)
    .DataType({ge::DT FLOAT})
    .Format({ge::FORMAT ND})
    .UnknownShapeFormat({ge::FORMAT ND});
this->Input("y")
    .ParamType(REQUIRED)
    .DataType({ge::DT FLOAT})
    .Format({ge::FORMAT ND})
    .UnknownShapeFormat( {ge::FORMAT ND});
this->SetInferShape(ge:: InferShape);
this->AICore()
    .SetTiling(optiling::TilingFunc);
this->AICore().AddConfig("ascend310");

算子内部更新向量x,在用c++进行aclnn调用时,可以在计算完毕后将device侧的x内存拷贝到host侧输出。但是使用mindspore进行aclnn调用时,CustomRegOP注册该算子时,无论添不添加output注册,都无法获取原地输出的值。该如何将原地计算的值从device侧拷贝到host侧

class MysarStage1Pre(Cell):
    def __init__(self):
        super (MysarStage1Pre, self).__init__()
        ari_stage1pre = CustomRegOp("ac lnnStage1Pre") \
            .input(0, "a", "required") \
            .input(1, "b", "required") \
            .output(0, "c", "required") 1
            .dtype_format(DataType.F32_Default, DataType.F32_Default, DataType. F32_Default) \
            .target("Ascend") \
            .get_op_info()
        ari_stage1 = CustomRegOp( "aclnnStage1") \
            .input(0, "x", "required") \
            .input(1, "y", "required") \
            .output(0, "x", "required") 1
            .dtype_format(DataType.F32_Default, DataType.F32_Default, DataType. F32_Default) \
            .target("Ascend") \
            .get_op_info()
        self.stage1pre = ops.Custom(func="ac InnStage1Pre", out_shape-lambda x, y: [1, mysar_colunm], out_dtype=lambda x, _: x, func_type="aot", bprop=None, reg_info=ari_stage1pre)
        self.stage1 = ops.Custom(func="aclnnStage1", out_shape=lambda x, _: x, out_dtype=lambda x, _: x, func_type="aot", bprop=None, reg_info=ari_stage1)
    def construct(self, a, sig):
        colunm_mean = self. stage1pre(a, sig)
        dc = self.stage1(sig, colunm_mean)
        print("*"*12, "dc is :", "*"*12, "\n", dc)
        print("*"*12, "sig is :", "*"*12, "\n", sig)
        return sig

3 根因分析

******此处由用户填写******

4 解决方案

******此处由用户填写******

包含文字方案和最终脚本代码

请将正确的脚本打包并上传附件

我要发帖子