Skip to content

工具链兼容性问题:TCopyIn/TCopyOut 跨地址空间赋值失败 #3

Description

@ly-ict

问题描述

在使用 linx_blockisa_llvm_musl 工具链编译 SuperNPUBench 算子时,遇到跨地址空间赋值错误。

错误信息

/Users/liyi/Documents/SuperNPU编译器构建/output/linx_blockisa_llvm_musl/lib/clang/15.0.4/include/tileop-api/jcore/TCopyIn.hpp:31:21: 
error: no viable overloaded '='
    tile_ptr[index] = src[idx_gm];
    ~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~

根本原因

__fp4_hif4x2 等结构体在 __vbuf__ (地址空间6) 与通用地址空间之间无法使用 = 赋值,因为隐式生成的赋值运算符不支持跨地址空间操作。

影响的文件

  • tileop-api/jcore/TCopyIn.hpp
  • tileop-api/jcore/TCopyOut.hpp
  • linx_blkc.h 中定义的所有自定义类型(__fp4_hif4x2, __blkc_bf16 等)

临时解决方案

添加 __tile_assign 辅助函数,通过直接访问 .data 成员绕过赋值运算符:

template <typename DstT, typename SrcT>
__attribute__((always_inline))
inline typename std::enable_if<std::is_class<DstT>::value>::type
__tile_assign(DstT &dst, const SrcT &src) {
  dst.data = src.data;
}

template <typename DstT, typename SrcT>
__attribute__((always_inline))
inline typename std::enable_if<!std::is_class<DstT>::value>::type
__tile_assign(DstT &dst, const SrcT &src) {
  dst = src;
}

将所有 tile_ptr[i] = src[j] 替换为 __tile_assign(tile_ptr[i], src[j])

建议的长期修复

linx_blkc.h 中为所有自定义类型添加跨地址空间赋值运算符:

struct __fp8_base {
  char data;
  
  // 添加跨地址空间赋值支持
  template<int AS>
  __fp8_base& operator=(const __fp8_base& other) {
    data = other.data;
    return *this;
  }
};

环境信息

  • 工具链: linx_blockisa_llvm_musl
  • Clang 版本: 15.0.4 (linx64v5-musl)
  • 编译命令: make TESTCASE=matmul TYPE=HIF4_HIF4 M=256 N=2048 K=2048 tM=64 tN=64 tK=128 COMPILER_DIR=/path/to/linx_blockisa_llvm_musl/bin

影响范围

  • 所有使用 TCOPYIN/TCOPYOUT 的算子都受影响
  • 包括 matmul、gelu、broadcast、reduction 等核心算子

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions