TBE TIK算子开发问题
收藏回复举报
TBE TIK算子开发问题
t('forum.solved') 已解决
发表于2023-11-04 13:06:29
0 查看

环境

  • CANN 7.0.0.alpha001
  • Ubuntu 18.04
  • Python 3.7.5
  • Ascend310B4

问题描述

使用msopgen工具生成的项目: 链接: https://pan.baidu.com/s/11d7ekUt1CqH09_57_3SQLg 提取码: 2n6m

使用TBE TIK算子开发方式,编译并部署算子。然后使用ATC生成单算子模型出现以下问题:

root@d8043722616b:/home/test_op/build_out# atc --singleop=single-op.json --output=./ --soc_version=Ascend310B4
ATC start working now, please wait for a moment.
...
ATC run failed, Please check the detail log, Try 'atc --help' for more information
E29999: Inner Error!
E29999  [SubGraphOpt][ParseJson][PkgTvmJsInfo] ReadJsonFile failed.[FUNC:PackageTvmJsonInfo][FILE:tbe_json_parse.cc][LINE:1073]
        TraceBack (most recent call last):
        [SubGraphOpt][Compile][Normal] Failed to parse json or compress op for graph[partition0_rank1_new_sub_graph3].[FUNC:ReCompileWithNoFusionStrategy][FILE:op_compiler_normal.cc][LINE:88]
        [SubGraphOpt][Compile][RunCmplProc] Failed to re-compile op with no lx fusion for graph [partition0_rank1_new_sub_graph3][FUNC:RunCompileProcess][FILE:op_compiler_normal.cc][LINE:155]
        [GraphOpt][FusedGraph][RunCompile] Failed to compile graph with compiler Normal mode Op Compiler[FUNC:SubGraphCompile][FILE:fe_graph_optimizer.cc][LINE:1291]
        Call OptimizeFusedGraph failed, ret:-1, engine_name:AIcoreEngine, graph_name:partition0_rank1_new_sub_graph3[FUNC:OptimizeSubGraph][FILE:graph_optimize.cc][LINE:131]
        subgraph 0 optimize failed[FUNC:OptimizeSubGraphWithMultiThreads][FILE:graph_manager.cc][LINE:991]
        build graph failed, graph id:0, ret:-1[FUNC:BuildModelWithGraphId][FILE:ge_generator.cc][LINE:1615]

但将算子实现代码中的Scalar语句或者Tensor cbuf定义语句删除后,ATC就可以运行成功。

具体代码如下:

def test(q_type, k_type, v_type, o_type, kernel_name="test"):
    tbe_platform.set_current_compile_soc_info("Ascend310B4")
    tik_instance = tik.Tik()

    batch_size = q_type['shape'][0]
    assert q_type['shape'][0] == k_type['shape'][0] and k_type['shape'][0] == v_type['shape'][0]

    q_shape = q_type['shape'][1:]
    k_shape = k_type['shape'][1:]
    v_shape = v_type['shape'][1:]
    o_shape = o_type['shape'][1:]
    assert q_shape[1] == k_shape[0]
    assert q_shape[1] % 16 == 0
    assert k_shape[0] % 16 == 0
    assert k_shape[1] % 16 == 0
    assert o_shape[0] == q_shape[0]
    assert o_shape[1] == v_shape[1]
    k0 = 16
    m0 = 16
    n0 = 16
    k = q_shape[1]
    k1 = (k + k0 - 1) // k0
    m = ((q_shape[0] + m0 - 1) // m0) * m0
    n1 = (k_shape[1] + n0 - 1) // 16
    n = n1 * n0

    d = k1 * k0

    block_size_r = 16
    tr = m // block_size_r

    block_size_c = 16
    tc = n // block_size_c

    assert m % block_size_r == 0
    assert n % block_size_c == 0
    assert block_size_c % 16 == 0

    q = tik_instance.Tensor(dtype='float16', shape=q_type['shape'], name="q", scope=tik.scope_gm)

    k = tik_instance.Tensor(dtype='float16', shape=k_type['shape'], name='k', scope=tik.scope_gm)

    v = tik_instance.Tensor(dtype='float16', shape=v_type['shape'], name='v', scope=tik.scope_gm)

    o = tik_instance.Tensor(dtype='float16', shape=o_type['shape'], name='o', scope=tik.scope_gm)
    with tik_instance.for_range(0, batch_size) as b:

        sij_scale_ub = tik_instance.Tensor(dtype='float16',
                                           shape=[1],
                                           name='sij_scale_ub',
                                           scope=tik.scope_ubuf,
                                           )

        src_scalar = tik_instance.Scalar(init_value=1.0, dtype='float16')

        q_cbuf = tik_instance.Tensor(dtype='float16', shape=[1], name='q_cbuf11', scope=tik.scope_cbuf)
        k_cbuf = tik_instance.Tensor(dtype='float16', shape=[1], name='k_cbuf11', scope=tik.scope_cbuf)
        pass

    tik_instance.BuildCCE(kernel_name="test", inputs=[q, k, v], outputs=[o])

    return tik_instance

请问我这个是代码的问题还是其他问题?

本帖最后由 匿名用户2023/12/04 14:36:11 编辑

我要发帖子