Merged
refactor(pypto-pro): Normalize integer scalar source types #6484
poorwillAdd on Sep 18
refactor(pypto-pro): Normalize integer scalar source types #6484
Merged
Merged fromwangbing110/pypto9.2.0intocann/pypto9.2.0
Total: 62 files changed+364-252
| @@ -78,7 +78,7 @@ public: | |||
| 78 | 78 | ||
| 79 | ## 约束说明 | 79 | ## 约束说明 |
| 80 | 80 | ||
| 81 | -- 裸整数常量(如42)默认为pypto_pro.language.DT_INT64,裸浮点常量(如3.14)默认为pypto_pro.language.DT_FP32。 | 81 | +- 裸整数常量(如42)使用DT_INT64。只有数值超过DT_INT64的上限时,才使用DT_UINT64。裸浮点常量(如3.14)使用DT_FP32。 |
| 82 | 82 | ||
| 83 | - MXFP8的数据元素使用DT_FP8E4M3FN或DT_FP8E5M2,MXFP4的数据元素使用DT_FP4E2M1或DT_FP4E1M2;两者均使用DT_FP8E8M0保存分组缩放因子。详见[matmul_mx](../cube_computation/matmul_mx.md)和[matmul_mx_acc](../cube_computation/matmul_mx_acc.md)。 | 83 | - MXFP8的数据元素使用DT_FP8E4M3FN或DT_FP8E5M2,MXFP4的数据元素使用DT_FP4E2M1或DT_FP4E1M2;两者均使用DT_FP8E8M0保存分组缩放因子。详见[matmul_mx](../cube_computation/matmul_mx.md)和[matmul_mx_acc](../cube_computation/matmul_mx_acc.md)。 |
| 84 | 84 | ||
| @@ -38,7 +38,7 @@ pypto_pro.language.Tensor.__init__( | |||
| 38 | 38 | ||
| 39 | | 参数 | 输入/输出 | 说明 | | 39 | | 参数 | 输入/输出 | 说明 | |
| 40 | |---|---|---| | 40 | |---|---|---| |
| 41 | -| shape | 输入 | 各维大小列表。<br>- 表现形式如下:<br> - 固定维度:正整数表示,如[64, 128],调用时对应维度须等于该整数。<br> - 动态维度:pypto_pro.language.DYNAMIC表示,调用时读取实际维度,维度值不参与编译缓存键,不同取值复用同一编译变体。<br> - 编译期特化维度:pypto_pro.language.STATIC表示,调用时读取实际维度,维度值固化到当前编译变体,取值变化时生成新的编译变体。<br> - 末尾`...`:展开剩余维度,各维均按pypto_pro.language.STATIC处理。<br> - 不同策略可混用,如[64, pl.DYNAMIC, pl.STATIC]。<br>- Kernel内可通过`tensor.shape[i]`读取对应维度。 | | 41 | +| shape | 输入 | 各维大小列表。<br>- 表现形式如下:<br> - 固定维度:正整数表示,如[64, 128],调用时对应维度须等于该整数。<br> - 动态维度:pypto_pro.language.DYNAMIC表示,调用时读取实际维度,维度值不参与编译缓存键,不同取值复用同一编译变体。<br> - 编译期特化维度:pypto_pro.language.STATIC表示,调用时读取实际维度,维度值固化到当前编译变体,取值变化时生成新的编译变体。<br> - 末尾`...`:展开剩余维度,各维均按pypto_pro.language.STATIC处理。<br> - 不同策略可混用,如[64, pl.DYNAMIC, pl.STATIC]。<br>- Kernel内可通过`tensor.shape[i]`读取对应维度,返回值类型为DT_INT64。 | |
| 42 | | dtype | 输入 | 元素数据类型,[pypto_pro.language.DataType](DataType.md)枚举值。 | | 42 | | dtype | 输入 | 元素数据类型,[pypto_pro.language.DataType](DataType.md)枚举值。 | |
| 43 | | layout | 输入 | 可选,内存布局,[pypto_pro.language.TensorLayout](TensorLayout.md)枚举值。<br>- 支持ND和NZ,不指定时按ND处理。<br>- 配置为NZ时只声明布局,不执行ND→NZ转换。 | | 43 | | layout | 输入 | 可选,内存布局,[pypto_pro.language.TensorLayout](TensorLayout.md)枚举值。<br>- 支持ND和NZ,不指定时按ND处理。<br>- 配置为NZ时只声明布局,不执行ND→NZ转换。 | |
| 44 | | memref | 输入 | 可选,显式内存引用,pypto_pro.language.MemRef实例。三参数形式中第三项为MemRef实例时按memref解析;需要同时指定layout和memref时使用四参数形式。 | | 44 | | memref | 输入 | 可选,显式内存引用,pypto_pro.language.MemRef实例。三参数形式中第三项为MemRef实例时按memref解析;需要同时指定layout和memref时使用四参数形式。 | |
| @@ -32,7 +32,7 @@ pypto_pro.language.get_block_idx() -> int | |||
| 32 | 32 | ||
| 33 | ## 返回值说明 | 33 | ## 返回值说明 |
| 34 | 34 | ||
| 35 | -返回设备运行时产生的整型标量值,可用于Kernel内整数运算和索引。取值范围与Kernel的执行域有关: | 35 | +返回DT_INT64类型的当前逻辑核索引,可用于Kernel内的整数计算和数据索引。取值范围与Kernel的执行域有关: |
| 36 | 36 | ||
| 37 | - 仅启动Cube(AIC)或仅启动Vector(AIV)时,范围为[0, get_block_num())。 | 37 | - 仅启动Cube(AIC)或仅启动Vector(AIV)时,范围为[0, get_block_num())。 |
| 38 | - 同时启动AIC与AIV时,AIC侧范围为[0, get_block_num());AIV侧范围为[0, get_subblock_num() × get_block_num())。当前1:2配置下,AIV侧范围为[0, 2 × get_block_num())。 | 38 | - 同时启动AIC与AIV时,AIC侧范围为[0, get_block_num());AIV侧范围为[0, get_subblock_num() × get_block_num())。当前1:2配置下,AIV侧范围为[0, 2 × get_block_num())。 |
| @@ -32,7 +32,7 @@ pypto_pro.language.get_block_num() -> int | |||
| 32 | 32 | ||
| 33 | ## 返回值说明 | 33 | ## 返回值说明 |
| 34 | 34 | ||
| 35 | -返回设备运行时产生的整型标量值,其值为限核后实际启动的逻辑Block数,可用于Kernel内整数运算和索引。 | 35 | +返回DT_INT64类型的实际逻辑Block数,可用于Kernel内的整数计算和数据索引。 |
| 36 | JIT每次启动通过C++启动器查询实际Stream的有效资源限制,按Kernel执行域和配对比例限制Host请求的`block_dim`。 | 36 | JIT每次启动通过C++启动器查询实际Stream的有效资源限制,按Kernel执行域和配对比例限制Host请求的`block_dim`。 |
| 37 | 因此返回值可能小于Host请求值;数据切分应使用本接口返回值作为循环步长,避免遗漏任务。 | 37 | 因此返回值可能小于Host请求值;数据切分应使用本接口返回值作为循环步长,避免遗漏任务。 |
| 38 | 38 | ||
| @@ -32,7 +32,7 @@ pypto_pro.language.get_subblock_idx() -> int | |||
| 32 | 32 | ||
| 33 | ## 返回值说明 | 33 | ## 返回值说明 |
| 34 | 34 | ||
| 35 | -返回设备运行时产生的整型标量值,可用于Kernel内整数运算和索引。取值范围为 | 35 | +返回DT_INT64类型的subblock索引,可用于Kernel内的整数计算和数据索引。取值范围为 |
| 36 | [0, get_subblock_num());在AIC与AIV比例为1:2的混合Kernel中,同一逻辑Block对应的两个AIV分别返回0和1。 | 36 | [0, get_subblock_num());在AIC与AIV比例为1:2的混合Kernel中,同一逻辑Block对应的两个AIV分别返回0和1。 |
| 37 | 37 | ||
| 38 | ## 典型使用场景 | 38 | ## 典型使用场景 |
| @@ -32,7 +32,7 @@ pypto_pro.language.get_subblock_num() -> int | |||
| 32 | 32 | ||
| 33 | ## 返回值说明 | 33 | ## 返回值说明 |
| 34 | 34 | ||
| 35 | -返回当前block的subblock总数,类型为整型Expr。返回值与核类型及编译模式有关: | 35 | +返回DT_INT64类型的subblock总数。返回值与核类型及编译模式有关: |
| 36 | 36 | ||
| 37 | - **AIC核**:始终返回1(AIC为block,无AIC从核)。 | 37 | - **AIC核**:始终返回1(AIC为block,无AIC从核)。 |
| 38 | - **AIV核**: | 38 | - **AIV核**: |
| @@ -35,7 +35,7 @@ pypto_pro.language.getval(container: Tile | Tensor, offset: int) -> Scalar | |||
| 35 | 35 | ||
| 36 | ## 返回值说明 | 36 | ## 返回值说明 |
| 37 | 37 | ||
| 38 | -返回与container元素类型一致的标量。 | 38 | +container元素类型为除DT_UINT64以外的整数类型时,统一返回DT_INT64类型的标量,其它场景返回与container元素类型一致的标量。 |
| 39 | 39 | ||
| 40 | ## 调用示例 | 40 | ## 调用示例 |
| 41 | 41 | ||
| @@ -33,7 +33,7 @@ pypto_pro.language.printf( | |||
| 33 | | 参数 | 输入/输出 | 说明 | | 33 | | 参数 | 输入/输出 | 说明 | |
| 34 | |---|---|---| | 34 | |---|---|---| |
| 35 | | format_str | 输入 | 格式串,必须是编译时常量字符串,不能是运行时变量。<br>支持%d/%i(有符号整数)、%u(无符号整数)、%x(十六进制)、%f(浮点)和%p(指针)。不支持flags、宽度、精度和长度修饰符。<br>不支持的conversion:%%(百分号本身)、%s(字符串)、%c(字符)。 | | 35 | | format_str | 输入 | 格式串,必须是编译时常量字符串,不能是运行时变量。<br>支持%d/%i(有符号整数)、%u(无符号整数)、%x(十六进制)、%f(浮点)和%p(指针)。不支持flags、宽度、精度和长度修饰符。<br>不支持的conversion:%%(百分号本身)、%s(字符串)、%c(字符)。 | |
| 36 | -| *args | 输入 | 要打印的标量值或Ptr指针,数量和类型须与格式串中的格式说明符匹配。支持Python int、Python float、Python bool以及Kernel标量表达式;使用%p时还支持Ptr指针。<br>%d/%i:接受有符号整型、BOOL、INDEX,拒绝无符号整型<br>%u:接受无符号整型、BOOL、INDEX,拒绝有符号整型<br>%x:接受无符号整型、INDEX,拒绝有符号整型和BOOL<br>%f:仅接受FP32,拒绝FP16/BF16和整型<br>%p:仅接受Ptr指针。 | | 36 | +| *args | 输入 | 要打印的标量值或Ptr指针,数量和类型须与格式串中的格式说明符匹配。支持Python int、Python float、Python bool以及Kernel标量表达式;使用%p时还支持Ptr指针。<br>%d/%i:接受有符号整数和DT_BOOL,拒绝无符号整数<br>%u:接受无符号整数和DT_BOOL,拒绝有符号整数<br>%x:接受无符号整数,拒绝有符号整数和DT_BOOL<br>%f:仅接受DT_FP32,拒绝其他数据类型<br>%p:仅接受Ptr指针。 | |
| 37 | | loc | 输入 | 可选,是否在输出前打印源文件/行号,取值为True或False(默认)。为True时,在输出前打印调用位置的源文件和行号。 | | 37 | | loc | 输入 | 可选,是否在输出前打印源文件/行号,取值为True或False(默认)。为True时,在输出前打印调用位置的源文件和行号。 | |
| 38 | 38 | ||
| 39 | ## 约束说明 | 39 | ## 约束说明 |
| @@ -29,7 +29,7 @@ class AddTiling: | |||
| 29 | 29 | ||
| 30 | ### 字段类型 | 30 | ### 字段类型 |
| 31 | 31 | ||
| 32 | -TilingData的字段支持标量`int`、`float`、`bool`,以及对应的定长数组`int[N]`、`float[N]`、`bool[N]`。 | 32 | +TilingData的字段支持标量`int`、`float`、`bool`,以及对应的定长数组`int[N]`、`float[N]`、`bool[N]`。其中,`int`对应DT_INT64,`float`对应DT_FP32,`bool`对应DT_BOOL。 |
| 33 | 33 | ||
| 34 | 字段声明需满足以下要求: | 34 | 字段声明需满足以下要求: |
| 35 | 35 | ||
| @@ -55,8 +55,8 @@ Span MakeCombinedSpan(const Span& begin_span, const Span& end_span) | |||
| 55 | * | 55 | * |
| 56 | * A ternary expression ``a if cond else b`` lowers to an if statement whose then/else | 56 | * A ternary expression ``a if cond else b`` lowers to an if statement whose then/else |
| 57 | * branches each yield their value into a phi return var. When the two branches produce | 57 | * branches each yield their value into a phi return var. When the two branches produce |
| 58 | - * differing but same-category scalar dtypes (e.g. ``INT32`` from a tensor read vs | 58 | + * differing but same-category scalar dtypes (e.g. ``INT64`` vs ``UINT64``), promote |
| 59 | - * ``INDEX`` from a shape access), promote both yielded values to the wider dtype and | 59 | + * both yielded values according to the scalar promotion rules and |
| 60 | * retype the phi return var to match, mirroring the promotion binary operators already | 60 | * retype the phi return var to match, mirroring the promotion binary operators already |
| 61 | * perform. Non-scalar or cross-category (int vs float) mismatches are left untouched so | 61 | * perform. Non-scalar or cross-category (int vs float) mismatches are left untouched so |
| 62 | * the type verifier still reports them. | 62 | * the type verifier still reports them. |
| @@ -350,8 +350,8 @@ StmtPtr IRBuilder::EndIf(const Span& end_span) | |||
| 350 | std::vector<StmtPtr> else_stmts = if_ctx->GetElseStmts(); | 350 | std::vector<StmtPtr> else_stmts = if_ctx->GetElseStmts(); |
| 351 | std::vector<VarPtr> return_vars = if_ctx->GetReturnVars(); | 351 | std::vector<VarPtr> return_vars = if_ctx->GetReturnVars(); |
| 352 | 352 | ||
| 353 | - // Promote differing but same-category scalar branch types (e.g. ``a if c else b`` | 353 | + // Promote differing but same-category scalar branch types to a common dtype |
| 354 | - // yielding INT32 vs INDEX) to a common dtype before building the phi. | 354 | + // before building the phi. |
| 355 | if (if_ctx->InElseBranch()) { | 355 | if (if_ctx->InElseBranch()) { |
| 356 | ReconcileIfReturnVarTypes(then_stmts, else_stmts, return_vars); | 356 | ReconcileIfReturnVarTypes(then_stmts, else_stmts, return_vars); |
| 357 | } | 357 | } |
| @@ -40,13 +40,25 @@ | |||
| 40 | namespace pypto { | 40 | namespace pypto { |
| 41 | namespace ir { | 41 | namespace ir { |
| 42 | 42 | ||
| 43 | +namespace { | ||
| 44 | + | ||
| 45 | +DataType GetValResultDtype(const DataType& element_dtype) | ||
| 46 | +{ | ||
| 47 | + if (!element_dtype.IsInt()) { | ||
| 48 | + return element_dtype; | ||
| 49 | + } | ||
| 50 | + return element_dtype == DataType::UINT64 ? DataType::UINT64 : DataType::INT64; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +} // namespace | ||
| 54 | + | ||
| 43 | TypePtr DeduceBlockGetBlockIdxType([[maybe_unused]] const std::vector<ExprPtr>& args, | 55 | TypePtr DeduceBlockGetBlockIdxType([[maybe_unused]] const std::vector<ExprPtr>& args, |
| 44 | [[maybe_unused]] const std::vector<std::pair<std::string, std::any>>& kwargs, | 56 | [[maybe_unused]] const std::vector<std::pair<std::string, std::any>>& kwargs, |
| 45 | const std::string& op_name) | 57 | const std::string& op_name) |
| 46 | { | 58 | { |
| 47 | CHECK(args.size() == 0) << "The operator " << op_name << " requires no arguments, but got " << args.size(); | 59 | CHECK(args.size() == 0) << "The operator " << op_name << " requires no arguments, but got " << args.size(); |
| 48 | 60 | ||
| 49 | - return std::make_shared<ScalarType>(DataType::INDEX); | 61 | + return std::make_shared<ScalarType>(DataType::INT64); |
| 50 | } | 62 | } |
| 51 | 63 | ||
| 52 | TypePtr DeduceBlockCreateTileType([[maybe_unused]] const std::vector<ExprPtr>& args, | 64 | TypePtr DeduceBlockCreateTileType([[maybe_unused]] const std::vector<ExprPtr>& args, |
| @@ -133,7 +145,7 @@ TypePtr DeduceBlockCreateTileType([[maybe_unused]] const std::vector<ExprPtr>& a | |||
| 133 | int64_t addr_val = GetOpKwarg<int>(kwargs, "memref_addr"); | 145 | int64_t addr_val = GetOpKwarg<int>(kwargs, "memref_addr"); |
| 134 | int64_t size_val = GetOpKwarg<int>(kwargs, "memref_size"); | 146 | int64_t size_val = GetOpKwarg<int>(kwargs, "memref_size"); |
| 135 | uint64_t id_val = static_cast<uint64_t>(GetOpKwarg<int>(kwargs, "memref_id")); | 147 | uint64_t id_val = static_cast<uint64_t>(GetOpKwarg<int>(kwargs, "memref_id")); |
| 136 | - auto addr_expr = std::make_shared<ConstInt>(addr_val, DataType::INDEX, Span::Unknown()); | 148 | + auto addr_expr = std::make_shared<ConstInt>(addr_val, DataType::INT64, Span::Unknown()); |
| 137 | MemRefPtr memref = std::make_shared<MemRef>(target_memory, addr_expr, static_cast<uint64_t>(size_val), id_val); | 149 | MemRefPtr memref = std::make_shared<MemRef>(target_memory, addr_expr, static_cast<uint64_t>(size_val), id_val); |
| 138 | return std::make_shared<TileType>(tile_shape, dtype, std::optional<MemRefPtr>(memref), tile_view, hw_info); | 150 | return std::make_shared<TileType>(tile_shape, dtype, std::optional<MemRefPtr>(memref), tile_view, hw_info); |
| 139 | } | 151 | } |
| @@ -153,12 +165,12 @@ TypePtr DeduceGetValType([[maybe_unused]] const std::vector<ExprPtr>& args, | |||
| 153 | << offset_type->dtype_.ToString(); | 165 | << offset_type->dtype_.ToString(); |
| 154 | 166 | ||
| 155 | if (auto tile_type = As<TileType>(first_type)) { | 167 | if (auto tile_type = As<TileType>(first_type)) { |
| 156 | - return std::make_shared<ScalarType>(tile_type->dtype_); | 168 | + return std::make_shared<ScalarType>(GetValResultDtype(tile_type->dtype_)); |
| 157 | } | 169 | } |
| 158 | auto tensor_type = As<TensorType>(first_type); | 170 | auto tensor_type = As<TensorType>(first_type); |
| 159 | CHECK(tensor_type) << "getval requires first argument to be TileType or TensorType, but got " | 171 | CHECK(tensor_type) << "getval requires first argument to be TileType or TensorType, but got " |
| 160 | << first_type->TypeName(); | 172 | << first_type->TypeName(); |
| 161 | - return std::make_shared<ScalarType>(tensor_type->dtype_); | 173 | + return std::make_shared<ScalarType>(GetValResultDtype(tensor_type->dtype_)); |
| 162 | } | 174 | } |
| 163 | 175 | ||
| 164 | TypePtr DeduceTileValidShapeType(const std::vector<ExprPtr>& args, | 176 | TypePtr DeduceTileValidShapeType(const std::vector<ExprPtr>& args, |
| @@ -167,7 +179,7 @@ TypePtr DeduceTileValidShapeType(const std::vector<ExprPtr>& args, | |||
| 167 | CHECK(args.size() == 1 && As<TileType>(args[0]->GetType())) << "block.tile_valid_shape requires one Tile argument"; | 179 | CHECK(args.size() == 1 && As<TileType>(args[0]->GetType())) << "block.tile_valid_shape requires one Tile argument"; |
| 168 | int axis = GetOpKwarg<int>(kwargs, "axis", 0); | 180 | int axis = GetOpKwarg<int>(kwargs, "axis", 0); |
| 169 | CHECK(axis >= 0 && axis <= 1) << "block.tile_valid_shape axis must be in [0, 1], got axis=" << axis; | 181 | CHECK(axis >= 0 && axis <= 1) << "block.tile_valid_shape axis must be in [0, 1], got axis=" << axis; |
| 170 | - return std::make_shared<ScalarType>(DataType(DataType::UINT32)); | 182 | + return std::make_shared<ScalarType>(DataType::INT64); |
| 171 | } | 183 | } |
| 172 | 184 | ||
| 173 | TypePtr DeduceSetValType([[maybe_unused]] const std::vector<ExprPtr>& args, | 185 | TypePtr DeduceSetValType([[maybe_unused]] const std::vector<ExprPtr>& args, |
| @@ -236,7 +236,7 @@ REGISTER_OP("block.ssbuf_store") | |||
| 236 | .f_deduce_type([]([[maybe_unused]] const std::vector<ExprPtr>& args, | 236 | .f_deduce_type([]([[maybe_unused]] const std::vector<ExprPtr>& args, |
| 237 | [[maybe_unused]] const std::vector<std::pair<std::string, std::any>>& kwargs) { | 237 | [[maybe_unused]] const std::vector<std::pair<std::string, std::any>>& kwargs) { |
| 238 | CHECK(args.size() == 2) << "The operator block.ssbuf_store requires 2 arguments (struct_var, offset)"; | 238 | CHECK(args.size() == 2) << "The operator block.ssbuf_store requires 2 arguments (struct_var, offset)"; |
| 239 | - return std::make_shared<ScalarType>(DataType::INDEX); | 239 | + return GetNoneType(); |
| 240 | }); | 240 | }); |
| 241 | 241 | ||
| 242 | // block.ssbuf_load: (struct_var, offset) -> void | 242 | // block.ssbuf_load: (struct_var, offset) -> void |
| @@ -249,7 +249,7 @@ REGISTER_OP("block.ssbuf_load") | |||
| 249 | .f_deduce_type([]([[maybe_unused]] const std::vector<ExprPtr>& args, | 249 | .f_deduce_type([]([[maybe_unused]] const std::vector<ExprPtr>& args, |
| 250 | [[maybe_unused]] const std::vector<std::pair<std::string, std::any>>& kwargs) { | 250 | [[maybe_unused]] const std::vector<std::pair<std::string, std::any>>& kwargs) { |
| 251 | CHECK(args.size() == 2) << "The operator block.ssbuf_load requires 2 arguments (struct_var, offset)"; | 251 | CHECK(args.size() == 2) << "The operator block.ssbuf_load requires 2 arguments (struct_var, offset)"; |
| 252 | - return std::make_shared<ScalarType>(DataType::INDEX); | 252 | + return GetNoneType(); |
| 253 | }); | 253 | }); |
| 254 | 254 | ||
| 255 | // block.full: (out, scalar) -> TileType (out's type) | 255 | // block.full: (out, scalar) -> TileType (out's type) |
| @@ -64,14 +64,12 @@ TypePtr DeduceAddPtrType([[maybe_unused]] const std::vector<ExprPtr>& args, | |||
| 64 | new_base_ptr = *ptr_type->base_ptr; | 64 | new_base_ptr = *ptr_type->base_ptr; |
| 65 | if (auto c1 = As<ConstInt>(*ptr_type->offset)) { | 65 | if (auto c1 = As<ConstInt>(*ptr_type->offset)) { |
| 66 | if (auto c2 = As<ConstInt>(args[1])) { | 66 | if (auto c2 = As<ConstInt>(args[1])) { |
| 67 | - new_offset = std::make_shared<ConstInt>(c1->value_ + c2->value_, DataType(DataType::INDEX), | 67 | + new_offset = std::make_shared<ConstInt>(c1->value_ + c2->value_, DataType::INT64, args[1]->span_); |
| 68 | - args[1]->span_); | ||
| 69 | } else { | 68 | } else { |
| 70 | - new_offset = std::make_shared<Add>(*ptr_type->offset, args[1], DataType(DataType::INDEX), | 69 | + new_offset = std::make_shared<Add>(*ptr_type->offset, args[1], DataType::INT64, args[1]->span_); |
| 71 | - args[1]->span_); | ||
| 72 | } | 70 | } |
| 73 | } else { | 71 | } else { |
| 74 | - new_offset = std::make_shared<Add>(*ptr_type->offset, args[1], DataType(DataType::INDEX), args[1]->span_); | 72 | + new_offset = std::make_shared<Add>(*ptr_type->offset, args[1], DataType::INT64, args[1]->span_); |
| 75 | } | 73 | } |
| 76 | } else { | 74 | } else { |
| 77 | // Direct addptr on a function parameter — record base and offset directly. | 75 | // Direct addptr on a function parameter — record base and offset directly. |
| @@ -228,7 +228,7 @@ REGISTER_OP("system.wait_cross_core") | |||
| 228 | REGISTER_OP("system.set_cross_core_dyn") | 228 | REGISTER_OP("system.set_cross_core_dyn") |
| 229 | .set_description("Cross-core sync set with dynamic event_id") | 229 | .set_description("Cross-core sync set with dynamic event_id") |
| 230 | .set_op_category("SyncOp") | 230 | .set_op_category("SyncOp") |
| 231 | - .add_argument("event_id", "Dynamic event ID (ScalarType INDEX)") | 231 | + .add_argument("event_id", "Dynamic event ID (ScalarType with integer dtype)") |
| 232 | .set_attr<int>("pipe") | 232 | .set_attr<int>("pipe") |
| 233 | .set_attr<int>("sync_mode") | 233 | .set_attr<int>("sync_mode") |
| 234 | .f_deduce_type(DeduceUnknownType); | 234 | .f_deduce_type(DeduceUnknownType); |
| @@ -237,7 +237,7 @@ REGISTER_OP("system.set_cross_core_dyn") | |||
| 237 | REGISTER_OP("system.wait_cross_core_dyn") | 237 | REGISTER_OP("system.wait_cross_core_dyn") |
| 238 | .set_description("Cross-core sync wait with dynamic event_id") | 238 | .set_description("Cross-core sync wait with dynamic event_id") |
| 239 | .set_op_category("SyncOp") | 239 | .set_op_category("SyncOp") |
| 240 | - .add_argument("event_id", "Dynamic event ID (ScalarType INDEX)") | 240 | + .add_argument("event_id", "Dynamic event ID (ScalarType with integer dtype)") |
| 241 | .set_attr<int>("pipe") | 241 | .set_attr<int>("pipe") |
| 242 | .set_attr<int>("sync_mode") | 242 | .set_attr<int>("sync_mode") |
| 243 | .f_deduce_type(DeduceUnknownType); | 243 | .f_deduce_type(DeduceUnknownType); |
| @@ -81,7 +81,7 @@ TypePtr DeduceTensorCreateType([[maybe_unused]] const std::vector<ExprPtr>& args | |||
| 81 | } else { | 81 | } else { |
| 82 | // Runtime tuple: use GetItemExpr with ConstInt slice | 82 | // Runtime tuple: use GetItemExpr with ConstInt slice |
| 83 | for (size_t i = 0; i < shape_tuple_type->types_.size(); ++i) { | 83 | for (size_t i = 0; i < shape_tuple_type->types_.size(); ++i) { |
| 84 | - auto idx_const = std::make_shared<ConstInt>(static_cast<int64_t>(i), DataType::INDEX, args[0]->span_); | 84 | + auto idx_const = std::make_shared<ConstInt>(static_cast<int64_t>(i), DataType::INT64, args[0]->span_); |
| 85 | shape.emplace_back(std::make_shared<GetItemExpr>(args[0], idx_const, args[0]->span_)); | 85 | shape.emplace_back(std::make_shared<GetItemExpr>(args[0], idx_const, args[0]->span_)); |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| @@ -140,7 +140,7 @@ TypePtr DeduceTensorViewType([[maybe_unused]] const std::vector<ExprPtr>& args, | |||
| 140 | } else { | 140 | } else { |
| 141 | // Runtime tuple: use GetItemExpr with ConstInt slice | 141 | // Runtime tuple: use GetItemExpr with ConstInt slice |
| 142 | for (size_t i = 0; i < shape_tuple_type->types_.size(); ++i) { | 142 | for (size_t i = 0; i < shape_tuple_type->types_.size(); ++i) { |
| 143 | - auto idx_const = std::make_shared<ConstInt>(static_cast<int64_t>(i), DataType::INDEX, args[1]->span_); | 143 | + auto idx_const = std::make_shared<ConstInt>(static_cast<int64_t>(i), DataType::INT64, args[1]->span_); |
| 144 | new_shape.emplace_back(std::make_shared<GetItemExpr>(args[1], idx_const, args[1]->span_)); | 144 | new_shape.emplace_back(std::make_shared<GetItemExpr>(args[1], idx_const, args[1]->span_)); |
| 145 | } | 145 | } |
| 146 | } | 146 | } |
| @@ -69,7 +69,7 @@ TypePtr DeduceTensorReductionType([[maybe_unused]] const std::vector<ExprPtr>& a | |||
| 69 | if (i == axis) { | 69 | if (i == axis) { |
| 70 | if (keep_dim) { | 70 | if (keep_dim) { |
| 71 | // Keep dimension as 1 | 71 | // Keep dimension as 1 |
| 72 | - output_shape.push_back(std::make_shared<ConstInt>(1, DataType::INDEX, Span::Unknown())); | 72 | + output_shape.push_back(std::make_shared<ConstInt>(1, DataType::INT64, Span::Unknown())); |
| 73 | } | 73 | } |
| 74 | // Otherwise, skip this dimension (reduce it out) | 74 | // Otherwise, skip this dimension (reduce it out) |
| 75 | } else { | 75 | } else { |
| @@ -101,7 +101,7 @@ TypePtr DeduceTensorReshapeType([[maybe_unused]] const std::vector<ExprPtr>& arg | |||
| 101 | } else { | 101 | } else { |
| 102 | // Runtime tuple: use GetItemExpr with ConstInt slice | 102 | // Runtime tuple: use GetItemExpr with ConstInt slice |
| 103 | for (size_t i = 0; i < shape_tuple_type->types_.size(); ++i) { | 103 | for (size_t i = 0; i < shape_tuple_type->types_.size(); ++i) { |
| 104 | - auto idx_const = std::make_shared<ConstInt>(static_cast<int64_t>(i), DataType::INDEX, args[1]->span_); | 104 | + auto idx_const = std::make_shared<ConstInt>(static_cast<int64_t>(i), DataType::INT64, args[1]->span_); |
| 105 | new_shape.emplace_back(std::make_shared<GetItemExpr>(args[1], idx_const, args[1]->span_)); | 105 | new_shape.emplace_back(std::make_shared<GetItemExpr>(args[1], idx_const, args[1]->span_)); |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| @@ -47,7 +47,7 @@ ExprPtr TileDim(const ExprPtr& tile, int axis) | |||
| 47 | std::make_shared<ScalarType>(DataType(DataType::UINT32)), Span::Unknown()); | 47 | std::make_shared<ScalarType>(DataType(DataType::UINT32)), Span::Unknown()); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | -ExprPtr IndexConst(int64_t v) { return std::make_shared<ConstInt>(v, DataType::INDEX, Span::Unknown()); } | 50 | +ExprPtr Int64Const(int64_t v) { return std::make_shared<ConstInt>(v, DataType::INT64, Span::Unknown()); } |
| 51 | 51 | ||
| 52 | // --------------------------------------------------------------------------- | 52 | // --------------------------------------------------------------------------- |
| 53 | // SanitizerInstrumenter injects the log records (an IRMutator). | 53 | // SanitizerInstrumenter injects the log records (an IRMutator). |
| @@ -74,8 +74,8 @@ public: | |||
| 74 | auto tile_transfer_bounds = [this](const CallPtr& c) { | 74 | auto tile_transfer_bounds = [this](const CallPtr& c) { |
| 75 | // move/move_fp (TEXTRACT): the offset is the SOURCE extraction | 75 | // move/move_fp (TEXTRACT): the offset is the SOURCE extraction |
| 76 | // start, the window the DESTINATION's valid shape. | 76 | // start, the window the DESTINATION's valid shape. |
| 77 | - ExprPtr src_off_row = IndexConst(0); | 77 | + ExprPtr src_off_row = Int64Const(0); |
| 78 | - ExprPtr src_off_col = IndexConst(0); | 78 | + ExprPtr src_off_col = Int64Const(0); |
| 79 | if (auto off_tuple = As<MakeTuple>(c->args_.back())) { | 79 | if (auto off_tuple = As<MakeTuple>(c->args_.back())) { |
| 80 | if (!off_tuple->elements_.empty()) | 80 | if (!off_tuple->elements_.empty()) |
| 81 | src_off_row = off_tuple->elements_[0]; | 81 | src_off_row = off_tuple->elements_[0]; |
| @@ -85,7 +85,7 @@ public: | |||
| 85 | ExprPtr win_row = TileDim(c->args_[0], 0); | 85 | ExprPtr win_row = TileDim(c->args_[0], 0); |
| 86 | ExprPtr win_col = TileDim(c->args_[0], 1); | 86 | ExprPtr win_col = TileDim(c->args_[0], 1); |
| 87 | auto src = RecordTileAccess(c, 1, src_off_row, src_off_col, win_row, win_col); | 87 | auto src = RecordTileAccess(c, 1, src_off_row, src_off_col, win_row, win_col); |
| 88 | - auto dst = RecordTileAccess(c, 0, IndexConst(0), IndexConst(0), win_row, win_col); | 88 | + auto dst = RecordTileAccess(c, 0, Int64Const(0), Int64Const(0), win_row, win_col); |
| 89 | return SeqStmts::Flatten({src, dst}, c->span_); | 89 | return SeqStmts::Flatten({src, dst}, c->span_); |
| 90 | }; | 90 | }; |
| 91 | auto tile_insert_bounds = [this](const CallPtr& c) { | 91 | auto tile_insert_bounds = [this](const CallPtr& c) { |
| @@ -93,7 +93,7 @@ public: | |||
| 93 | // the window the SOURCE's valid shape. | 93 | // the window the SOURCE's valid shape. |
| 94 | ExprPtr win_row = TileDim(c->args_[1], 0); | 94 | ExprPtr win_row = TileDim(c->args_[1], 0); |
| 95 | ExprPtr win_col = TileDim(c->args_[1], 1); | 95 | ExprPtr win_col = TileDim(c->args_[1], 1); |
| 96 | - auto src = RecordTileAccess(c, 1, IndexConst(0), IndexConst(0), win_row, win_col); | 96 | + auto src = RecordTileAccess(c, 1, Int64Const(0), Int64Const(0), win_row, win_col); |
| 97 | auto dst = RecordTileAccess(c, 0, c->args_[2], c->args_[3], win_row, win_col); | 97 | auto dst = RecordTileAccess(c, 0, c->args_[2], c->args_[3], win_row, win_col); |
| 98 | return SeqStmts::Flatten({src, dst}, c->span_); | 98 | return SeqStmts::Flatten({src, dst}, c->span_); |
| 99 | }; | 99 | }; |
| @@ -225,7 +225,7 @@ std::pair<int64_t, int64_t> SanitizerInstrumenter::TileDims(const ExprPtr& tile) | |||
| 225 | 225 | ||
| 226 | ExprPtr SanitizerInstrumenter::ShapeProduct(const ShapedTypePtr& type, const Span& span) | 226 | ExprPtr SanitizerInstrumenter::ShapeProduct(const ShapedTypePtr& type, const Span& span) |
| 227 | { | 227 | { |
| 228 | - ExprPtr numel = IndexConst(1); | 228 | + ExprPtr numel = Int64Const(1); |
| 229 | for (const auto& d : type->shape_) | 229 | for (const auto& d : type->shape_) |
| 230 | numel = MakeMul(numel, d, span); | 230 | numel = MakeMul(numel, d, span); |
| 231 | return numel; | 231 | return numel; |
| @@ -236,13 +236,13 @@ ExprPtr SanitizerInstrumenter::ShapeProduct(const ShapedTypePtr& type, const Spa | |||
| 236 | StmtPtr SanitizerInstrumenter::MakeLogStmt(uint32_t det_id, std::vector<ExprPtr> fields, const Span& span) | 236 | StmtPtr SanitizerInstrumenter::MakeLogStmt(uint32_t det_id, std::vector<ExprPtr> fields, const Span& span) |
| 237 | { | 237 | { |
| 238 | std::vector<ExprPtr> args; | 238 | std::vector<ExprPtr> args; |
| 239 | - args.push_back(IndexConst(det_id)); // codegen / decoder dispatch on it | 239 | + args.push_back(Int64Const(det_id)); // codegen / decoder dispatch on it |
| 240 | args.insert(args.end(), std::make_move_iterator(fields.begin()), std::make_move_iterator(fields.end())); | 240 | args.insert(args.end(), std::make_move_iterator(fields.begin()), std::make_move_iterator(fields.end())); |
| 241 | args.push_back(log_param_); | 241 | args.push_back(log_param_); |
| 242 | args.push_back(capacity_param_); | 242 | args.push_back(capacity_param_); |
| 243 | // Source line for the replay report; the file comes from the Python | 243 | // Source line for the replay report; the file comes from the Python |
| 244 | // side, which knows the kernel's source path. | 244 | // side, which knows the kernel's source path. |
| 245 | - args.push_back(IndexConst(static_cast<int64_t>(span.BeginLine()))); | 245 | + args.push_back(Int64Const(static_cast<int64_t>(span.BeginLine()))); |
| 246 | auto call = std::make_shared<Call>("block.sanitizer_log", std::move(args), Span::Unknown()); | 246 | auto call = std::make_shared<Call>("block.sanitizer_log", std::move(args), Span::Unknown()); |
| 247 | return std::make_shared<EvalStmt>(call, Span::Unknown()); | 247 | return std::make_shared<EvalStmt>(call, Span::Unknown()); |
| 248 | } | 248 | } |
| @@ -257,8 +257,8 @@ StmtPtr SanitizerInstrumenter::RecordScalarAccess(const CallPtr& call) | |||
| 257 | auto [tile_dim0, tile_dim1] = TileDims(container); | 257 | auto [tile_dim0, tile_dim1] = TileDims(container); |
| 258 | if (tile_dim0 >= 0) { | 258 | if (tile_dim0 >= 0) { |
| 259 | std::vector<ExprPtr> fields; | 259 | std::vector<ExprPtr> fields; |
| 260 | - fields.push_back(IndexConst(tile_dim0)); | 260 | + fields.push_back(Int64Const(tile_dim0)); |
| 261 | - fields.push_back(IndexConst(tile_dim1)); | 261 | + fields.push_back(Int64Const(tile_dim1)); |
| 262 | fields.push_back(call->args_[1]); | 262 | fields.push_back(call->args_[1]); |
| 263 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::TileScalar), std::move(fields), call->span_); | 263 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::TileScalar), std::move(fields), call->span_); |
| 264 | } | 264 | } |
| @@ -271,14 +271,14 @@ StmtPtr SanitizerInstrumenter::RecordScalarAccess(const CallPtr& call) | |||
| 271 | // acc_row carries the count. | 271 | // acc_row carries the count. |
| 272 | ExprPtr numel = ShapeProduct(tensor_type, call->span_); | 272 | ExprPtr numel = ShapeProduct(tensor_type, call->span_); |
| 273 | std::vector<ExprPtr> fields; | 273 | std::vector<ExprPtr> fields; |
| 274 | - fields.push_back(IndexConst(0)); // ndim = 0: linear-offset access | 274 | + fields.push_back(Int64Const(0)); // ndim = 0: linear-offset access |
| 275 | fields.push_back(call->args_[1]); | 275 | fields.push_back(call->args_[1]); |
| 276 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims - 1; ++i) | 276 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims - 1; ++i) |
| 277 | - fields.push_back(IndexConst(0)); | 277 | + fields.push_back(Int64Const(0)); |
| 278 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) | 278 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) |
| 279 | - fields.push_back(IndexConst(0)); // shape slots (length only) | 279 | + fields.push_back(Int64Const(0)); // shape slots (length only) |
| 280 | fields.push_back(numel); | 280 | fields.push_back(numel); |
| 281 | - fields.push_back(IndexConst(1)); | 281 | + fields.push_back(Int64Const(1)); |
| 282 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::GmAccess), std::move(fields), call->span_); | 282 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::GmAccess), std::move(fields), call->span_); |
| 283 | } | 283 | } |
| 284 | 284 | ||
| @@ -291,10 +291,10 @@ StmtPtr SanitizerInstrumenter::RecordValidShape(const CallPtr& call) | |||
| 291 | auto [dim0, dim1] = TileDims(call->args_[0]); | 291 | auto [dim0, dim1] = TileDims(call->args_[0]); |
| 292 | CHECK(dim0 >= 0) << "sanitizer: set_validshape target must be a Tile"; | 292 | CHECK(dim0 >= 0) << "sanitizer: set_validshape target must be a Tile"; |
| 293 | std::vector<ExprPtr> fields; | 293 | std::vector<ExprPtr> fields; |
| 294 | - fields.push_back(IndexConst(dim0)); | 294 | + fields.push_back(Int64Const(dim0)); |
| 295 | - fields.push_back(IndexConst(dim1)); | 295 | + fields.push_back(Int64Const(dim1)); |
| 296 | - fields.push_back(IndexConst(0)); | 296 | + fields.push_back(Int64Const(0)); |
| 297 | - fields.push_back(IndexConst(0)); | 297 | + fields.push_back(Int64Const(0)); |
| 298 | fields.push_back(call->args_[1]); | 298 | fields.push_back(call->args_[1]); |
| 299 | fields.push_back(call->args_[2]); | 299 | fields.push_back(call->args_[2]); |
| 300 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::TileAccess), std::move(fields), call->span_); | 300 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::TileAccess), std::move(fields), call->span_); |
| @@ -321,13 +321,13 @@ StmtPtr SanitizerInstrumenter::RecordGmAccess(const CallPtr& call) | |||
| 321 | CHECK(tensor_type != nullptr) << "sanitizer: " << call->name_ << " tensor operand must be a Tensor"; | 321 | CHECK(tensor_type != nullptr) << "sanitizer: " << call->name_ << " tensor operand must be a Tensor"; |
| 322 | uint32_t ndim = std::min<uint32_t>(static_cast<uint32_t>(off_tuple->elements_.size()), kSanitizerMaxTensorDims); | 322 | uint32_t ndim = std::min<uint32_t>(static_cast<uint32_t>(off_tuple->elements_.size()), kSanitizerMaxTensorDims); |
| 323 | std::vector<ExprPtr> fields; | 323 | std::vector<ExprPtr> fields; |
| 324 | - fields.push_back(IndexConst(ndim)); | 324 | + fields.push_back(Int64Const(ndim)); |
| 325 | // Offsets (up to 5, pad with 0). | 325 | // Offsets (up to 5, pad with 0). |
| 326 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) { | 326 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) { |
| 327 | if (i < off_tuple->elements_.size()) { | 327 | if (i < off_tuple->elements_.size()) { |
| 328 | fields.push_back(off_tuple->elements_[i]); | 328 | fields.push_back(off_tuple->elements_[i]); |
| 329 | } else { | 329 | } else { |
| 330 | - fields.push_back(IndexConst(0)); | 330 | + fields.push_back(Int64Const(0)); |
| 331 | } | 331 | } |
| 332 | } | 332 | } |
| 333 | // Shape dims aligned with the offsets (same alignment as the replay's | 333 | // Shape dims aligned with the offsets (same alignment as the replay's |
| @@ -335,7 +335,7 @@ StmtPtr SanitizerInstrumenter::RecordGmAccess(const CallPtr& call) | |||
| 335 | uint32_t rank = std::min<uint32_t>(static_cast<uint32_t>(tensor_type->shape_.size()), kSanitizerMaxTensorDims); | 335 | uint32_t rank = std::min<uint32_t>(static_cast<uint32_t>(tensor_type->shape_.size()), kSanitizerMaxTensorDims); |
| 336 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) { | 336 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) { |
| 337 | uint32_t dim = (rank <= ndim) ? i : (ndim - rank) + i; // leading dims dropped | 337 | uint32_t dim = (rank <= ndim) ? i : (ndim - rank) + i; // leading dims dropped |
| 338 | - fields.push_back(dim < rank ? tensor_type->shape_[dim] : IndexConst(0)); | 338 | + fields.push_back(dim < rank ? tensor_type->shape_[dim] : Int64Const(0)); |
| 339 | } | 339 | } |
| 340 | // The order kwarg decomposes into ascending tile_dims + is_transpose; | 340 | // The order kwarg decomposes into ascending tile_dims + is_transpose; |
| 341 | // a transposed trailing-axes load swaps the recorded windows. Orders | 341 | // a transposed trailing-axes load swaps the recorded windows. Orders |
| @@ -372,8 +372,8 @@ StmtPtr SanitizerInstrumenter::RecordTileAccess(const CallPtr& call, uint32_t ti | |||
| 372 | auto [dim0, dim1] = TileDims(call->args_[tile_arg_idx]); | 372 | auto [dim0, dim1] = TileDims(call->args_[tile_arg_idx]); |
| 373 | CHECK(dim0 >= 0) << "sanitizer: tile operand must be a Tile"; | 373 | CHECK(dim0 >= 0) << "sanitizer: tile operand must be a Tile"; |
| 374 | std::vector<ExprPtr> fields; | 374 | std::vector<ExprPtr> fields; |
| 375 | - fields.push_back(IndexConst(dim0)); | 375 | + fields.push_back(Int64Const(dim0)); |
| 376 | - fields.push_back(IndexConst(dim1)); | 376 | + fields.push_back(Int64Const(dim1)); |
| 377 | fields.push_back(off_row); | 377 | fields.push_back(off_row); |
| 378 | fields.push_back(off_col); | 378 | fields.push_back(off_col); |
| 379 | fields.push_back(win_row); | 379 | fields.push_back(win_row); |
| @@ -391,8 +391,8 @@ StmtPtr SanitizerInstrumenter::RecordMutex(const CallPtr& call) | |||
| 391 | for (const auto& mutex_id : call->args_) { | 391 | for (const auto& mutex_id : call->args_) { |
| 392 | std::vector<ExprPtr> fields; | 392 | std::vector<ExprPtr> fields; |
| 393 | fields.push_back(mutex_id); | 393 | fields.push_back(mutex_id); |
| 394 | - fields.push_back(IndexConst(pipe)); | 394 | + fields.push_back(Int64Const(pipe)); |
| 395 | - fields.push_back(IndexConst(is_lock ? 1 : 0)); | 395 | + fields.push_back(Int64Const(is_lock ? 1 : 0)); |
| 396 | logs.push_back( | 396 | logs.push_back( |
| 397 | MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::MutexAccess), std::move(fields), call->span_)); | 397 | MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::MutexAccess), std::move(fields), call->span_)); |
| 398 | } | 398 | } |
| @@ -439,10 +439,10 @@ StmtPtr SanitizerInstrumenter::CollectMakeTile(const CallPtr& call) | |||
| 439 | } | 439 | } |
| 440 | } | 440 | } |
| 441 | std::vector<ExprPtr> fields; | 441 | std::vector<ExprPtr> fields; |
| 442 | - fields.push_back(IndexConst(addr)); | 442 | + fields.push_back(Int64Const(addr)); |
| 443 | - fields.push_back(IndexConst(sz * dtype_bytes)); | 443 | + fields.push_back(Int64Const(sz * dtype_bytes)); |
| 444 | - fields.push_back(IndexConst(static_cast<int64_t>((*tile_type->memref_)->memorySpace_))); | 444 | + fields.push_back(Int64Const(static_cast<int64_t>((*tile_type->memref_)->memorySpace_))); |
| 445 | - fields.push_back(IndexConst(sz)); // element count (report display) | 445 | + fields.push_back(Int64Const(sz)); // element count (report display) |
| 446 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::TileDecl), std::move(fields), call->span_); | 446 | return MakeLogStmt(static_cast<uint32_t>(SanitizerDetection::TileDecl), std::move(fields), call->span_); |
| 447 | } | 447 | } |
| 448 | 448 | ||
| @@ -481,31 +481,31 @@ StmtPtr SanitizerInstrumenter::CollectMakeTensor(const CallPtr& call) | |||
| 481 | auto stride_of = [&](size_t i) -> ExprPtr { | 481 | auto stride_of = [&](size_t i) -> ExprPtr { |
| 482 | if (i < stride_tuple->elements_.size()) | 482 | if (i < stride_tuple->elements_.size()) |
| 483 | return stride_tuple->elements_[i]; | 483 | return stride_tuple->elements_[i]; |
| 484 | - ExprPtr product = IndexConst(1); | 484 | + ExprPtr product = Int64Const(1); |
| 485 | for (size_t j = i + 1; j < shape_tuple->elements_.size(); ++j) | 485 | for (size_t j = i + 1; j < shape_tuple->elements_.size(); ++j) |
| 486 | product = MakeMul(product, shape_tuple->elements_[j], call->span_); | 486 | product = MakeMul(product, shape_tuple->elements_[j], call->span_); |
| 487 | return product; | 487 | return product; |
| 488 | }; | 488 | }; |
| 489 | - ExprPtr fp_elems = IndexConst(1); | 489 | + ExprPtr fp_elems = Int64Const(1); |
| 490 | for (size_t i = 0; i < shape_tuple->elements_.size(); ++i) { | 490 | for (size_t i = 0; i < shape_tuple->elements_.size(); ++i) { |
| 491 | - ExprPtr term = MakeMul(MakeSub(shape_tuple->elements_[i], IndexConst(1), call->span_), stride_of(i), | 491 | + ExprPtr term = MakeMul(MakeSub(shape_tuple->elements_[i], Int64Const(1), call->span_), stride_of(i), |
| 492 | call->span_); | 492 | call->span_); |
| 493 | fp_elems = MakeAdd(fp_elems, term, call->span_); | 493 | fp_elems = MakeAdd(fp_elems, term, call->span_); |
| 494 | } | 494 | } |
| 495 | - ExprPtr fp_bytes = MakeMul(fp_elems, IndexConst(elem_bytes), call->span_); | 495 | + ExprPtr fp_bytes = MakeMul(fp_elems, Int64Const(elem_bytes), call->span_); |
| 496 | 496 | ||
| 497 | // Source capacity in bytes: the element-count product of the source | 497 | // Source capacity in bytes: the element-count product of the source |
| 498 | // tensor's shape scaled by its element width. A raw pointer has no | 498 | // tensor's shape scaled by its element width. A raw pointer has no |
| 499 | // known bound (-1); the record skips the check then. | 499 | // known bound (-1); the record skips the check then. |
| 500 | - ExprPtr src_bytes = IndexConst(-1); | 500 | + ExprPtr src_bytes = Int64Const(-1); |
| 501 | if (auto src_tensor = As<TensorType>(call->args_[0]->GetType())) { | 501 | if (auto src_tensor = As<TensorType>(call->args_[0]->GetType())) { |
| 502 | int64_t src_elem = std::max<int64_t>(1, static_cast<int64_t>(src_tensor->dtype_.GetBit()) / 8); | 502 | int64_t src_elem = std::max<int64_t>(1, static_cast<int64_t>(src_tensor->dtype_.GetBit()) / 8); |
| 503 | - src_bytes = MakeMul(ShapeProduct(src_tensor, call->span_), IndexConst(src_elem), call->span_); | 503 | + src_bytes = MakeMul(ShapeProduct(src_tensor, call->span_), Int64Const(src_elem), call->span_); |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | std::vector<ExprPtr> fields; | 506 | std::vector<ExprPtr> fields; |
| 507 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) { | 507 | for (uint32_t i = 0; i < kSanitizerMaxTensorDims; ++i) { |
| 508 | - fields.push_back(i < shape_tuple->elements_.size() ? shape_tuple->elements_[i] : IndexConst(0)); | 508 | + fields.push_back(i < shape_tuple->elements_.size() ? shape_tuple->elements_[i] : Int64Const(0)); |
| 509 | } | 509 | } |
| 510 | fields.push_back(std::move(fp_bytes)); | 510 | fields.push_back(std::move(fp_bytes)); |
| 511 | fields.push_back(std::move(src_bytes)); | 511 | fields.push_back(std::move(src_bytes)); |
| @@ -534,8 +534,8 @@ ProgramPtr SanitizerInstrumenter::Instrument(ProgramPtr program) | |||
| 534 | } | 534 | } |
| 535 | auto log_var = std::make_shared<Var>("sanitizer_log", std::make_shared<PtrType>(DataType(DataType::INT8)), | 535 | auto log_var = std::make_shared<Var>("sanitizer_log", std::make_shared<PtrType>(DataType(DataType::INT8)), |
| 536 | Span::Unknown()); | 536 | Span::Unknown()); |
| 537 | - auto capacity_var = std::make_shared<Var>( | 537 | + auto capacity_var = std::make_shared<Var>("sanitizer_log_capacity", |
| 538 | - "sanitizer_log_capacity", std::make_shared<ScalarType>(DataType(DataType::INDEX)), Span::Unknown()); | 538 | + std::make_shared<ScalarType>(DataType::INT64), Span::Unknown()); |
| 539 | log_param_ = log_var; | 539 | log_param_ = log_var; |
| 540 | capacity_param_ = capacity_var; | 540 | capacity_param_ = capacity_var; |
| 541 | 541 | ||
| @@ -30,7 +30,7 @@ ShapedType::ShapedType(DataType dtype, const std::vector<int64_t>& shape, std::o | |||
| 30 | : dtype_(dtype), memref_(std::move(memref)) | 30 | : dtype_(dtype), memref_(std::move(memref)) |
| 31 | { | 31 | { |
| 32 | for (int64_t dim : shape) { | 32 | for (int64_t dim : shape) { |
| 33 | - shape_.push_back(std::make_shared<ConstInt>(dim, DataType::INDEX, Span::Unknown())); | 33 | + shape_.push_back(std::make_shared<ConstInt>(dim, DataType::INT64, Span::Unknown())); |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| @@ -548,7 +548,7 @@ static std::string MakeDebugPrintfCodegenCCE(const ir::CallPtr& op, codegen::Cod | |||
| 548 | args.emplace_back(codegen.GetExprAsCode(op->args_[i])); | 548 | args.emplace_back(codegen.GetExprAsCode(op->args_[i])); |
| 549 | if (ir::As<ir::PtrType>(op->args_[i]->GetType())) { | 549 | if (ir::As<ir::PtrType>(op->args_[i]->GetType())) { |
| 550 | // Pointer arguments are passed directly to ASC printf. | 550 | // Pointer arguments are passed directly to ASC printf. |
| 551 | - arg_dtypes.emplace_back(DataType::INDEX); | 551 | + arg_dtypes.emplace_back(DataType::INT64); |
| 552 | } else { | 552 | } else { |
| 553 | auto scalar_type = ir::As<ir::ScalarType>(op->args_[i]->GetType()); | 553 | auto scalar_type = ir::As<ir::ScalarType>(op->args_[i]->GetType()); |
| 554 | CHECK(scalar_type) << "debug.printf argument must be ScalarType in CCE lowering"; | 554 | CHECK(scalar_type) << "debug.printf argument must be ScalarType in CCE lowering"; |
| @@ -753,9 +753,9 @@ static std::string MakeBlockGetBlockIdxCodegenCCE(const ir::CallPtr& op, codegen | |||
| 753 | auto& cg = dynamic_cast<codegen::CCECodegen&>(codegen_base); | 753 | auto& cg = dynamic_cast<codegen::CCECodegen&>(codegen_base); |
| 754 | const auto target = cg.GetTarget(); | 754 | const auto target = cg.GetTarget(); |
| 755 | if (target == ir::SectionKind::Vector) { | 755 | if (target == ir::SectionKind::Vector) { |
| 756 | - return "(int32_t)(get_block_idx() * get_subblockdim() + get_subblockid())"; | 756 | + return "(int64_t)(get_block_idx() * get_subblockdim() + get_subblockid())"; |
| 757 | } | 757 | } |
| 758 | - return "(int32_t)(get_block_idx())"; | 758 | + return "(int64_t)(get_block_idx())"; |
| 759 | } | 759 | } |
| 760 | 760 | ||
| 761 | // Helper function for block.make_tile (no-op: allocation handled elsewhere) | 761 | // Helper function for block.make_tile (no-op: allocation handled elsewhere) |
| @@ -1671,14 +1671,14 @@ REGISTER_BACKEND_OP(BackendCCE, "get_block_num") | |||
| 1671 | .set_pipe(ir::PipeType::V) | 1671 | .set_pipe(ir::PipeType::V) |
| 1672 | .f_codegen([](const ir::CallPtr& op, codegen::CodegenBase& /*codegen_base*/) { | 1672 | .f_codegen([](const ir::CallPtr& op, codegen::CodegenBase& /*codegen_base*/) { |
| 1673 | CHECK(op->args_.size() == 0) << "get_block_num requires no arguments"; | 1673 | CHECK(op->args_.size() == 0) << "get_block_num requires no arguments"; |
| 1674 | - return std::string("(int32_t)(get_block_num())"); | 1674 | + return std::string("(int64_t)(get_block_num())"); |
| 1675 | }); | 1675 | }); |
| 1676 | 1676 | ||
| 1677 | REGISTER_BACKEND_OP(BackendCCE, "get_subblock_idx") | 1677 | REGISTER_BACKEND_OP(BackendCCE, "get_subblock_idx") |
| 1678 | .set_pipe(ir::PipeType::V) | 1678 | .set_pipe(ir::PipeType::V) |
| 1679 | .f_codegen([](const ir::CallPtr& op, codegen::CodegenBase& /*codegen_base*/) { | 1679 | .f_codegen([](const ir::CallPtr& op, codegen::CodegenBase& /*codegen_base*/) { |
| 1680 | CHECK(op->args_.size() == 0) << "get_subblock_idx requires no arguments"; | 1680 | CHECK(op->args_.size() == 0) << "get_subblock_idx requires no arguments"; |
| 1681 | - return std::string("(int32_t)(get_subblockid())"); | 1681 | + return std::string("(int64_t)(get_subblockid())"); |
| 1682 | }); | 1682 | }); |
| 1683 | 1683 | ||
| 1684 | REGISTER_BACKEND_OP(BackendCCE, "get_subblock_num") | 1684 | REGISTER_BACKEND_OP(BackendCCE, "get_subblock_num") |
| @@ -1689,9 +1689,9 @@ REGISTER_BACKEND_OP(BackendCCE, "get_subblock_num") | |||
| 1689 | auto& cg = dynamic_cast<codegen::CCECodegen&>(codegen_base); | 1689 | auto& cg = dynamic_cast<codegen::CCECodegen&>(codegen_base); |
| 1690 | const auto target = cg.GetTarget(); | 1690 | const auto target = cg.GetTarget(); |
| 1691 | if (target == ir::SectionKind::Vector) { | 1691 | if (target == ir::SectionKind::Vector) { |
| 1692 | - return std::string("(int32_t)(get_subblockdim())"); | 1692 | + return std::string("(int64_t)(get_subblockdim())"); |
| 1693 | } | 1693 | } |
| 1694 | - return std::string("(int32_t)(1)"); | 1694 | + return std::string("(int64_t)(1)"); |
| 1695 | }); | 1695 | }); |
| 1696 | 1696 | ||
| 1697 | // ============================================================================ | 1697 | // ============================================================================ |
| @@ -1703,14 +1703,24 @@ static std::string MakeGetValCodegenCCE(const ir::CallPtr& op, codegen::CodegenB | |||
| 1703 | auto& codegen = dynamic_cast<codegen::CCECodegen&>(codegen_base); | 1703 | auto& codegen = dynamic_cast<codegen::CCECodegen&>(codegen_base); |
| 1704 | CHECK(op->args_.size() == 2) << "getval requires 2 arguments, but got " << op->args_.size(); | 1704 | CHECK(op->args_.size() == 2) << "getval requires 2 arguments, but got " << op->args_.size(); |
| 1705 | 1705 | ||
| 1706 | + auto result_type = ir::As<ir::ScalarType>(op->GetType()); | ||
| 1707 | + INTERNAL_CHECK(result_type) << "getval result must be ScalarType"; | ||
| 1708 | + auto cast_result_if_dtype_changed = [](std::string result, const ir::DataType& result_dtype, | ||
| 1709 | + const ir::DataType& input_dtype) { | ||
| 1710 | + if (result_dtype != input_dtype) { | ||
| 1711 | + return "(" + result_dtype.ToCTypeString() + ")(" + result + ")"; | ||
| 1712 | + } | ||
| 1713 | + return result; | ||
| 1714 | + }; | ||
| 1715 | + | ||
| 1706 | auto first_type = op->args_[0]->GetType(); | 1716 | auto first_type = op->args_[0]->GetType(); |
| 1707 | - if (ir::As<ir::TileType>(first_type)) { | 1717 | + if (auto tile_type = ir::As<ir::TileType>(first_type)) { |
| 1708 | std::string tile = codegen.GetExprAsCode(op->args_[0]); | 1718 | std::string tile = codegen.GetExprAsCode(op->args_[0]); |
| 1709 | std::string offset = codegen.GetExprAsCode(op->args_[1]); | 1719 | std::string offset = codegen.GetExprAsCode(op->args_[1]); |
| 1710 | if (codegen.IsInSimtContext()) { | 1720 | if (codegen.IsInSimtContext()) { |
| 1711 | - return tile + "[" + offset + "]"; | 1721 | + return cast_result_if_dtype_changed(tile + "[" + offset + "]", result_type->dtype_, tile_type->dtype_); |
| 1712 | } | 1722 | } |
| 1713 | - return tile + ".GetValue(" + offset + ")"; | 1723 | + return cast_result_if_dtype_changed(tile + ".GetValue(" + offset + ")", result_type->dtype_, tile_type->dtype_); |
| 1714 | } | 1724 | } |
| 1715 | 1725 | ||
| 1716 | auto tensor_var = ir::As<ir::Var>(op->args_[0]); | 1726 | auto tensor_var = ir::As<ir::Var>(op->args_[0]); |
| @@ -1723,7 +1733,8 @@ static std::string MakeGetValCodegenCCE(const ir::CallPtr& op, codegen::CodegenB | |||
| 1723 | 1733 | ||
| 1724 | std::string tensor_ptr = codegen.GetPointer(tensor_name); | 1734 | std::string tensor_ptr = codegen.GetPointer(tensor_name); |
| 1725 | 1735 | ||
| 1726 | - return "*((__gm__ " + dtype_str + "*)" + tensor_ptr + " + " + offset + ")"; | 1736 | + return cast_result_if_dtype_changed("*((__gm__ " + dtype_str + "*)" + tensor_ptr + " + " + offset + ")", |
| 1737 | + result_type->dtype_, tensor_type->dtype_); | ||
| 1727 | } | 1738 | } |
| 1728 | 1739 | ||
| 1729 | static std::string MakeSetValCodegenCCE(const ir::CallPtr& op, codegen::CodegenBase& codegen_base) | 1740 | static std::string MakeSetValCodegenCCE(const ir::CallPtr& op, codegen::CodegenBase& codegen_base) |
| @@ -1768,9 +1779,9 @@ static std::string MakeTileValidShapeCodegenCCE(const ir::CallPtr& op, codegen:: | |||
| 1768 | CHECK(axis >= 0 && axis <= 1) << "block.tile_valid_shape axis must be in [0, 1]"; | 1779 | CHECK(axis >= 0 && axis <= 1) << "block.tile_valid_shape axis must be in [0, 1]"; |
| 1769 | 1780 | ||
| 1770 | if (codegen.IsInSimtContext()) { | 1781 | if (codegen.IsInSimtContext()) { |
| 1771 | - return codegen.GetExprAsCode(op->args_[0]) + (axis == 0 ? "__valid_row" : "__valid_col"); | 1782 | + return "(int64_t)(" + codegen.GetExprAsCode(op->args_[0]) + (axis == 0 ? "__valid_row)" : "__valid_col)"); |
| 1772 | } | 1783 | } |
| 1773 | - return codegen.GetExprAsCode(op->args_[0]) + (axis == 0 ? ".GetValidRow()" : ".GetValidCol()"); | 1784 | + return "(int64_t)(" + codegen.GetExprAsCode(op->args_[0]) + (axis == 0 ? ".GetValidRow())" : ".GetValidCol())"); |
| 1774 | } | 1785 | } |
| 1775 | 1786 | ||
| 1776 | // getval/setval use the "block." IR namespace like every other explicit-output | 1787 | // getval/setval use the "block." IR namespace like every other explicit-output |
| @@ -1552,7 +1552,7 @@ static std::string EmitVFMuls(const ir::CallPtr& op, codegen::CodegenBase& codeg | |||
| 1552 | src_dt == DataType::UINT32 || src_dt == DataType::FP16 || src_dt == DataType::FP32)) | 1552 | src_dt == DataType::UINT32 || src_dt == DataType::FP16 || src_dt == DataType::FP32)) |
| 1553 | << "vf.muls src only supports INT16/UINT16/INT32/UINT32/FP16/FP32, got " << DTypeStr(src_dt); | 1553 | << "vf.muls src only supports INT16/UINT16/INT32/UINT32/FP16/FP32, got " << DTypeStr(src_dt); |
| 1554 | DataType scalar_dt = GetExprDtype(op->args_[2]); | 1554 | DataType scalar_dt = GetExprDtype(op->args_[2]); |
| 1555 | - if (scalar_dt == DataType::INDEX) { | 1555 | + if (scalar_dt == DataType::INDEX || scalar_dt == DataType::INT64) { |
| 1556 | scalar_dt = src_dt; | 1556 | scalar_dt = src_dt; |
| 1557 | } | 1557 | } |
| 1558 | CHECK((scalar_dt == DataType::INT16 || scalar_dt == DataType::UINT16 || scalar_dt == DataType::INT32 || | 1558 | CHECK((scalar_dt == DataType::INT16 || scalar_dt == DataType::UINT16 || scalar_dt == DataType::INT32 || |
| @@ -44,41 +44,41 @@ using namespace test_helpers; | |||
| 44 | 44 | ||
| 45 | class BlockOpsMemoryTest : public testing::Test {}; | 45 | class BlockOpsMemoryTest : public testing::Test {}; |
| 46 | 46 | ||
| 47 | -TEST_F(BlockOpsMemoryTest, GetBlockIdx_NoArgs_ReturnsIndexScalar) | 47 | +TEST_F(BlockOpsMemoryTest, GetBlockIdx_NoArgs_ReturnsInt64Scalar) |
| 48 | { | 48 | { |
| 49 | auto& reg = OpRegistry::GetInstance(); | 49 | auto& reg = OpRegistry::GetInstance(); |
| 50 | auto call = reg.Create("get_block_idx", {}, Sp()); | 50 | auto call = reg.Create("get_block_idx", {}, Sp()); |
| 51 | ASSERT_NE(call, nullptr); | 51 | ASSERT_NE(call, nullptr); |
| 52 | auto rt = As<ScalarType>(call->GetType()); | 52 | auto rt = As<ScalarType>(call->GetType()); |
| 53 | ASSERT_NE(rt, nullptr); | 53 | ASSERT_NE(rt, nullptr); |
| 54 | - EXPECT_EQ(rt->dtype_, DataType::INDEX); | 54 | + EXPECT_EQ(rt->dtype_, DataType::INT64); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | -TEST_F(BlockOpsMemoryTest, GetBlockNum_NoArgs_ReturnsIndexScalar) | 57 | +TEST_F(BlockOpsMemoryTest, GetBlockNum_NoArgs_ReturnsInt64Scalar) |
| 58 | { | 58 | { |
| 59 | auto& reg = OpRegistry::GetInstance(); | 59 | auto& reg = OpRegistry::GetInstance(); |
| 60 | auto call = reg.Create("get_block_num", {}, Sp()); | 60 | auto call = reg.Create("get_block_num", {}, Sp()); |
| 61 | auto rt = As<ScalarType>(call->GetType()); | 61 | auto rt = As<ScalarType>(call->GetType()); |
| 62 | ASSERT_NE(rt, nullptr); | 62 | ASSERT_NE(rt, nullptr); |
| 63 | - EXPECT_EQ(rt->dtype_, DataType::INDEX); | 63 | + EXPECT_EQ(rt->dtype_, DataType::INT64); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | -TEST_F(BlockOpsMemoryTest, GetSubblockIdx_NoArgs_ReturnsIndexScalar) | 66 | +TEST_F(BlockOpsMemoryTest, GetSubblockIdx_NoArgs_ReturnsInt64Scalar) |
| 67 | { | 67 | { |
| 68 | auto& reg = OpRegistry::GetInstance(); | 68 | auto& reg = OpRegistry::GetInstance(); |
| 69 | auto call = reg.Create("get_subblock_idx", {}, Sp()); | 69 | auto call = reg.Create("get_subblock_idx", {}, Sp()); |
| 70 | auto rt = As<ScalarType>(call->GetType()); | 70 | auto rt = As<ScalarType>(call->GetType()); |
| 71 | ASSERT_NE(rt, nullptr); | 71 | ASSERT_NE(rt, nullptr); |
| 72 | - EXPECT_EQ(rt->dtype_, DataType::INDEX); | 72 | + EXPECT_EQ(rt->dtype_, DataType::INT64); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | -TEST_F(BlockOpsMemoryTest, GetSubblockNum_NoArgs_ReturnsIndexScalar) | 75 | +TEST_F(BlockOpsMemoryTest, GetSubblockNum_NoArgs_ReturnsInt64Scalar) |
| 76 | { | 76 | { |
| 77 | auto& reg = OpRegistry::GetInstance(); | 77 | auto& reg = OpRegistry::GetInstance(); |
| 78 | auto call = reg.Create("get_subblock_num", {}, Sp()); | 78 | auto call = reg.Create("get_subblock_num", {}, Sp()); |
| 79 | auto rt = As<ScalarType>(call->GetType()); | 79 | auto rt = As<ScalarType>(call->GetType()); |
| 80 | ASSERT_NE(rt, nullptr); | 80 | ASSERT_NE(rt, nullptr); |
| 81 | - EXPECT_EQ(rt->dtype_, DataType::INDEX); | 81 | + EXPECT_EQ(rt->dtype_, DataType::INT64); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | TEST_F(BlockOpsMemoryTest, GetBlockIdx_WithArgs_Throws) | 84 | TEST_F(BlockOpsMemoryTest, GetBlockIdx_WithArgs_Throws) |
| @@ -203,7 +203,7 @@ TEST_F(BlockOpsMemoryTest, MakeTile_WithLayoutKwargs_ReturnsTileType) | |||
| 203 | // ============================================================================ | 203 | // ============================================================================ |
| 204 | // memory.cpp: block.tile_valid_shape | 204 | // memory.cpp: block.tile_valid_shape |
| 205 | // ============================================================================ | 205 | // ============================================================================ |
| 206 | -TEST_F(BlockOpsMemoryTest, TileValidShape_ReturnsUint32) | 206 | +TEST_F(BlockOpsMemoryTest, TileValidShape_ReturnsInt64) |
| 207 | { | 207 | { |
| 208 | auto& reg = OpRegistry::GetInstance(); | 208 | auto& reg = OpRegistry::GetInstance(); |
| 209 | auto tile = MakeTileVar("tile", {16, 32}, DataType::FP16); | 209 | auto tile = MakeTileVar("tile", {16, 32}, DataType::FP16); |
| @@ -211,7 +211,7 @@ TEST_F(BlockOpsMemoryTest, TileValidShape_ReturnsUint32) | |||
| 211 | Sp()); | 211 | Sp()); |
| 212 | auto rt = As<ScalarType>(call->GetType()); | 212 | auto rt = As<ScalarType>(call->GetType()); |
| 213 | ASSERT_NE(rt, nullptr); | 213 | ASSERT_NE(rt, nullptr); |
| 214 | - EXPECT_EQ(rt->dtype_, DataType::UINT32); | 214 | + EXPECT_EQ(rt->dtype_, DataType::INT64); |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | TEST_F(BlockOpsMemoryTest, TileValidShape_RejectsInvalidAxis) | 217 | TEST_F(BlockOpsMemoryTest, TileValidShape_RejectsInvalidAxis) |
| @@ -244,6 +244,25 @@ TEST_F(BlockOpsMemoryTest, GetVal_TileAndIndex_ReturnsScalarOfTileDtype) | |||
| 244 | EXPECT_EQ(rt->dtype_, DataType::FP16); | 244 | EXPECT_EQ(rt->dtype_, DataType::FP16); |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | +TEST_F(BlockOpsMemoryTest, GetVal_IntegerContainer_ReturnsInt64UnlessUint64) | ||
| 248 | +{ | ||
| 249 | + auto& reg = OpRegistry::GetInstance(); | ||
| 250 | + const std::vector<std::pair<DataType, DataType>> cases = { | ||
| 251 | + {DataType::INT8, DataType::INT64}, {DataType::INT16, DataType::INT64}, {DataType::INT32, DataType::INT64}, | ||
| 252 | + {DataType::INT64, DataType::INT64}, {DataType::UINT8, DataType::INT64}, {DataType::UINT16, DataType::INT64}, | ||
| 253 | + {DataType::UINT32, DataType::INT64}, {DataType::UINT64, DataType::UINT64}, | ||
| 254 | + }; | ||
| 255 | + for (const auto& [source_dtype, expected_dtype] : cases) { | ||
| 256 | + SCOPED_TRACE(source_dtype.ToString()); | ||
| 257 | + auto offset = MakeScalarVar("i", DataType::INT64); | ||
| 258 | + auto tile_call = reg.Create("block.getval", {MakeTileVar("tile", {64}, source_dtype), offset}, Sp()); | ||
| 259 | + auto tensor_call = reg.Create("block.getval", {MakeTensorVar("tensor", {64}, source_dtype), offset}, Sp()); | ||
| 260 | + | ||
| 261 | + EXPECT_EQ(As<ScalarType>(tile_call->GetType())->dtype_, expected_dtype); | ||
| 262 | + EXPECT_EQ(As<ScalarType>(tensor_call->GetType())->dtype_, expected_dtype); | ||
| 263 | + } | ||
| 264 | +} | ||
| 265 | + | ||
| 247 | TEST_F(BlockOpsMemoryTest, GetVal_WrongArgCount_Throws) | 266 | TEST_F(BlockOpsMemoryTest, GetVal_WrongArgCount_Throws) |
| 248 | { | 267 | { |
| 249 | auto& reg = OpRegistry::GetInstance(); | 268 | auto& reg = OpRegistry::GetInstance(); |
| @@ -1219,26 +1238,22 @@ TEST_F(BlockOpsOutMemoryTest, BlockFull_OutScalar_ReturnsOutType) | |||
| 1219 | EXPECT_NE(As<TileType>(call->GetType()), nullptr); | 1238 | EXPECT_NE(As<TileType>(call->GetType()), nullptr); |
| 1220 | } | 1239 | } |
| 1221 | 1240 | ||
| 1222 | -TEST_F(BlockOpsOutMemoryTest, BlockSsbufStore_ReturnsIndexScalar) | 1241 | +TEST_F(BlockOpsOutMemoryTest, BlockSsbufStore_ReturnsNone) |
| 1223 | { | 1242 | { |
| 1224 | auto& reg = OpRegistry::GetInstance(); | 1243 | auto& reg = OpRegistry::GetInstance(); |
| 1225 | auto struct_type = std::make_shared<TupleType>(std::vector<TypePtr>{std::make_shared<ScalarType>(DataType::INT64)}); | 1244 | auto struct_type = std::make_shared<TupleType>(std::vector<TypePtr>{std::make_shared<ScalarType>(DataType::INT64)}); |
| 1226 | auto struct_var = std::make_shared<Var>("state", struct_type, Sp()); | 1245 | auto struct_var = std::make_shared<Var>("state", struct_type, Sp()); |
| 1227 | auto call = reg.Create("block.ssbuf_store", {struct_var, MakeScalarVar("off", DataType::INT32)}, Sp()); | 1246 | auto call = reg.Create("block.ssbuf_store", {struct_var, MakeScalarVar("off", DataType::INT32)}, Sp()); |
| 1228 | - auto rt = As<ScalarType>(call->GetType()); | 1247 | + EXPECT_NE(As<NoneType>(call->GetType()), nullptr); |
| 1229 | - ASSERT_NE(rt, nullptr); | ||
| 1230 | - EXPECT_EQ(rt->dtype_, DataType::INDEX); | ||
| 1231 | } | 1248 | } |
| 1232 | 1249 | ||
| 1233 | -TEST_F(BlockOpsOutMemoryTest, BlockSsbufLoad_ReturnsIndexScalar) | 1250 | +TEST_F(BlockOpsOutMemoryTest, BlockSsbufLoad_ReturnsNone) |
| 1234 | { | 1251 | { |
| 1235 | auto& reg = OpRegistry::GetInstance(); | 1252 | auto& reg = OpRegistry::GetInstance(); |
| 1236 | auto struct_type = std::make_shared<TupleType>(std::vector<TypePtr>{std::make_shared<ScalarType>(DataType::INT64)}); | 1253 | auto struct_type = std::make_shared<TupleType>(std::vector<TypePtr>{std::make_shared<ScalarType>(DataType::INT64)}); |
| 1237 | auto struct_var = std::make_shared<Var>("state", struct_type, Sp()); | 1254 | auto struct_var = std::make_shared<Var>("state", struct_type, Sp()); |
| 1238 | auto call = reg.Create("block.ssbuf_load", {struct_var, MakeScalarVar("off", DataType::INT32)}, Sp()); | 1255 | auto call = reg.Create("block.ssbuf_load", {struct_var, MakeScalarVar("off", DataType::INT32)}, Sp()); |
| 1239 | - auto rt = As<ScalarType>(call->GetType()); | 1256 | + EXPECT_NE(As<NoneType>(call->GetType()), nullptr); |
| 1240 | - ASSERT_NE(rt, nullptr); | ||
| 1241 | - EXPECT_EQ(rt->dtype_, DataType::INDEX); | ||
| 1242 | } | 1257 | } |
| 1243 | 1258 | ||
| 1244 | // ============================================================================ | 1259 | // ============================================================================ |
| @@ -130,7 +130,7 @@ std::string RunCodegen(const std::string& op_name, const ir::CallPtr& call) | |||
| 130 | 130 | ||
| 131 | TEST(BackendCceOpsTest, GetBlockIdx) | 131 | TEST(BackendCceOpsTest, GetBlockIdx) |
| 132 | { | 132 | { |
| 133 | - auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT32); | 133 | + auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); |
| 134 | auto result = MakeVar("idx", int_type); | 134 | auto result = MakeVar("idx", int_type); |
| 135 | auto call = std::make_shared<const ir::Call>("get_block_idx", std::vector<ir::ExprPtr>{}, int_type, | 135 | auto call = std::make_shared<const ir::Call>("get_block_idx", std::vector<ir::ExprPtr>{}, int_type, |
| 136 | ir::Span::Unknown()); | 136 | ir::Span::Unknown()); |
| @@ -138,24 +138,24 @@ TEST(BackendCceOpsTest, GetBlockIdx) | |||
| 138 | 138 | ||
| 139 | codegen::CCECodegen codegen(ir::SectionKind::Cube); | 139 | codegen::CCECodegen codegen(ir::SectionKind::Cube); |
| 140 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); | 140 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); |
| 141 | - EXPECT_NE(generated.find("(int32_t)(get_block_idx())"), std::string::npos); | 141 | + EXPECT_NE(generated.find("(int64_t)(get_block_idx())"), std::string::npos); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | TEST(BackendCceOpsTest, GetBlockIdxVectorUsesGlobalAivIndex) | 144 | TEST(BackendCceOpsTest, GetBlockIdxVectorUsesGlobalAivIndex) |
| 145 | { | 145 | { |
| 146 | - auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT32); | 146 | + auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); |
| 147 | auto call = std::make_shared<const ir::Call>("get_block_idx", std::vector<ir::ExprPtr>{}, int_type, | 147 | auto call = std::make_shared<const ir::Call>("get_block_idx", std::vector<ir::ExprPtr>{}, int_type, |
| 148 | ir::Span::Unknown()); | 148 | ir::Span::Unknown()); |
| 149 | const auto* info = BackendCCE::Instance().GetOpInfo("get_block_idx"); | 149 | const auto* info = BackendCCE::Instance().GetOpInfo("get_block_idx"); |
| 150 | ASSERT_NE(info, nullptr); | 150 | ASSERT_NE(info, nullptr); |
| 151 | 151 | ||
| 152 | codegen::CCECodegen codegen(ir::SectionKind::Vector); | 152 | codegen::CCECodegen codegen(ir::SectionKind::Vector); |
| 153 | - EXPECT_EQ(info->codegen_func(call, codegen), "(int32_t)(get_block_idx() * get_subblockdim() + get_subblockid())"); | 153 | + EXPECT_EQ(info->codegen_func(call, codegen), "(int64_t)(get_block_idx() * get_subblockdim() + get_subblockid())"); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | TEST(BackendCceOpsTest, GetBlockNum) | 156 | TEST(BackendCceOpsTest, GetBlockNum) |
| 157 | { | 157 | { |
| 158 | - auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT32); | 158 | + auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); |
| 159 | auto result = MakeVar("num", int_type); | 159 | auto result = MakeVar("num", int_type); |
| 160 | auto call = std::make_shared<const ir::Call>("get_block_num", std::vector<ir::ExprPtr>{}, int_type, | 160 | auto call = std::make_shared<const ir::Call>("get_block_num", std::vector<ir::ExprPtr>{}, int_type, |
| 161 | ir::Span::Unknown()); | 161 | ir::Span::Unknown()); |
| @@ -163,7 +163,7 @@ TEST(BackendCceOpsTest, GetBlockNum) | |||
| 163 | 163 | ||
| 164 | codegen::CCECodegen codegen(ir::SectionKind::Vector); | 164 | codegen::CCECodegen codegen(ir::SectionKind::Vector); |
| 165 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); | 165 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); |
| 166 | - EXPECT_NE(generated.find("(int32_t)(get_block_num())"), std::string::npos); | 166 | + EXPECT_NE(generated.find("(int64_t)(get_block_num())"), std::string::npos); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | TEST(BackendCceOpsTest, GetSpr) | 169 | TEST(BackendCceOpsTest, GetSpr) |
| @@ -180,7 +180,7 @@ TEST(BackendCceOpsTest, GetSpr) | |||
| 180 | 180 | ||
| 181 | TEST(BackendCceOpsTest, GetSubBlockIdx) | 181 | TEST(BackendCceOpsTest, GetSubBlockIdx) |
| 182 | { | 182 | { |
| 183 | - auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT32); | 183 | + auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); |
| 184 | auto result = MakeVar("sub", int_type); | 184 | auto result = MakeVar("sub", int_type); |
| 185 | auto call = std::make_shared<const ir::Call>("get_subblock_idx", std::vector<ir::ExprPtr>{}, int_type, | 185 | auto call = std::make_shared<const ir::Call>("get_subblock_idx", std::vector<ir::ExprPtr>{}, int_type, |
| 186 | ir::Span::Unknown()); | 186 | ir::Span::Unknown()); |
| @@ -188,12 +188,12 @@ TEST(BackendCceOpsTest, GetSubBlockIdx) | |||
| 188 | 188 | ||
| 189 | codegen::CCECodegen codegen(ir::SectionKind::Vector); | 189 | codegen::CCECodegen codegen(ir::SectionKind::Vector); |
| 190 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); | 190 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); |
| 191 | - EXPECT_NE(generated.find("(int32_t)(get_subblockid())"), std::string::npos); | 191 | + EXPECT_NE(generated.find("(int64_t)(get_subblockid())"), std::string::npos); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | TEST(BackendCceOpsTest, GetSubBlockNumIsTargetSpecific) | 194 | TEST(BackendCceOpsTest, GetSubBlockNumIsTargetSpecific) |
| 195 | { | 195 | { |
| 196 | - auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT32); | 196 | + auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); |
| 197 | auto call = std::make_shared<const ir::Call>("get_subblock_num", std::vector<ir::ExprPtr>{}, int_type, | 197 | auto call = std::make_shared<const ir::Call>("get_subblock_num", std::vector<ir::ExprPtr>{}, int_type, |
| 198 | ir::Span::Unknown()); | 198 | ir::Span::Unknown()); |
| 199 | const auto* info = BackendCCE::Instance().GetOpInfo("get_subblock_num"); | 199 | const auto* info = BackendCCE::Instance().GetOpInfo("get_subblock_num"); |
| @@ -201,10 +201,10 @@ TEST(BackendCceOpsTest, GetSubBlockNumIsTargetSpecific) | |||
| 201 | EXPECT_EQ(info->pipe, ir::PipeType::V); | 201 | EXPECT_EQ(info->pipe, ir::PipeType::V); |
| 202 | 202 | ||
| 203 | codegen::CCECodegen cube_codegen(ir::SectionKind::Cube); | 203 | codegen::CCECodegen cube_codegen(ir::SectionKind::Cube); |
| 204 | - EXPECT_EQ(info->codegen_func(call, cube_codegen), "(int32_t)(1)"); | 204 | + EXPECT_EQ(info->codegen_func(call, cube_codegen), "(int64_t)(1)"); |
| 205 | 205 | ||
| 206 | codegen::CCECodegen vector_codegen(ir::SectionKind::Vector); | 206 | codegen::CCECodegen vector_codegen(ir::SectionKind::Vector); |
| 207 | - EXPECT_EQ(info->codegen_func(call, vector_codegen), "(int32_t)(get_subblockdim())"); | 207 | + EXPECT_EQ(info->codegen_func(call, vector_codegen), "(int64_t)(get_subblockdim())"); |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | TEST(BackendCceOpsTest, DebugTrap) | 210 | TEST(BackendCceOpsTest, DebugTrap) |
| @@ -923,13 +923,13 @@ TEST(BackendCceOpsTest, BlockMakeTileAndSetValTile) | |||
| 923 | 923 | ||
| 924 | TEST(BackendCceOpsTest, BlockGetValTile) | 924 | TEST(BackendCceOpsTest, BlockGetValTile) |
| 925 | { | 925 | { |
| 926 | - auto tile_type = MakeTileType({16, 16}, ir::DataType::FP16); | 926 | + auto tile_type = MakeTileType({16, 16}, ir::DataType::INT32); |
| 927 | auto tile = MakeVar("tile", tile_type); | 927 | auto tile = MakeVar("tile", tile_type); |
| 928 | auto make_tile = std::make_shared<const ir::Call>("block.make_tile", std::vector<ir::ExprPtr>{}, tile_type, | 928 | auto make_tile = std::make_shared<const ir::Call>("block.make_tile", std::vector<ir::ExprPtr>{}, tile_type, |
| 929 | ir::Span::Unknown()); | 929 | ir::Span::Unknown()); |
| 930 | auto tile_assign = std::make_shared<const ir::AssignStmt>(tile, make_tile, ir::Span::Unknown()); | 930 | auto tile_assign = std::make_shared<const ir::AssignStmt>(tile, make_tile, ir::Span::Unknown()); |
| 931 | 931 | ||
| 932 | - auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT32); | 932 | + auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); |
| 933 | auto result = MakeVar("val", int_type); | 933 | auto result = MakeVar("val", int_type); |
| 934 | auto getval = std::make_shared<const ir::Call>("block.getval", std::vector<ir::ExprPtr>{tile, MakeConstInt(3)}, | 934 | auto getval = std::make_shared<const ir::Call>("block.getval", std::vector<ir::ExprPtr>{tile, MakeConstInt(3)}, |
| 935 | int_type, ir::Span::Unknown()); | 935 | int_type, ir::Span::Unknown()); |
| @@ -940,7 +940,7 @@ TEST(BackendCceOpsTest, BlockGetValTile) | |||
| 940 | 940 | ||
| 941 | codegen::CCECodegen codegen(ir::SectionKind::Vector); | 941 | codegen::CCECodegen codegen(ir::SectionKind::Vector); |
| 942 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); | 942 | auto generated = codegen.GenerateSingle(MakeProgram(body), "a3"); |
| 943 | - EXPECT_NE(generated.find(".GetValue(3)"), std::string::npos); | 943 | + EXPECT_NE(generated.find("(int64_t)(tile.GetValue(3))"), std::string::npos); |
| 944 | } | 944 | } |
| 945 | 945 | ||
| 946 | // ============================================================================ | 946 | // ============================================================================ |
| @@ -950,10 +950,10 @@ TEST(BackendCceOpsTest, BlockGetValTile) | |||
| 950 | TEST(BackendCceOpsTest, BlockGetValTensor) | 950 | TEST(BackendCceOpsTest, BlockGetValTensor) |
| 951 | { | 951 | { |
| 952 | auto tensor = MakeTensorVar("data", {64}, ir::DataType::FP32); | 952 | auto tensor = MakeTensorVar("data", {64}, ir::DataType::FP32); |
| 953 | - auto int_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT32); | 953 | + auto scalar_type = std::make_shared<const ir::ScalarType>(ir::DataType::FP32); |
| 954 | - auto result = MakeVar("val", int_type); | 954 | + auto result = MakeVar("val", scalar_type); |
| 955 | auto call = std::make_shared<const ir::Call>("block.getval", std::vector<ir::ExprPtr>{tensor, MakeConstInt(5)}, | 955 | auto call = std::make_shared<const ir::Call>("block.getval", std::vector<ir::ExprPtr>{tensor, MakeConstInt(5)}, |
| 956 | - int_type, ir::Span::Unknown()); | 956 | + scalar_type, ir::Span::Unknown()); |
| 957 | auto body = std::make_shared<const ir::AssignStmt>(result, call, ir::Span::Unknown()); | 957 | auto body = std::make_shared<const ir::AssignStmt>(result, call, ir::Span::Unknown()); |
| 958 | 958 | ||
| 959 | codegen::CCECodegen codegen(ir::SectionKind::Vector); | 959 | codegen::CCECodegen codegen(ir::SectionKind::Vector); |
| @@ -962,6 +962,35 @@ TEST(BackendCceOpsTest, BlockGetValTensor) | |||
| 962 | EXPECT_NE(generated.find("+ 5)"), std::string::npos); | 962 | EXPECT_NE(generated.find("+ 5)"), std::string::npos); |
| 963 | } | 963 | } |
| 964 | 964 | ||
| 965 | +TEST(BackendCceOpsTest, BlockGetValTensorInt32CastsResult) | ||
| 966 | +{ | ||
| 967 | + auto tensor = MakeTensorVar("data", {64}, ir::DataType::INT32); | ||
| 968 | + auto int64_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); | ||
| 969 | + auto result = MakeVar("val", int64_type); | ||
| 970 | + auto call = std::make_shared<const ir::Call>("block.getval", std::vector<ir::ExprPtr>{tensor, MakeConstInt(5)}, | ||
| 971 | + int64_type, ir::Span::Unknown()); | ||
| 972 | + auto body = std::make_shared<const ir::AssignStmt>(result, call, ir::Span::Unknown()); | ||
| 973 | + | ||
| 974 | + codegen::CCECodegen codegen(ir::SectionKind::Vector); | ||
| 975 | + auto generated = codegen.GenerateSingle(MakeProgram(body, {tensor}), "a3"); | ||
| 976 | + EXPECT_NE(generated.find("(int64_t)(*((__gm__ int32_t*)"), std::string::npos); | ||
| 977 | +} | ||
| 978 | + | ||
| 979 | +TEST(BackendCceOpsTest, BlockGetValTensorUint64DoesNotCastResult) | ||
| 980 | +{ | ||
| 981 | + auto tensor = MakeTensorVar("data", {64}, ir::DataType::UINT64); | ||
| 982 | + auto uint64_type = std::make_shared<const ir::ScalarType>(ir::DataType::UINT64); | ||
| 983 | + auto result = MakeVar("val", uint64_type); | ||
| 984 | + auto call = std::make_shared<const ir::Call>("block.getval", std::vector<ir::ExprPtr>{tensor, MakeConstInt(5)}, | ||
| 985 | + uint64_type, ir::Span::Unknown()); | ||
| 986 | + auto body = std::make_shared<const ir::AssignStmt>(result, call, ir::Span::Unknown()); | ||
| 987 | + | ||
| 988 | + codegen::CCECodegen codegen(ir::SectionKind::Vector); | ||
| 989 | + auto generated = codegen.GenerateSingle(MakeProgram(body, {tensor}), "a3"); | ||
| 990 | + EXPECT_NE(generated.find("*((__gm__ uint64_t*)"), std::string::npos); | ||
| 991 | + EXPECT_EQ(generated.find("(uint64_t)(*((__gm__ uint64_t*)"), std::string::npos); | ||
| 992 | +} | ||
| 993 | + | ||
| 965 | TEST(BackendCceOpsTest, BlockSetValTensor) | 994 | TEST(BackendCceOpsTest, BlockSetValTensor) |
| 966 | { | 995 | { |
| 967 | auto tensor = MakeTensorVar("data", {64}, ir::DataType::FP32); | 996 | auto tensor = MakeTensorVar("data", {64}, ir::DataType::FP32); |
| @@ -1623,7 +1623,7 @@ TEST(BackendCCEVFOpsTest, DoesNotCoerceForFloatSrc) | |||
| 1623 | EXPECT_NE(emitted.find("3.5"), std::string::npos) << emitted; | 1623 | EXPECT_NE(emitted.find("3.5"), std::string::npos) << emitted; |
| 1624 | } | 1624 | } |
| 1625 | 1625 | ||
| 1626 | -TEST(BackendCCEVFOpsTest, MulsAcceptsIndexScalarConvertedToSrcType) | 1626 | +TEST(BackendCCEVFOpsTest, MulsAcceptsIndexOrInt64ScalarConvertedToSrcType) |
| 1627 | { | 1627 | { |
| 1628 | CapturingCCECodegen codegen(ir::SectionKind::Vector); | 1628 | CapturingCCECodegen codegen(ir::SectionKind::Vector); |
| 1629 | auto i32_dst = MakeVar("i32_dst", ir::DataType::INT32); | 1629 | auto i32_dst = MakeVar("i32_dst", ir::DataType::INT32); |
| @@ -1633,8 +1633,9 @@ TEST(BackendCCEVFOpsTest, MulsAcceptsIndexScalarConvertedToSrcType) | |||
| 1633 | codegen.RegisterRegTensorVar("i32_src"); | 1633 | codegen.RegisterRegTensorVar("i32_src"); |
| 1634 | const Kwargs zeroing = {{"mode", EnumValue(ir::MergeMode::ZEROING)}}; | 1634 | const Kwargs zeroing = {{"mode", EnumValue(ir::MergeMode::ZEROING)}}; |
| 1635 | 1635 | ||
| 1636 | - // Python int 3 → ConstInt(INDEX) → converted to src_dt (INT32) → emits "3" | 1636 | + // Keep accepting the legacy INDEX scalar and the new INT64 default integer. |
| 1637 | ExpectInvoke(codegen, "vf.muls", {"vmuls("}, {i32_dst, i32_src, IndexVal(3), mask}, zeroing); | 1637 | ExpectInvoke(codegen, "vf.muls", {"vmuls("}, {i32_dst, i32_src, IndexVal(3), mask}, zeroing); |
| 1638 | + ExpectInvoke(codegen, "vf.muls", {"vmuls("}, {i32_dst, i32_src, Int(3), mask}, zeroing); | ||
| 1638 | } | 1639 | } |
| 1639 | 1640 | ||
| 1640 | TEST(BackendCCEVFOpsTest, MulsRejectsUnlistedIntTypes) | 1641 | TEST(BackendCCEVFOpsTest, MulsRejectsUnlistedIntTypes) |
| @@ -1683,7 +1684,7 @@ TEST(BackendCCEVFOpsTest, StoreAlignAcceptsCompatibleIntDtypes) | |||
| 1683 | ExpectInvoke(codegen, "vf.store_align", {"vsts("}, {tile_i32, u32_reg, mask}); | 1684 | ExpectInvoke(codegen, "vf.store_align", {"vsts("}, {tile_i32, u32_reg, mask}); |
| 1684 | } | 1685 | } |
| 1685 | 1686 | ||
| 1686 | -TEST(BackendCCEVFOpsTest, AxpyAcceptsIndexScalar) | 1687 | +TEST(BackendCCEVFOpsTest, AxpyAcceptsInt64Scalar) |
| 1687 | { | 1688 | { |
| 1688 | CapturingCCECodegen codegen(ir::SectionKind::Vector); | 1689 | CapturingCCECodegen codegen(ir::SectionKind::Vector); |
| 1689 | auto i64_dst = MakeVar("i64_dst", ir::DataType::INT64); | 1690 | auto i64_dst = MakeVar("i64_dst", ir::DataType::INT64); |
| @@ -1693,7 +1694,7 @@ TEST(BackendCCEVFOpsTest, AxpyAcceptsIndexScalar) | |||
| 1693 | codegen.RegisterRegTensorVar("i64_src"); | 1694 | codegen.RegisterRegTensorVar("i64_src"); |
| 1694 | const Kwargs zeroing = {{"mode", EnumValue(ir::MergeMode::ZEROING)}}; | 1695 | const Kwargs zeroing = {{"mode", EnumValue(ir::MergeMode::ZEROING)}}; |
| 1695 | 1696 | ||
| 1696 | - // Python int 2 → ConstInt(INDEX) → allowed for axpy | 1697 | + // Python int 2 → ConstInt(INT64) → allowed for axpy |
| 1697 | ExpectInvoke(codegen, "vf.axpy", {"vaxpy("}, {i64_dst, i64_src, Int(2), mask}, zeroing); | 1698 | ExpectInvoke(codegen, "vf.axpy", {"vaxpy("}, {i64_dst, i64_src, Int(2), mask}, zeroing); |
| 1698 | } | 1699 | } |
| 1699 | 1700 | ||
| @@ -852,26 +852,26 @@ TEST(CCECodegenTest, EmitsKernelTileValidShapeGetters) | |||
| 852 | auto tile_type = std::make_shared<const ir::TileType>(std::vector<int64_t>{16, 32}, ir::DataType::FP16, | 852 | auto tile_type = std::make_shared<const ir::TileType>(std::vector<int64_t>{16, 32}, ir::DataType::FP16, |
| 853 | std::optional<ir::MemRefPtr>(std::nullopt), | 853 | std::optional<ir::MemRefPtr>(std::nullopt), |
| 854 | std::optional<ir::TileView>(std::nullopt)); | 854 | std::optional<ir::TileView>(std::nullopt)); |
| 855 | - auto u32 = std::make_shared<const ir::ScalarType>(ir::DataType::UINT32); | 855 | + auto int64_type = std::make_shared<const ir::ScalarType>(ir::DataType::INT64); |
| 856 | auto tile = MakeVar("tile", tile_type); | 856 | auto tile = MakeVar("tile", tile_type); |
| 857 | auto make_tile = std::make_shared<const ir::Call>("block.make_tile", std::vector<ir::ExprPtr>{}, tile_type, | 857 | auto make_tile = std::make_shared<const ir::Call>("block.make_tile", std::vector<ir::ExprPtr>{}, tile_type, |
| 858 | ir::Span::Unknown()); | 858 | ir::Span::Unknown()); |
| 859 | auto valid_shape = [&](int axis) { | 859 | auto valid_shape = [&](int axis) { |
| 860 | return std::make_shared<const ir::Call>("block.tile_valid_shape", std::vector<ir::ExprPtr>{tile}, | 860 | return std::make_shared<const ir::Call>("block.tile_valid_shape", std::vector<ir::ExprPtr>{tile}, |
| 861 | - std::vector<std::pair<std::string, std::any>>{{"axis", axis}}, u32, | 861 | + std::vector<std::pair<std::string, std::any>>{{"axis", axis}}, |
| 862 | - ir::Span::Unknown()); | 862 | + int64_type, ir::Span::Unknown()); |
| 863 | }; | 863 | }; |
| 864 | auto body = std::make_shared<const ir::SeqStmts>( | 864 | auto body = std::make_shared<const ir::SeqStmts>( |
| 865 | std::vector<ir::StmtPtr>{ | 865 | std::vector<ir::StmtPtr>{ |
| 866 | std::make_shared<const ir::AssignStmt>(tile, make_tile, ir::Span::Unknown()), | 866 | std::make_shared<const ir::AssignStmt>(tile, make_tile, ir::Span::Unknown()), |
| 867 | - std::make_shared<const ir::AssignStmt>(MakeVar("rows", u32), valid_shape(0), ir::Span::Unknown()), | 867 | + std::make_shared<const ir::AssignStmt>(MakeVar("rows", int64_type), valid_shape(0), ir::Span::Unknown()), |
| 868 | - std::make_shared<const ir::AssignStmt>(MakeVar("cols", u32), valid_shape(1), ir::Span::Unknown()), | 868 | + std::make_shared<const ir::AssignStmt>(MakeVar("cols", int64_type), valid_shape(1), ir::Span::Unknown()), |
| 869 | }, | 869 | }, |
| 870 | ir::Span::Unknown()); | 870 | ir::Span::Unknown()); |
| 871 | CCECodegen codegen(ir::SectionKind::Vector); | 871 | CCECodegen codegen(ir::SectionKind::Vector); |
| 872 | std::string generated = codegen.GenerateSingle(MakeProgram(body), "a5"); | 872 | std::string generated = codegen.GenerateSingle(MakeProgram(body), "a5"); |
| 873 | - EXPECT_NE(generated.find(".GetValidRow()"), std::string::npos); | 873 | + EXPECT_NE(generated.find("(int64_t)(tile.GetValidRow())"), std::string::npos); |
| 874 | - EXPECT_NE(generated.find(".GetValidCol()"), std::string::npos); | 874 | + EXPECT_NE(generated.find("(int64_t)(tile.GetValidCol())"), std::string::npos); |
| 875 | } | 875 | } |
| 876 | 876 | ||
| 877 | TEST(CCECodegenTest, ComputesTensorOffsetAndRejectsRankMismatch) | 877 | TEST(CCECodegenTest, ComputesTensorOffsetAndRejectsRankMismatch) |
| @@ -511,7 +511,7 @@ TEST(CCESimtCodegenTest, DoesNotInterceptOrdinaryKernelCallsWithMatchingCalleeNa | |||
| 511 | auto entry_function = generated.substr(entry_pos, kernel_pos - entry_pos); | 511 | auto entry_function = generated.substr(entry_pos, kernel_pos - entry_pos); |
| 512 | auto kernel_function = generated.substr(kernel_pos); | 512 | auto kernel_function = generated.substr(kernel_pos); |
| 513 | EXPECT_EQ(CountOccurrences(entry_function, "get_subblock_idx();"), 1u); | 513 | EXPECT_EQ(CountOccurrences(entry_function, "get_subblock_idx();"), 1u); |
| 514 | - EXPECT_EQ(CountOccurrences(kernel_function, "(int32_t)(get_subblockid())"), 1u); | 514 | + EXPECT_EQ(CountOccurrences(kernel_function, "(int64_t)(get_subblockid())"), 1u); |
| 515 | } | 515 | } |
| 516 | 516 | ||
| 517 | TEST(CCESimtCodegenTest, GeneratesRegisteredSynchronizationScalarCastAndMathOperations) | 517 | TEST(CCESimtCodegenTest, GeneratesRegisteredSynchronizationScalarCastAndMathOperations) |
| @@ -60,7 +60,7 @@ def _is_int(value: object) -> bool: | |||
| 60 | def _normalize_expr( | 60 | def _normalize_expr( |
| 61 | value: int | float | _ir.Expr, | 61 | value: int | float | _ir.Expr, |
| 62 | span: _ir.Span | None = None, | 62 | span: _ir.Span | None = None, |
| 63 | - int_dtype: DataType = DataType.INDEX, | 63 | + int_dtype: DataType | None = None, |
| 64 | float_dtype: DataType = DataType.FP32, | 64 | float_dtype: DataType = DataType.FP32, |
| 65 | ) -> _ir.Expr: | 65 | ) -> _ir.Expr: |
| 66 | """Convert Python values to IR expressions. | 66 | """Convert Python values to IR expressions. |
| @@ -68,7 +68,8 @@ def _normalize_expr( | |||
| 68 | Args: | 68 | Args: |
| 69 | value: Python int/float or existing Expr | 69 | value: Python int/float or existing Expr |
| 70 | span: Optional span for created constants | 70 | span: Optional span for created constants |
| 71 | - int_dtype: Data type to use for integer constants (default: INDEX) | 71 | + int_dtype: Explicit data type for integer constants. By default, use |
| 72 | + INT64 unless the value requires UINT64. | ||
| 72 | float_dtype: Data type to use for float constants (default: FP32) | 73 | float_dtype: Data type to use for float constants (default: FP32) |
| 73 | 74 | ||
| 74 | Returns: | 75 | Returns: |
| @@ -109,7 +110,7 @@ def _normalize_shape( | |||
| 109 | Raises: | 110 | Raises: |
| 110 | TypeError: If shape contains non-int, non-Expr values | 111 | TypeError: If shape contains non-int, non-Expr values |
| 111 | """ | 112 | """ |
| 112 | - return [_normalize_expr(dim, span, int_dtype=DataType.INDEX) for dim in shape] | 113 | + return [_normalize_expr(dim, span, int_dtype=DataType.INT64) for dim in shape] |
| 113 | 114 | ||
| 114 | 115 | ||
| 115 | def _to_make_tuple( | 116 | def _to_make_tuple( |
| @@ -137,7 +138,7 @@ def _to_make_tuple( | |||
| 137 | value_type = getattr(value, "type", None) | 138 | value_type = getattr(value, "type", None) |
| 138 | if isinstance(value_type, _ir.TupleType): | 139 | if isinstance(value_type, _ir.TupleType): |
| 139 | elements = [ | 140 | elements = [ |
| 140 | - _ir.GetItemExpr(value, _ir.ConstInt(i, DataType.INDEX, actual_span), actual_span) | 141 | + _ir.GetItemExpr(value, _ir.ConstInt(i, DataType.INT64, actual_span), actual_span) |
| 141 | for i in range(len(value_type.types)) | 142 | for i in range(len(value_type.types)) |
| 142 | ] | 143 | ] |
| 143 | return _ir.MakeTuple(elements, actual_span) | 144 | return _ir.MakeTuple(elements, actual_span) |
| @@ -1138,7 +1138,7 @@ def _ir_getval(container: Expr, offset: int | Expr, *, span: Span | None = None) | |||
| 1138 | "field, use attribute access (e.g. tiling.axis1) instead.", | 1138 | "field, use attribute access (e.g. tiling.axis1) instead.", |
| 1139 | ) | 1139 | ) |
| 1140 | _check_scalar_access_supported("getval", container, actual_span) | 1140 | _check_scalar_access_supported("getval", container, actual_span) |
| 1141 | - offset_expr = offset if isinstance(offset, Expr) else _normalize_expr(offset, actual_span, int_dtype=DataType.INDEX) | 1141 | + offset_expr = offset if isinstance(offset, Expr) else _normalize_expr(offset, actual_span, int_dtype=DataType.INT64) |
| 1142 | return _ir_core.create_op_call(block_ir_op("getval"), [container, offset_expr], {}, actual_span) | 1142 | return _ir_core.create_op_call(block_ir_op("getval"), [container, offset_expr], {}, actual_span) |
| 1143 | 1143 | ||
| 1144 | 1144 | ||
| @@ -1155,7 +1155,7 @@ def _ir_setval(container: Expr, offset: int | Expr, value: int | float | Expr, * | |||
| 1155 | "field, use attribute assignment (e.g. tiling.axis1 = ...) instead.", | 1155 | "field, use attribute assignment (e.g. tiling.axis1 = ...) instead.", |
| 1156 | ) | 1156 | ) |
| 1157 | _check_scalar_access_supported("setval", container, actual_span) | 1157 | _check_scalar_access_supported("setval", container, actual_span) |
| 1158 | - offset_expr = offset if isinstance(offset, Expr) else _normalize_expr(offset, actual_span, int_dtype=DataType.INDEX) | 1158 | + offset_expr = offset if isinstance(offset, Expr) else _normalize_expr(offset, actual_span, int_dtype=DataType.INT64) |
| 1159 | if not isinstance(value, Expr): | 1159 | if not isinstance(value, Expr): |
| 1160 | container_dtype = container.type.dtype | 1160 | container_dtype = container.type.dtype |
| 1161 | value_expr = _normalize_expr(value, actual_span, int_dtype=container_dtype, float_dtype=container_dtype) | 1161 | value_expr = _normalize_expr(value, actual_span, int_dtype=container_dtype, float_dtype=container_dtype) |
| @@ -3944,11 +3944,11 @@ def _parse_set_validshape(self, call: ast.Call) -> Expr: | |||
| 3944 | tiles = self.lower_attr_access(group_var, "tiles", span) | 3944 | tiles = self.lower_attr_access(group_var, "tiles", span) |
| 3945 | 3945 | ||
| 3946 | for i in range(n_tiles): | 3946 | for i in range(n_tiles): |
| 3947 | - tile_ir = _ir_core.GetItemExpr(tiles, ConstInt(i, DataType.INDEX, span), span) | 3947 | + tile_ir = _ir_core.GetItemExpr(tiles, ConstInt(i, DataType.INT64, span), span) |
| 3948 | vs_call = _ir_set_validshape(tile_ir, shape, span=span) | 3948 | vs_call = _ir_set_validshape(tile_ir, shape, span=span) |
| 3949 | self.builder.emit(_ir_core.EvalStmt(vs_call, span)) | 3949 | self.builder.emit(_ir_core.EvalStmt(vs_call, span)) |
| 3950 | 3950 | ||
| 3951 | - return ConstInt(0, DataType.INDEX, span) | 3951 | + return ConstInt(0, DataType.INT64, span) |
| 3952 | 3952 | ||
| 3953 | result = _ir_set_validshape(*args, **kwargs, span=span) | 3953 | result = _ir_set_validshape(*args, **kwargs, span=span) |
| 3954 | 3954 | ||
| @@ -137,7 +137,7 @@ def addptr(ptr: Expr, offset: int | Expr, span: Span | None = None) -> Call: | |||
| 137 | _check_addptr_dtype(ptr) | 137 | _check_addptr_dtype(ptr) |
| 138 | actual_span = _get_span_or_capture(span) | 138 | actual_span = _get_span_or_capture(span) |
| 139 | if isinstance(offset, int): | 139 | if isinstance(offset, int): |
| 140 | - offset_expr = _normalize_expr(offset, actual_span, int_dtype=DataType.INDEX) | 140 | + offset_expr = _normalize_expr(offset, actual_span, int_dtype=DataType.INT64) |
| 141 | else: | 141 | else: |
| 142 | offset_expr = offset | 142 | offset_expr = offset |
| 143 | return _ir_core.create_op_call("ptr.addptr", [ptr, offset_expr], {}, actual_span) | 143 | return _ir_core.create_op_call("ptr.addptr", [ptr, offset_expr], {}, actual_span) |
| @@ -438,8 +438,8 @@ def transpose(tensor: Expr, axis1: int, axis2: int, span: Span | None = None) -> | |||
| 438 | Call expression for tensor transpose | 438 | Call expression for tensor transpose |
| 439 | """ | 439 | """ |
| 440 | actual_span = _get_span_or_capture(span) | 440 | actual_span = _get_span_or_capture(span) |
| 441 | - axis1_expr = ConstInt(axis1, DataType.INDEX, actual_span) | 441 | + axis1_expr = ConstInt(axis1, DataType.INT64, actual_span) |
| 442 | - axis2_expr = ConstInt(axis2, DataType.INDEX, actual_span) | 442 | + axis2_expr = ConstInt(axis2, DataType.INT64, actual_span) |
| 443 | 443 | ||
| 444 | args = [tensor, axis1_expr, axis2_expr] | 444 | args = [tensor, axis1_expr, axis2_expr] |
| 445 | 445 | ||
| @@ -301,7 +301,7 @@ class AssignmentParserMixin: | |||
| 301 | continue | 301 | continue |
| 302 | item_expr = ir.GetItemExpr( | 302 | item_expr = ir.GetItemExpr( |
| 303 | tuple_var, | 303 | tuple_var, |
| 304 | - ir.ConstInt(i, DataType.INDEX, ir.Span.unknown()), | 304 | + ir.ConstInt(i, DataType.INT64, ir.Span.unknown()), |
| 305 | span, | 305 | span, |
| 306 | ) | 306 | ) |
| 307 | var = self.builder.let(elt.id, item_expr, span=span) | 307 | var = self.builder.let(elt.id, item_expr, span=span) |
| @@ -374,7 +374,7 @@ class AssignmentParserMixin: | |||
| 374 | span=span, | 374 | span=span, |
| 375 | ) | 375 | ) |
| 376 | for j in range(val_len): | 376 | for j in range(val_len): |
| 377 | - idx_const = ir.ConstInt(j, DataType.INDEX, span) | 377 | + idx_const = ir.ConstInt(j, DataType.INT64, span) |
| 378 | call = ir.create_op_call( | 378 | call = ir.create_op_call( |
| 379 | "struct.set", [base, idx_const, value_expr.elements[j]], | 379 | "struct.set", [base, idx_const, value_expr.elements[j]], |
| 380 | {"field": field_name}, span, | 380 | {"field": field_name}, span, |
| @@ -250,7 +250,7 @@ class BufferParserMixin: | |||
| 250 | mut_tuples.append( | 250 | mut_tuples.append( |
| 251 | self.builder.let( | 251 | self.builder.let( |
| 252 | f"_tg_{var_name}_mutex_ids{suffix}", | 252 | f"_tg_{var_name}_mutex_ids{suffix}", |
| 253 | - ir.MakeTuple([ir.ConstInt(m, DataType.INDEX, span) for m in values], span), | 253 | + ir.MakeTuple([ir.ConstInt(m, DataType.INT64, span) for m in values], span), |
| 254 | span=span, | 254 | span=span, |
| 255 | ) | 255 | ) |
| 256 | ) | 256 | ) |
| @@ -266,7 +266,7 @@ class BufferParserMixin: | |||
| 266 | return result | 266 | return result |
| 267 | cursor_call = ir.create_op_call( | 267 | cursor_call = ir.create_op_call( |
| 268 | "struct.create", | 268 | "struct.create", |
| 269 | - [ir.ConstInt(depth - 1, DataType.INDEX, span)], | 269 | + [ir.ConstInt(depth - 1, DataType.INT64, span)], |
| 270 | {"name": "_TileGroupCursor", "fields": ["cursor"]}, | 270 | {"name": "_TileGroupCursor", "fields": ["cursor"]}, |
| 271 | span, | 271 | span, |
| 272 | ) | 272 | ) |
| @@ -308,7 +308,7 @@ class BufferParserMixin: | |||
| 308 | n_slots, per_tile_mutex_ids, _memory = meta | 308 | n_slots, per_tile_mutex_ids, _memory = meta |
| 309 | tiles = self.lower_attr_access(group, "tiles", span) | 309 | tiles = self.lower_attr_access(group, "tiles", span) |
| 310 | 310 | ||
| 311 | - slot0 = ir.GetItemExpr(tiles, ir.ConstInt(0, DataType.INDEX, span), span) | 311 | + slot0 = ir.GetItemExpr(tiles, ir.ConstInt(0, DataType.INT64, span), span) |
| 312 | t = getattr(slot0, "type", None) | 312 | t = getattr(slot0, "type", None) |
| 313 | memref = getattr(t, "memref", None) | 313 | memref = getattr(t, "memref", None) |
| 314 | try: | 314 | try: |
| @@ -327,7 +327,7 @@ class BufferParserMixin: | |||
| 327 | var_name = self.current_target_name | 327 | var_name = self.current_target_name |
| 328 | tile_vars = [] | 328 | tile_vars = [] |
| 329 | for i in range(n_slots): | 329 | for i in range(n_slots): |
| 330 | - slot = ir.GetItemExpr(tiles, ir.ConstInt(i, DataType.INDEX, span), span) | 330 | + slot = ir.GetItemExpr(tiles, ir.ConstInt(i, DataType.INT64, span), span) |
| 331 | slot_tile = _ir_reinterpret(slot, shape=new_shape if kwargs.get("shape") is not None else None, | 331 | slot_tile = _ir_reinterpret(slot, shape=new_shape if kwargs.get("shape") is not None else None, |
| 332 | dtype=kwargs.get("dtype"), layout=kwargs.get("layout"), span=span) | 332 | dtype=kwargs.get("dtype"), layout=kwargs.get("layout"), span=span) |
| 333 | tile_vars.append(self.builder.let(f"_tg_{var_name}_tiles_{i}", slot_tile, span=span)) | 333 | tile_vars.append(self.builder.let(f"_tg_{var_name}_tiles_{i}", slot_tile, span=span)) |
| @@ -395,10 +395,10 @@ class BufferParserMixin: | |||
| 395 | When mutex metadata exists, attach the slot's static id; it needs no | 395 | When mutex metadata exists, attach the slot's static id; it needs no |
| 396 | ``% n`` and no dynamic lock at lock time. | 396 | ``% n`` and no dynamic lock at lock time. |
| 397 | """ | 397 | """ |
| 398 | - tile_ir = ir.GetItemExpr(tiles, ir.ConstInt(slot, DataType.INDEX, span), span) | 398 | + tile_ir = ir.GetItemExpr(tiles, ir.ConstInt(slot, DataType.INT64, span), span) |
| 399 | if per_tile_mutex_ids is not None: | 399 | if per_tile_mutex_ids is not None: |
| 400 | mutex_id_irs = tuple( | 400 | mutex_id_irs = tuple( |
| 401 | - ir.ConstInt(value, DataType.INDEX, span) for value in per_tile_mutex_ids[slot] | 401 | + ir.ConstInt(value, DataType.INT64, span) for value in per_tile_mutex_ids[slot] |
| 402 | ) | 402 | ) |
| 403 | self._tile_mutex_meta[tile_ir] = (mutex_id_irs, candidate_ids) | 403 | self._tile_mutex_meta[tile_ir] = (mutex_id_irs, candidate_ids) |
| 404 | return tile_ir | 404 | return tile_ir |
| @@ -449,14 +449,14 @@ class BufferParserMixin: | |||
| 449 | cursor_struct = self.lower_attr_access(group_var, "cursor", span) | 449 | cursor_struct = self.lower_attr_access(group_var, "cursor", span) |
| 450 | cur_read = self.lower_attr_access(cursor_struct, "cursor", span) | 450 | cur_read = self.lower_attr_access(cursor_struct, "cursor", span) |
| 451 | if method_name == "next": | 451 | if method_name == "next": |
| 452 | - new_val = cur_read + ir.ConstInt(1, DataType.INDEX, span) | 452 | + new_val = cur_read + ir.ConstInt(1, DataType.INT64, span) |
| 453 | self._emit_cursor_advance(cursor_struct, new_val, span) | 453 | self._emit_cursor_advance(cursor_struct, new_val, span) |
| 454 | raw = self.lower_attr_access(cursor_struct, "cursor", span) | 454 | raw = self.lower_attr_access(cursor_struct, "cursor", span) |
| 455 | elif method_name == "current": | 455 | elif method_name == "current": |
| 456 | raw = cur_read | 456 | raw = cur_read |
| 457 | else: # previous | 457 | else: # previous |
| 458 | - raw = cur_read + ir.ConstInt(n_slots - 1, DataType.INDEX, span) | 458 | + raw = cur_read + ir.ConstInt(n_slots - 1, DataType.INT64, span) |
| 459 | - wrapped = raw % ir.ConstInt(n_slots, DataType.INDEX, span) | 459 | + wrapped = raw % ir.ConstInt(n_slots, DataType.INT64, span) |
| 460 | return self._select_dynamic_slot( | 460 | return self._select_dynamic_slot( |
| 461 | group_var, | 461 | group_var, |
| 462 | tiles, | 462 | tiles, |
| @@ -1516,7 +1516,7 @@ class CallParserMixin: | |||
| 1516 | ) | 1516 | ) |
| 1517 | if self._auto_mutex: | 1517 | if self._auto_mutex: |
| 1518 | self._tile_mutex_meta[undefined_return] = ( | 1518 | self._tile_mutex_meta[undefined_return] = ( |
| 1519 | - (ir.ConstInt(-1, ir.DataType.INDEX, span),), | 1519 | + (ir.ConstInt(-1, ir.DataType.INT64, span),), |
| 1520 | [], | 1520 | [], |
| 1521 | ) | 1521 | ) |
| 1522 | 1522 | ||
| @@ -244,7 +244,7 @@ class ControlFlowParserMixin: | |||
| 244 | return tuple( | 244 | return tuple( |
| 245 | self.builder.var( | 245 | self.builder.var( |
| 246 | f"{name}__mutexid" if index == 0 else f"{name}__mutexid_{index}", | 246 | f"{name}__mutexid" if index == 0 else f"{name}__mutexid_{index}", |
| 247 | - ir.ScalarType(DataType.INDEX), | 247 | + ir.ScalarType(DataType.INT64), |
| 248 | span, | 248 | span, |
| 249 | ) | 249 | ) |
| 250 | for index in range(count) | 250 | for index in range(count) |
| @@ -433,7 +433,7 @@ class ControlFlowParserMixin: | |||
| 433 | 433 | ||
| 434 | @staticmethod | 434 | @staticmethod |
| 435 | def _as_index_expr(value: int | ir.Expr, span: ir.Span) -> ir.Expr: | 435 | def _as_index_expr(value: int | ir.Expr, span: ir.Span) -> ir.Expr: |
| 436 | - return value if isinstance(value, ir.Expr) else ir.ConstInt(value, DataType.INDEX, span) | 436 | + return value if isinstance(value, ir.Expr) else ir.ConstInt(value, DataType.INT64, span) |
| 437 | 437 | ||
| 438 | def _select_loop_merge_inputs( | 438 | def _select_loop_merge_inputs( |
| 439 | self, writes: set[str], span: ir.Span | 439 | self, writes: set[str], span: ir.Span |
| @@ -640,7 +640,7 @@ class ControlFlowParserMixin: | |||
| 640 | slot.state.result_phi.propagate(slot.init_value) | 640 | slot.state.result_phi.propagate(slot.init_value) |
| 641 | info = ControlFlowInfo(merge_names) | 641 | info = ControlFlowInfo(merge_names) |
| 642 | self._prepare_loop_mutex_iter_vars(slots, span) | 642 | self._prepare_loop_mutex_iter_vars(slots, span) |
| 643 | - loop_var = self.builder.var(loop_var_name, ir.ScalarType(DataType.INDEX), span) | 643 | + loop_var = self.builder.var(loop_var_name, ir.ScalarType(DataType.INT64), span) |
| 644 | with self.scope_manager.change_loop_info(info): | 644 | with self.scope_manager.change_loop_info(info): |
| 645 | body = self._parse_loop_region( | 645 | body = self._parse_loop_region( |
| 646 | stmt.body, "for", span, slots, (loop_var_name, loop_var) | 646 | stmt.body, "for", span, slots, (loop_var_name, loop_var) |
| @@ -246,7 +246,7 @@ class ExprEvaluator: | |||
| 246 | if isinstance(value, bool): | 246 | if isinstance(value, bool): |
| 247 | return ir.ConstBool(value, span) | 247 | return ir.ConstBool(value, span) |
| 248 | if isinstance(value, int): | 248 | if isinstance(value, int): |
| 249 | - return make_const_int(value, DataType.INDEX, span=span) | 249 | + return make_const_int(value, span=span) |
| 250 | if isinstance(value, float): | 250 | if isinstance(value, float): |
| 251 | return ir.ConstFloat(value, DataType.DEFAULT_CONST_FLOAT, span) | 251 | return ir.ConstFloat(value, DataType.DEFAULT_CONST_FLOAT, span) |
| 252 | if isinstance(value, ir.Expr): | 252 | if isinstance(value, ir.Expr): |
| @@ -304,7 +304,7 @@ class ExpressionParserMixin: | |||
| 304 | """ | 304 | """ |
| 305 | none_expr = self.builder.builder.none() | 305 | none_expr = self.builder.builder.none() |
| 306 | if self._auto_mutex and none_expr not in self._tile_mutex_meta: | 306 | if self._auto_mutex and none_expr not in self._tile_mutex_meta: |
| 307 | - self._tile_mutex_meta[none_expr] = ((ir.ConstInt(-1, DataType.INDEX, span),), []) | 307 | + self._tile_mutex_meta[none_expr] = ((ir.ConstInt(-1, DataType.INT64, span),), []) |
| 308 | return none_expr | 308 | return none_expr |
| 309 | 309 | ||
| 310 | def tile_mutex_lock_meta(self, expr): | 310 | def tile_mutex_lock_meta(self, expr): |
| @@ -331,7 +331,7 @@ class ExpressionParserMixin: | |||
| 331 | if isinstance(value, bool): | 331 | if isinstance(value, bool): |
| 332 | return ir.ConstBool(value, span) | 332 | return ir.ConstBool(value, span) |
| 333 | elif isinstance(value, int): | 333 | elif isinstance(value, int): |
| 334 | - return make_const_int(value, DataType.INDEX, span=span) | 334 | + return make_const_int(value, span=span) |
| 335 | elif isinstance(value, float): | 335 | elif isinstance(value, float): |
| 336 | return ir.ConstFloat(value, DataType.DEFAULT_CONST_FLOAT, span) | 336 | return ir.ConstFloat(value, DataType.DEFAULT_CONST_FLOAT, span) |
| 337 | elif isinstance(value, str): | 337 | elif isinstance(value, str): |
| @@ -720,7 +720,7 @@ class ExpressionParserMixin: | |||
| 720 | idx = fields.index(field_name) | 720 | idx = fields.index(field_name) |
| 721 | if isinstance(base, ir.MakeTuple) and not self._is_struct_array_tuple(base): | 721 | if isinstance(base, ir.MakeTuple) and not self._is_struct_array_tuple(base): |
| 722 | return base.elements[idx] | 722 | return base.elements[idx] |
| 723 | - return ir.GetItemExpr(base, ir.ConstInt(idx, DataType.INDEX, span), span) | 723 | + return ir.GetItemExpr(base, ir.ConstInt(idx, DataType.INT64, span), span) |
| 724 | 724 | ||
| 725 | def parse_attribute(self, attr: ast.Attribute) -> ir.Expr: | 725 | def parse_attribute(self, attr: ast.Attribute) -> ir.Expr: |
| 726 | """Parse attribute access. | 726 | """Parse attribute access. |
| @@ -990,7 +990,7 @@ class ExpressionParserMixin: | |||
| 990 | if not step_is_one: | 990 | if not step_is_one: |
| 991 | diff = _make_binary("sub", left, start, span) | 991 | diff = _make_binary("sub", left, start, span) |
| 992 | mod_val = _make_binary("mod", diff, step, span) | 992 | mod_val = _make_binary("mod", diff, step, span) |
| 993 | - zero = ir.ConstInt(0, DataType.INDEX, span) | 993 | + zero = ir.ConstInt(0, DataType.INT64, span) |
| 994 | result = ir.And(result, _make_binary("eq", mod_val, zero, span), DataType.BOOL, span) | 994 | result = ir.And(result, _make_binary("eq", mod_val, zero, span), DataType.BOOL, span) |
| 995 | return ir.not_(result, span) if is_not_in else result | 995 | return ir.not_(result, span) if is_not_in else result |
| 996 | 996 | ||
| @@ -1183,7 +1183,7 @@ class ExpressionParserMixin: | |||
| 1183 | next_shape_val = _const_int_value(shape[dim]) | 1183 | next_shape_val = _const_int_value(shape[dim]) |
| 1184 | cur_stride_val = _const_int_value(stride) | 1184 | cur_stride_val = _const_int_value(stride) |
| 1185 | if next_shape_val is not None and cur_stride_val is not None: | 1185 | if next_shape_val is not None and cur_stride_val is not None: |
| 1186 | - stride = ir.ConstInt(next_shape_val * cur_stride_val, DataType.INDEX, span) | 1186 | + stride = ir.ConstInt(next_shape_val * cur_stride_val, DataType.INT64, span) |
| 1187 | else: | 1187 | else: |
| 1188 | stride = shape[dim] * stride | 1188 | stride = shape[dim] * stride |
| 1189 | return offset | 1189 | return offset |
| @@ -1296,7 +1296,7 @@ class ExpressionParserMixin: | |||
| 1296 | span=span, | 1296 | span=span, |
| 1297 | hint="Omit the step or use a contiguous slice with step 1", | 1297 | hint="Omit the step or use a contiguous slice with step 1", |
| 1298 | ) | 1298 | ) |
| 1299 | - start = ir.ConstInt(0, DataType.INDEX, span) if s.lower is None else self.parse_expression(s.lower) | 1299 | + start = ir.ConstInt(0, DataType.INT64, span) if s.lower is None else self.parse_expression(s.lower) |
| 1300 | dim_starts.append(start) | 1300 | dim_starts.append(start) |
| 1301 | start_val = self._validate_subscript_value(start, "Tile slice start", i, span) | 1301 | start_val = self._validate_subscript_value(start, "Tile slice start", i, span) |
| 1302 | 1302 | ||
| @@ -1312,7 +1312,7 @@ class ExpressionParserMixin: | |||
| 1312 | shape_val if effective_upper_val is None else min(effective_upper_val, shape_val) | 1312 | shape_val if effective_upper_val is None else min(effective_upper_val, shape_val) |
| 1313 | ) | 1313 | ) |
| 1314 | if shape_val is not None and upper_val is not None and upper_val > shape_val: | 1314 | if shape_val is not None and upper_val is not None and upper_val > shape_val: |
| 1315 | - upper = ir.ConstInt(shape_val, DataType.INDEX, span) | 1315 | + upper = ir.ConstInt(shape_val, DataType.INT64, span) |
| 1316 | upper_val = shape_val | 1316 | upper_val = shape_val |
| 1317 | if ( | 1317 | if ( |
| 1318 | start_val is not None | 1318 | start_val is not None |
| @@ -1345,14 +1345,14 @@ class ExpressionParserMixin: | |||
| 1345 | ) | 1345 | ) |
| 1346 | if size_val is not None: | 1346 | if size_val is not None: |
| 1347 | if size_val > remaining: | 1347 | if size_val > remaining: |
| 1348 | - size = ir.ConstInt(remaining, DataType.INDEX, span) | 1348 | + size = ir.ConstInt(remaining, DataType.INT64, span) |
| 1349 | size_val = remaining | 1349 | size_val = remaining |
| 1350 | else: | 1350 | else: |
| 1351 | - size = ir.Min(size, ir.ConstInt(remaining, DataType.INDEX, span), DataType.INDEX, span) | 1351 | + size = _make_binary("min_", size, ir.ConstInt(remaining, DataType.INT64, span), span) |
| 1352 | elif vs_val is None and start_val is not None: | 1352 | elif vs_val is None and start_val is not None: |
| 1353 | # Dynamic valid_shape: emit runtime clamp min(size, vs - start) | 1353 | # Dynamic valid_shape: emit runtime clamp min(size, vs - start) |
| 1354 | remaining_expr = vs - start | 1354 | remaining_expr = vs - start |
| 1355 | - size = ir.Min(size, remaining_expr, DataType.INDEX, span) | 1355 | + size = _make_binary("min_", size, remaining_expr, span) |
| 1356 | 1356 | ||
| 1357 | new_shape_exprs.append(size) | 1357 | new_shape_exprs.append(size) |
| 1358 | 1358 | ||
| @@ -158,7 +158,7 @@ class TypeResolver: | |||
| 158 | return shape | 158 | return shape |
| 159 | 159 | ||
| 160 | # Convert all to Expr | 160 | # Convert all to Expr |
| 161 | - return [ir.ConstInt(d, DataType.INDEX, ir.Span.unknown()) if isinstance(d, int) else d for d in shape] | 161 | + return [ir.ConstInt(d, DataType.INT64, ir.Span.unknown()) if isinstance(d, int) else d for d in shape] |
| 162 | 162 | ||
| 163 | @classmethod | 163 | @classmethod |
| 164 | def dtype_from_value(cls, value: int) -> DataType | None: | 164 | def dtype_from_value(cls, value: int) -> DataType | None: |
| @@ -168,13 +168,12 @@ def make_const_int( | |||
| 168 | ) -> ir.Expr: | 168 | ) -> ir.Expr: |
| 169 | """Materialise an integer literal as ``ir.ConstInt``, range-checked and folded. | 169 | """Materialise an integer literal as ``ir.ConstInt``, range-checked and folded. |
| 170 | 170 | ||
| 171 | - ``INDEX`` (and no dtype at all) means "width not committed yet", so a value above ``INT64_MAX`` | 171 | + With no dtype, values use ``INT64`` unless they require ``UINT64``. A dtype the caller named explicitly |
| 172 | - settles on ``UINT64`` instead of being rejected. A dtype the caller named explicitly is taken at its | 172 | + is taken at its word: the value has to fit it. |
| 173 | - word: the value has to fit it. | ||
| 174 | """ | 173 | """ |
| 175 | - if dtype is None or dtype == ir.DataType.INDEX: | 174 | + if dtype is None: |
| 176 | storage = check_ir_int(value, subject=subject, span=span) | 175 | storage = check_ir_int(value, subject=subject, span=span) |
| 177 | - settled = ir.DataType.UINT64 if value > INT64_MAX else (dtype or ir.DataType.INDEX) | 176 | + settled = ir.DataType.UINT64 if value > INT64_MAX else ir.DataType.INT64 |
| 178 | return ir.ConstInt(storage, settled, span) | 177 | return ir.ConstInt(storage, settled, span) |
| 179 | check_fits_dtype(value, dtype, subject=subject, span=span, api=api) | 178 | check_fits_dtype(value, dtype, subject=subject, span=span, api=api) |
| 180 | return ir.ConstInt(to_storage_int(value), dtype, span) | 179 | return ir.ConstInt(to_storage_int(value), dtype, span) |
| @@ -40,7 +40,7 @@ from pypto_pro.language.parser.diagnostics import check_in_range | |||
| 40 | _MAX_ARRAY_SIZE = 2048 | 40 | _MAX_ARRAY_SIZE = 2048 |
| 41 | 41 | ||
| 42 | _PYTHON_TYPE_TO_DTYPE: dict[type, DataType] = { | 42 | _PYTHON_TYPE_TO_DTYPE: dict[type, DataType] = { |
| 43 | - int: DataType.INDEX, | 43 | + int: DataType.INT64, |
| 44 | float: DataType.FP32, | 44 | float: DataType.FP32, |
| 45 | bool: DataType.BOOL, | 45 | bool: DataType.BOOL, |
| 46 | } | 46 | } |
| @@ -199,7 +199,7 @@ def get_tiling_tuple_type(cls: type) -> ir.TupleType: | |||
| 199 | def _field_ctype(dtype: DataType) -> type: | 199 | def _field_ctype(dtype: DataType) -> type: |
| 200 | # Reuse the single DataType→ctype map maintained in the runtime (lazy import to avoid a | 200 | # Reuse the single DataType→ctype map maintained in the runtime (lazy import to avoid a |
| 201 | # module-level cycle; jit imports this module inside functions). Must stay in sync with | 201 | # module-level cycle; jit imports this module inside functions). Must stay in sync with |
| 202 | - # the C struct member types emitted by CCE codegen's CppTypeForField (e.g. INDEX → int64_t). | 202 | + # the C struct member types emitted by CCE codegen's CppTypeForField (e.g. INT64 → int64_t). |
| 203 | from pypto_pro.runtime.jit import _PL_DTYPE_TO_CTYPE | 203 | from pypto_pro.runtime.jit import _PL_DTYPE_TO_CTYPE |
| 204 | 204 | ||
| 205 | ctype = _PL_DTYPE_TO_CTYPE.get(str(dtype)) | 205 | ctype = _PL_DTYPE_TO_CTYPE.get(str(dtype)) |
| @@ -612,7 +612,7 @@ def _collect_outer_slots(info: PipelineInfo) -> dict: | |||
| 612 | """{name: (group, kind, slot count)} for slots picked outside the pipeline loop. | 612 | """{name: (group, kind, slot count)} for slots picked outside the pipeline loop. |
| 613 | 613 | ||
| 614 | Such a slot advances once per outer iteration while every beat reads it, so a delayed stage | 614 | Such a slot advances once per outer iteration while every beat reads it, so a delayed stage |
| 615 | - would see whatever the variable was last rebound to. Carrying the INDEX in ctx fixes that: | 615 | + would see whatever the variable was last rebound to. Carrying the slot index in ctx fixes that: |
| 616 | each beat snapshots the index it used, and every stage re-selects the slot with its own. | 616 | each beat snapshots the index it used, and every stage re-selects the slot with its own. |
| 617 | 617 | ||
| 618 | Renames are followed to a fixed point and every name on the chain keeps its entry, because | 618 | Renames are followed to a fixed point and every name on the chain keeps its entry, because |
| @@ -837,7 +837,7 @@ def _derive_ctx_fields(info: PipelineInfo): | |||
| 837 | arg_map.append(PL_STRUCT_ARG) | 837 | arg_map.append(PL_STRUCT_ARG) |
| 838 | continue | 838 | continue |
| 839 | if arg.id in info.outer_slots: | 839 | if arg.id in info.outer_slots: |
| 840 | - # Slot chosen outside the loop: ctx carries the INDEX, and the stage | 840 | + # Slot chosen outside the loop: ctx carries the slot index, and the stage |
| 841 | # re-selects the slot with its own beat's index (see _build_stage_args). | 841 | # re-selects the slot with its own beat's index (see _build_stage_args). |
| 842 | arg_map.append(register_slot_index(arg.id)) | 842 | arg_map.append(register_slot_index(arg.id)) |
| 843 | continue | 843 | continue |
| @@ -138,11 +138,11 @@ class BoundTensorShape: | |||
| 138 | result = [] | 138 | result = [] |
| 139 | for dim in self.dimensions: | 139 | for dim in self.dimensions: |
| 140 | if dim.dynamic_name is not None: | 140 | if dim.dynamic_name is not None: |
| 141 | - result.append(ir.Var(dim.dynamic_name, ir.ScalarType(DataType.INDEX), span)) | 141 | + result.append(ir.Var(dim.dynamic_name, ir.ScalarType(DataType.INT64), span)) |
| 142 | else: | 142 | else: |
| 143 | if dim.value is None: # Guard the BoundDimension invariant for type checkers. | 143 | if dim.value is None: # Guard the BoundDimension invariant for type checkers. |
| 144 | raise ValueError("A constant bound dimension must contain a value") | 144 | raise ValueError("A constant bound dimension must contain a value") |
| 145 | - result.append(ir.ConstInt(dim.value, DataType.INDEX, span)) | 145 | + result.append(ir.ConstInt(dim.value, DataType.INT64, span)) |
| 146 | return result | 146 | return result |
| 147 | 147 | ||
| 148 | 148 | ||
| @@ -253,8 +253,8 @@ def seg_window(rule, gs, ge, r0, c0): | |||
| 253 | 253 | ||
| 254 | def calc_loop(start, end, work_id, b_idx, s1_o_acc, s1_size_acc, s2_size_acc, actual_seq_q, actual_seq_kv, n_dim): | 254 | def calc_loop(start, end, work_id, b_idx, s1_o_acc, s1_size_acc, s2_size_acc, actual_seq_q, actual_seq_kv, n_dim): |
| 255 | for _ in pl.range(start, end): | 255 | for _ in pl.range(start, end): |
| 256 | - actual_s1 = pl.astype(0, pl.DT_INT32) | 256 | + actual_s1 = 0 |
| 257 | - actual_s2 = pl.astype(0, pl.DT_INT32) | 257 | + actual_s2 = 0 |
| 258 | if b_idx == 0: | 258 | if b_idx == 0: |
| 259 | actual_s1 = pl.getval(actual_seq_q, b_idx) | 259 | actual_s1 = pl.getval(actual_seq_q, b_idx) |
| 260 | actual_s2 = pl.getval(actual_seq_kv, b_idx) | 260 | actual_s2 = pl.getval(actual_seq_kv, b_idx) |
| @@ -1068,8 +1068,8 @@ def fa_tnd_with_mask_kernel( | |||
| 1068 | b_idx = 0 | 1068 | b_idx = 0 |
| 1069 | s1_size_acc = 0 | 1069 | s1_size_acc = 0 |
| 1070 | s2_size_acc = 0 | 1070 | s2_size_acc = 0 |
| 1071 | - actual_s1 = pl.astype(0, pl.DT_INT32) | 1071 | + actual_s1 = 0 |
| 1072 | - actual_s2 = pl.astype(0, pl.DT_INT32) | 1072 | + actual_s2 = 0 |
| 1073 | s1_o_acc = 0 | 1073 | s1_o_acc = 0 |
| 1074 | ctx_arr = pl.struct_array( | 1074 | ctx_arr = pl.struct_array( |
| 1075 | 4, "CubeCtx", n_idx=0, qi=0, ki=0, task_id=0, s1SizeAcc=0, s2SizeAcc=0, s1_size=0, s2_size=0 | 1075 | 4, "CubeCtx", n_idx=0, qi=0, ki=0, task_id=0, s1SizeAcc=0, s2SizeAcc=0, s1_size=0, s2_size=0 |
| @@ -1238,8 +1238,8 @@ def fa_tnd_with_mask_kernel( | |||
| 1238 | b_idx = 0 | 1238 | b_idx = 0 |
| 1239 | s1_size_acc = 0 | 1239 | s1_size_acc = 0 |
| 1240 | s2_size_acc = 0 | 1240 | s2_size_acc = 0 |
| 1241 | - actual_s1 = pl.astype(0, pl.DT_INT32) | 1241 | + actual_s1 = 0 |
| 1242 | - actual_s2 = pl.astype(0, pl.DT_INT32) | 1242 | + actual_s2 = 0 |
| 1243 | s1_o_acc = 0 | 1243 | s1_o_acc = 0 |
| 1244 | segment_idx = 0 | 1244 | segment_idx = 0 |
| 1245 | 1245 | ||
| @@ -1305,7 +1305,7 @@ def fa_tnd_with_mask_kernel( | |||
| 1305 | segment_idx, segment_acc, cross_segment = calc_segment_idx(b_idx, s1_idx, segment_starts, actual_s1) | 1305 | segment_idx, segment_acc, cross_segment = calc_segment_idx(b_idx, s1_idx, segment_starts, actual_s1) |
| 1306 | s1_size = pl.min(TS, actual_s1 - s1_idx * TS) | 1306 | s1_size = pl.min(TS, actual_s1 - s1_idx * TS) |
| 1307 | 1307 | ||
| 1308 | - sq_acc = pl.astype(0, pl.DT_INT32) | 1308 | + sq_acc = 0 |
| 1309 | if b_idx > 0: | 1309 | if b_idx > 0: |
| 1310 | sq_acc = pl.getval(actual_seq_q, b_idx - 1) | 1310 | sq_acc = pl.getval(actual_seq_q, b_idx - 1) |
| 1311 | q_off = sq_acc + s1_idx * TS | 1311 | q_off = sq_acc + s1_idx * TS |
| @@ -915,8 +915,8 @@ def flex_attention( | |||
| 915 | b_idx = 0 | 915 | b_idx = 0 |
| 916 | s1_size_acc = 0 | 916 | s1_size_acc = 0 |
| 917 | s2_size_acc = 0 | 917 | s2_size_acc = 0 |
| 918 | - actual_s1 = pl.astype(0, pl.DT_INT32) | 918 | + actual_s1 = 0 |
| 919 | - actual_s2 = pl.astype(0, pl.DT_INT32) | 919 | + actual_s2 = 0 |
| 920 | s1o_acc = 0 | 920 | s1o_acc = 0 |
| 921 | ctx_arr = pl.struct_array( | 921 | ctx_arr = pl.struct_array( |
| 922 | 4, | 922 | 4, |
| @@ -1116,8 +1116,8 @@ def flex_attention( | |||
| 1116 | b_idx = 0 | 1116 | b_idx = 0 |
| 1117 | s1_size_acc = 0 | 1117 | s1_size_acc = 0 |
| 1118 | s2_size_acc = 0 | 1118 | s2_size_acc = 0 |
| 1119 | - actual_s1 = pl.astype(0, pl.DT_INT32) | 1119 | + actual_s1 = 0 |
| 1120 | - actual_s2 = pl.astype(0, pl.DT_INT32) | 1120 | + actual_s2 = 0 |
| 1121 | s1o_acc = 0 | 1121 | s1o_acc = 0 |
| 1122 | 1122 | ||
| 1123 | # StructArray(3) for pipeline context tracking (same as original) | 1123 | # StructArray(3) for pipeline context tracking (same as original) |
| @@ -1182,7 +1182,7 @@ def flex_attention( | |||
| 1182 | s1_idx = s1o_size % cur_b_s1o | 1182 | s1_idx = s1o_size % cur_b_s1o |
| 1183 | s1_size = pl.min(TS, actual_s1 - s1_idx * TS) | 1183 | s1_size = pl.min(TS, actual_s1 - s1_idx * TS) |
| 1184 | 1184 | ||
| 1185 | - sq_acc = pl.astype(0, pl.DT_INT32) | 1185 | + sq_acc = 0 |
| 1186 | if b_idx > 0: | 1186 | if b_idx > 0: |
| 1187 | sq_acc = pl.getval(actual_seq_q, b_idx - 1) | 1187 | sq_acc = pl.getval(actual_seq_q, b_idx - 1) |
| 1188 | q_off = sq_acc + s1_idx * TS | 1188 | q_off = sq_acc + s1_idx * TS |
| @@ -939,8 +939,8 @@ def flex_attention_bf16( | |||
| 939 | two_c = pl.getval(work_ranges, core_id * 4 + 3) | 939 | two_c = pl.getval(work_ranges, core_id * 4 + 3) |
| 940 | task_id = 0 | 940 | task_id = 0 |
| 941 | b_idx = 0 | 941 | b_idx = 0 |
| 942 | - actual_s1 = pl.astype(0, pl.DT_INT32) | 942 | + actual_s1 = 0 |
| 943 | - actual_s2 = pl.astype(0, pl.DT_INT32) | 943 | + actual_s2 = 0 |
| 944 | s1o_acc = 0 | 944 | s1o_acc = 0 |
| 945 | ctx_arr = pl.struct_array(4, "CubeCtx", n_idx=0, kv_n_idx=0, qi=0, ki=0, | 945 | ctx_arr = pl.struct_array(4, "CubeCtx", n_idx=0, kv_n_idx=0, qi=0, ki=0, |
| 946 | task_id=0, kv_page=0, kv_slot=0, s1_size=0, s2_size=0, loop_count=0) | 946 | task_id=0, kv_page=0, kv_slot=0, s1_size=0, s2_size=0, loop_count=0) |
| @@ -1092,8 +1092,8 @@ def flex_attention_bf16( | |||
| 1092 | task_id = 0 | 1092 | task_id = 0 |
| 1093 | q_count = 0 | 1093 | q_count = 0 |
| 1094 | b_idx = 0 | 1094 | b_idx = 0 |
| 1095 | - actual_s1 = pl.astype(0, pl.DT_INT32) | 1095 | + actual_s1 = 0 |
| 1096 | - actual_s2 = pl.astype(0, pl.DT_INT32) | 1096 | + actual_s2 = 0 |
| 1097 | s1o_acc = 0 | 1097 | s1o_acc = 0 |
| 1098 | 1098 | ||
| 1099 | # StructArray(3) for pipeline context tracking (same as original) | 1099 | # StructArray(3) for pipeline context tracking (same as original) |
| @@ -33,16 +33,20 @@ def bitcast_all_scalar_pairs( | |||
| 33 | out_uint32: pl.Tensor[[1, ELEMENTS], pl.DT_UINT32], | 33 | out_uint32: pl.Tensor[[1, ELEMENTS], pl.DT_UINT32], |
| 34 | ): | 34 | ): |
| 35 | tid = pl.simt.linear_thread_idx() | 35 | tid = pl.simt.linear_thread_idx() |
| 36 | - out_fp16[0, tid] = pl.simt.bitcast(src_int16[0, tid], pl.DT_FP16) | 36 | + value_int16 = pl.simt.cast(src_int16[0, tid], pl.DT_INT16) |
| 37 | - out_fp16[1, tid] = pl.simt.bitcast(src_uint16[0, tid], pl.DT_FP16) | 37 | + value_uint16 = pl.simt.cast(src_uint16[0, tid], pl.DT_UINT16) |
| 38 | - out_bf16[0, tid] = pl.simt.bitcast(src_int16[0, tid], pl.DT_BF16) | 38 | + value_int32 = pl.simt.cast(src_int32[0, tid], pl.DT_INT32) |
| 39 | - out_bf16[1, tid] = pl.simt.bitcast(src_uint16[0, tid], pl.DT_BF16) | 39 | + value_uint32 = pl.simt.cast(src_uint32[0, tid], pl.DT_UINT32) |
| 40 | + out_fp16[0, tid] = pl.simt.bitcast(value_int16, pl.DT_FP16) | ||
| 41 | + out_fp16[1, tid] = pl.simt.bitcast(value_uint16, pl.DT_FP16) | ||
| 42 | + out_bf16[0, tid] = pl.simt.bitcast(value_int16, pl.DT_BF16) | ||
| 43 | + out_bf16[1, tid] = pl.simt.bitcast(value_uint16, pl.DT_BF16) | ||
| 40 | out_int16[0, tid] = pl.simt.bitcast(src_fp16[0, tid], pl.DT_INT16) | 44 | out_int16[0, tid] = pl.simt.bitcast(src_fp16[0, tid], pl.DT_INT16) |
| 41 | out_int16[1, tid] = pl.simt.bitcast(src_bf16[0, tid], pl.DT_INT16) | 45 | out_int16[1, tid] = pl.simt.bitcast(src_bf16[0, tid], pl.DT_INT16) |
| 42 | out_uint16[0, tid] = pl.simt.bitcast(src_fp16[0, tid], pl.DT_UINT16) | 46 | out_uint16[0, tid] = pl.simt.bitcast(src_fp16[0, tid], pl.DT_UINT16) |
| 43 | out_uint16[1, tid] = pl.simt.bitcast(src_bf16[0, tid], pl.DT_UINT16) | 47 | out_uint16[1, tid] = pl.simt.bitcast(src_bf16[0, tid], pl.DT_UINT16) |
| 44 | - out_fp32[0, tid] = pl.simt.bitcast(src_int32[0, tid], pl.DT_FP32) | 48 | + out_fp32[0, tid] = pl.simt.bitcast(value_int32, pl.DT_FP32) |
| 45 | - out_fp32[1, tid] = pl.simt.bitcast(src_uint32[0, tid], pl.DT_FP32) | 49 | + out_fp32[1, tid] = pl.simt.bitcast(value_uint32, pl.DT_FP32) |
| 46 | out_int32[0, tid] = pl.simt.bitcast(src_fp32[0, tid], pl.DT_INT32) | 50 | out_int32[0, tid] = pl.simt.bitcast(src_fp32[0, tid], pl.DT_INT32) |
| 47 | out_uint32[0, tid] = pl.simt.bitcast(src_fp32[0, tid], pl.DT_UINT32) | 51 | out_uint32[0, tid] = pl.simt.bitcast(src_fp32[0, tid], pl.DT_UINT32) |
| 48 | 52 | ||
| @@ -31,8 +31,12 @@ def multiply_high( | |||
| 31 | out_u64: pl.Tensor[[1, ELEMENTS], pl.DT_UINT64], | 31 | out_u64: pl.Tensor[[1, ELEMENTS], pl.DT_UINT64], |
| 32 | ): | 32 | ): |
| 33 | tid = pl.simt.linear_thread_idx() | 33 | tid = pl.simt.linear_thread_idx() |
| 34 | - out_i32[0, tid] = pl.simt.mul_hi(lhs_i32[0, tid], rhs_i32[0, tid]) | 34 | + lhs_i32_value = pl.simt.cast(lhs_i32[0, tid], pl.DT_INT32) |
| 35 | - out_u32[0, tid] = pl.simt.mul_hi(lhs_u32[0, tid], rhs_u32[0, tid]) | 35 | + rhs_i32_value = pl.simt.cast(rhs_i32[0, tid], pl.DT_INT32) |
| 36 | + lhs_u32_value = pl.simt.cast(lhs_u32[0, tid], pl.DT_UINT32) | ||
| 37 | + rhs_u32_value = pl.simt.cast(rhs_u32[0, tid], pl.DT_UINT32) | ||
| 38 | + out_i32[0, tid] = pl.simt.mul_hi(lhs_i32_value, rhs_i32_value) | ||
| 39 | + out_u32[0, tid] = pl.simt.mul_hi(lhs_u32_value, rhs_u32_value) | ||
| 36 | out_i64[0, tid] = pl.simt.mul_hi(lhs_i64[0, tid], rhs_i64[0, tid]) | 40 | out_i64[0, tid] = pl.simt.mul_hi(lhs_i64[0, tid], rhs_i64[0, tid]) |
| 37 | out_u64[0, tid] = pl.simt.mul_hi(lhs_u64[0, tid], rhs_u64[0, tid]) | 41 | out_u64[0, tid] = pl.simt.mul_hi(lhs_u64[0, tid], rhs_u64[0, tid]) |
| 38 | 42 | ||
| @@ -23,7 +23,8 @@ def count_bits( | |||
| 23 | count64: pl.Tensor[[1, ELEMENTS], pl.DT_INT32], | 23 | count64: pl.Tensor[[1, ELEMENTS], pl.DT_INT32], |
| 24 | ): | 24 | ): |
| 25 | tid = pl.simt.linear_thread_idx() | 25 | tid = pl.simt.linear_thread_idx() |
| 26 | - count32[0, tid] = pl.simt.popcount(src32[0, tid]) | 26 | + value32 = pl.simt.cast(src32[0, tid], pl.DT_UINT32) |
| 27 | + count32[0, tid] = pl.simt.popcount(value32) | ||
| 27 | count64[0, tid] = pl.simt.popcount(src64[0, tid]) | 28 | count64[0, tid] = pl.simt.popcount(src64[0, tid]) |
| 28 | 29 | ||
| 29 | 30 | ||
| @@ -448,8 +448,8 @@ def test_simt_callee_codegen_emits_native_nested_calls_and_tile_abi(): | |||
| 448 | apply_signature = next(line for line in cpp.splitlines() if "_callee_apply(" in line and "__simt_callee__" in line) | 448 | apply_signature = next(line for line in cpp.splitlines() if "_callee_apply(" in line and "__simt_callee__" in line) |
| 449 | entry_signature = next(line for line in cpp.splitlines() if "inline void _callee_entry(" in line) | 449 | entry_signature = next(line for line in cpp.splitlines() if "inline void _callee_entry(" in line) |
| 450 | 450 | ||
| 451 | - assert "__simt_callee__ inline int32_t" in add_signature | 451 | + assert "__simt_callee__ inline int64_t" in add_signature |
| 452 | - assert "__simt_callee__ inline int32_t" in load_signature | 452 | + assert "__simt_callee__ inline int64_t" in load_signature |
| 453 | assert "__simt_callee__ inline void" in store_signature | 453 | assert "__simt_callee__ inline void" in store_signature |
| 454 | for signature in (store_signature, apply_signature): | 454 | for signature in (store_signature, apply_signature): |
| 455 | assert re.search(r"__ubuf__\s+int32_t\s*\*\s*dst(?:_\d+)*\b", signature) | 455 | assert re.search(r"__ubuf__\s+int32_t\s*\*\s*dst(?:_\d+)*\b", signature) |
| @@ -468,7 +468,7 @@ def test_simt_callee_codegen_emits_native_nested_calls_and_tile_abi(): | |||
| 468 | assert max(add_pos, load_pos, store_pos) < apply_pos < entry_pos | 468 | assert max(add_pos, load_pos, store_pos) < apply_pos < entry_pos |
| 469 | add_function = cpp[add_pos:cpp.index("\n}\n", add_pos)] | 469 | add_function = cpp[add_pos:cpp.index("\n}\n", add_pos)] |
| 470 | apply_function = cpp[apply_pos:entry_pos] | 470 | apply_function = cpp[apply_pos:entry_pos] |
| 471 | - assert re.search(r"\bvalue(?:_\d+)*\s*\+\s*delta(?:_\d+)*\b", add_function) | 471 | + assert re.search(r"\bvalue(?:_\d+)*\s*\+\s*\(\(int64_t\)delta(?:_\d+)*\)", add_function) |
| 472 | assert re.search(r"\breturn\s+[^;]+;", add_function) | 472 | assert re.search(r"\breturn\s+[^;]+;", add_function) |
| 473 | assert re.search(r"_callee_load\(src(?:_\d+)?,\s*index(?:_\d+)?\)", apply_function) | 473 | assert re.search(r"_callee_load\(src(?:_\d+)?,\s*index(?:_\d+)?\)", apply_function) |
| 474 | assert re.search(r"_callee_add\([^;]+\)", apply_function) | 474 | assert re.search(r"_callee_add\([^;]+\)", apply_function) |
| @@ -159,7 +159,7 @@ def test_dynamic_shape_subscript_uses_parameter_shape_var(): | |||
| 159 | 159 | ||
| 160 | assert isinstance(dynamic_dim, ir.Var) | 160 | assert isinstance(dynamic_dim, ir.Var) |
| 161 | assert dynamic_dim.name == "__pypto_dyn_a_0" | 161 | assert dynamic_dim.name == "__pypto_dyn_a_0" |
| 162 | - assert dynamic_dim.type.dtype == DataType.INDEX | 162 | + assert dynamic_dim.type.dtype == DataType.INT64 |
| 163 | assert dynamic_dim.name in ir.python_print(add_kernel_shape_subscript) | 163 | assert dynamic_dim.name in ir.python_print(add_kernel_shape_subscript) |
| 164 | 164 | ||
| 165 | 165 | ||
| @@ -97,6 +97,13 @@ def test_tensor_shape_transform_helpers_create_calls(factory, expected_name): | |||
| 97 | assert isinstance(call.type, ir.TensorType) | 97 | assert isinstance(call.type, ir.TensorType) |
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | +def test_tensor_transpose_integer_axes_use_int64(): | ||
| 101 | + call = ir.op.tensor.transpose(_tensor_var("x", shape=[4, 8]), 0, 1) | ||
| 102 | + | ||
| 103 | + assert call.args[1].type.dtype == DataType.INT64 | ||
| 104 | + assert call.args[2].type.dtype == DataType.INT64 | ||
| 105 | + | ||
| 106 | + | ||
| 100 | def test_tensor_matmul_helper_accepts_kwargs(): | 107 | def test_tensor_matmul_helper_accepts_kwargs(): |
| 101 | lhs = _tensor_var("lhs", [4, 8], DataType.FP16) | 108 | lhs = _tensor_var("lhs", [4, 8], DataType.FP16) |
| 102 | rhs = _tensor_var("rhs", [8, 16], DataType.FP16) | 109 | rhs = _tensor_var("rhs", [8, 16], DataType.FP16) |
| @@ -371,7 +371,7 @@ def test_iter_arg_with_inferred_type(): | |||
| 371 | 371 | ||
| 372 | assert sum_iter.name == "sum" | 372 | assert sum_iter.name == "sum" |
| 373 | assert isinstance(sum_iter.iterVar.type, ir.ScalarType) | 373 | assert isinstance(sum_iter.iterVar.type, ir.ScalarType) |
| 374 | - assert sum_iter.iterVar.type.dtype == DataType.INDEX | 374 | + assert sum_iter.iterVar.type.dtype == DataType.INT64 |
| 375 | 375 | ||
| 376 | func = f.get_result() | 376 | func = f.get_result() |
| 377 | assert func is not None | 377 | assert func is not None |
| @@ -388,14 +388,14 @@ def test_iter_arg_with_type_validation(): | |||
| 388 | 388 | ||
| 389 | with ib.for_loop(i, 0, 10, 1) as loop: | 389 | with ib.for_loop(i, 0, 10, 1) as loop: |
| 390 | # Provide matching type for validation | 390 | # Provide matching type for validation |
| 391 | - explicit_type = ir.ScalarType(DataType.INDEX) | 391 | + explicit_type = ir.ScalarType(DataType.INT64) |
| 392 | sum_iter = loop.iter_arg("sum", 0, iter_type=explicit_type) | 392 | sum_iter = loop.iter_arg("sum", 0, iter_type=explicit_type) |
| 393 | # Must have matching return_var | 393 | # Must have matching return_var |
| 394 | _ = loop.return_var("sum_final") | 394 | _ = loop.return_var("sum_final") |
| 395 | 395 | ||
| 396 | assert sum_iter.name == "sum" | 396 | assert sum_iter.name == "sum" |
| 397 | assert isinstance(sum_iter.iterVar.type, ir.ScalarType) | 397 | assert isinstance(sum_iter.iterVar.type, ir.ScalarType) |
| 398 | - assert sum_iter.iterVar.type.dtype == DataType.INDEX | 398 | + assert sum_iter.iterVar.type.dtype == DataType.INT64 |
| 399 | 399 | ||
| 400 | func = f.get_result() | 400 | func = f.get_result() |
| 401 | assert func is not None | 401 | assert func is not None |
| @@ -433,7 +433,7 @@ def test_return_var_with_inferred_type(): | |||
| 433 | 433 | ||
| 434 | assert sum_final.name == "sum_final" | 434 | assert sum_final.name == "sum_final" |
| 435 | assert isinstance(sum_final.type, ir.ScalarType) | 435 | assert isinstance(sum_final.type, ir.ScalarType) |
| 436 | - assert sum_final.type.dtype == DataType.INDEX | 436 | + assert sum_final.type.dtype == DataType.INT64 |
| 437 | 437 | ||
| 438 | func = f.get_result() | 438 | func = f.get_result() |
| 439 | assert func is not None | 439 | assert func is not None |
| @@ -459,8 +459,8 @@ def test_return_var_with_multiple_iter_args(): | |||
| 459 | 459 | ||
| 460 | assert isinstance(sum_final.type, ir.ScalarType) | 460 | assert isinstance(sum_final.type, ir.ScalarType) |
| 461 | assert isinstance(count_final.type, ir.ScalarType) | 461 | assert isinstance(count_final.type, ir.ScalarType) |
| 462 | - assert sum_final.type.dtype == DataType.INDEX | 462 | + assert sum_final.type.dtype == DataType.INT64 |
| 463 | - assert count_final.type.dtype == DataType.INDEX | 463 | + assert count_final.type.dtype == DataType.INT64 |
| 464 | 464 | ||
| 465 | func = f.get_result() | 465 | func = f.get_result() |
| 466 | assert func is not None | 466 | assert func is not None |
| @@ -478,11 +478,11 @@ def test_return_var_explicit_type_validation(): | |||
| 478 | with ib.for_loop(i, 0, 10, 1) as loop: | 478 | with ib.for_loop(i, 0, 10, 1) as loop: |
| 479 | _ = loop.iter_arg("sum", 0) | 479 | _ = loop.iter_arg("sum", 0) |
| 480 | # Provide explicit type that matches iter_arg type | 480 | # Provide explicit type that matches iter_arg type |
| 481 | - explicit_type = ir.ScalarType(DataType.INDEX) | 481 | + explicit_type = ir.ScalarType(DataType.INT64) |
| 482 | sum_final = loop.return_var("sum_final", var_type=explicit_type) | 482 | sum_final = loop.return_var("sum_final", var_type=explicit_type) |
| 483 | 483 | ||
| 484 | assert isinstance(sum_final.type, ir.ScalarType) | 484 | assert isinstance(sum_final.type, ir.ScalarType) |
| 485 | - assert sum_final.type.dtype == DataType.INDEX | 485 | + assert sum_final.type.dtype == DataType.INT64 |
| 486 | 486 | ||
| 487 | func = f.get_result() | 487 | func = f.get_result() |
| 488 | assert func is not None | 488 | assert func is not None |
| @@ -453,7 +453,7 @@ def test_loop_output_single_return_var(): | |||
| 453 | 453 | ||
| 454 | assert result.name == "sum_final" | 454 | assert result.name == "sum_final" |
| 455 | assert isinstance(result.type, ir.ScalarType) | 455 | assert isinstance(result.type, ir.ScalarType) |
| 456 | - assert result.type.dtype == DataType.INDEX | 456 | + assert result.type.dtype == DataType.INT64 |
| 457 | 457 | ||
| 458 | ib.return_stmt(result) | 458 | ib.return_stmt(result) |
| 459 | 459 | ||
| @@ -81,7 +81,7 @@ def test_all_binary_and_comparison_operators_fold(): | |||
| 81 | "shift_right": 3, | 81 | "shift_right": 3, |
| 82 | } | 82 | } |
| 83 | for name, expected in int_expected.items(): | 83 | for name, expected in int_expected.items(): |
| 84 | - _assert_constant(values[name], expected, ir.DataType.INDEX) | 84 | + _assert_constant(values[name], expected, ir.DataType.INT64) |
| 85 | _assert_constant(values["truediv"], 3.5, ir.DataType.FP32) | 85 | _assert_constant(values["truediv"], 3.5, ir.DataType.FP32) |
| 86 | for name in ("eq", "ne", "lt", "le", "gt", "ge"): | 86 | for name in ("eq", "ne", "lt", "le", "gt", "ge"): |
| 87 | _assert_constant(values[name], True, ir.DataType.BOOL) | 87 | _assert_constant(values[name], True, ir.DataType.BOOL) |
| @@ -149,7 +149,7 @@ def test_bool_numeric_and_unary_result_dtypes(): | |||
| 149 | _assert_constant(values["float_plus"], 1.5, ir.DataType.FP32) | 149 | _assert_constant(values["float_plus"], 1.5, ir.DataType.FP32) |
| 150 | _assert_constant(values["float_minus"], -1.5, ir.DataType.FP32) | 150 | _assert_constant(values["float_minus"], -1.5, ir.DataType.FP32) |
| 151 | _assert_constant(values["int_not"], False, ir.DataType.BOOL) | 151 | _assert_constant(values["int_not"], False, ir.DataType.BOOL) |
| 152 | - _assert_constant(values["int_invert"], -4, ir.DataType.INDEX) | 152 | + _assert_constant(values["int_invert"], -4, ir.DataType.INT64) |
| 153 | _assert_constant(values["compare"], True, ir.DataType.BOOL) | 153 | _assert_constant(values["compare"], True, ir.DataType.BOOL) |
| 154 | 154 | ||
| 155 | 155 | ||
| @@ -187,7 +187,7 @@ def test_pl_and_builtin_min_max_fold_with_numeric_promotion(): | |||
| 187 | folded_min_max = folded_min_max_program.get_function(folded_min_max.__name__) | 187 | folded_min_max = folded_min_max_program.get_function(folded_min_max.__name__) |
| 188 | 188 | ||
| 189 | values = _assignments(folded_min_max) | 189 | values = _assignments(folded_min_max) |
| 190 | - _assert_constant(values["pl_min"], 2, ir.DataType.INDEX) | 190 | + _assert_constant(values["pl_min"], 2, ir.DataType.INT64) |
| 191 | _assert_constant(values["pl_max"], 2.0, ir.DataType.FP32) | 191 | _assert_constant(values["pl_max"], 2.0, ir.DataType.FP32) |
| 192 | _assert_constant(values["builtin_min"], 1, ir.DataType.INT64) | 192 | _assert_constant(values["builtin_min"], 1, ir.DataType.INT64) |
| 193 | _assert_constant(values["builtin_max"], 2.5, ir.DataType.FP32) | 193 | _assert_constant(values["builtin_max"], 2.5, ir.DataType.FP32) |
| @@ -321,7 +321,7 @@ def test_inline_helper_constant_conditions_fold_independently_at_multiple_call_s | |||
| 321 | "fallback_is_constant", | 321 | "fallback_is_constant", |
| 322 | ): | 322 | ): |
| 323 | _assert_constant(values[name], True, ir.DataType.BOOL) | 323 | _assert_constant(values[name], True, ir.DataType.BOOL) |
| 324 | - _assert_constant(values["combined"], 110, ir.DataType.INDEX) | 324 | + _assert_constant(values["combined"], 110, ir.DataType.INT64) |
| 325 | 325 | ||
| 326 | 326 | ||
| 327 | def test_unary_plus_is_identity_for_non_scalar_operand(): | 327 | def test_unary_plus_is_identity_for_non_scalar_operand(): |
| @@ -198,7 +198,7 @@ def test_inline_helper_nested_if_returns_preserve_fallthrough_retval_state(): | |||
| 198 | assert all(not isinstance(var.type, ir.UnknownType) for var in retval_results) | 198 | assert all(not isinstance(var.type, ir.UnknownType) for var in retval_results) |
| 199 | 199 | ||
| 200 | 200 | ||
| 201 | -def test_inline_helper_dynamic_loop_preserves_real_return_type_conflict(): | 201 | +def test_inline_helper_dynamic_loop_uses_one_int64_return_type(): |
| 202 | def choose(value): | 202 | def choose(value): |
| 203 | index = 0 | 203 | index = 0 |
| 204 | while index < value: | 204 | while index < value: |
| @@ -207,14 +207,20 @@ def test_inline_helper_dynamic_loop_preserves_real_return_type_conflict(): | |||
| 207 | index = index + 1 | 207 | index = index + 1 |
| 208 | return value | 208 | return value |
| 209 | 209 | ||
| 210 | - with pytest.raises(UndefinedVariableError, match="Use of potentially undefined variable"): | 210 | + @pl.jit(auto_mutex=False) |
| 211 | + def caller(value: pl.DT_INT64): | ||
| 212 | + selected = choose(value) | ||
| 213 | + _test_result = selected + 1 | ||
| 211 | 214 | ||
| 212 | - @pl.jit(auto_mutex=False) | 215 | + caller_program, _ = caller.to_kernel_def().parse_target_program(ir.SectionKind.Vector) |
| 213 | - def caller(value: pl.DT_INT64): | 216 | + caller_ir = caller_program.get_function(caller.__name__) |
| 214 | - selected = choose(value) | 217 | + selected = next( |
| 215 | - _test_result = selected + 1 | 218 | + stmt.var |
| 216 | - | 219 | + for stmt in _walk_statements(caller_ir.body) |
| 217 | - caller.to_kernel_def().parse_target_program(ir.SectionKind.Vector) | 220 | + if isinstance(stmt, ir.AssignStmt) and stmt.var.name.startswith("selected") |
| 221 | + ) | ||
| 222 | + assert isinstance(selected.type, ir.ScalarType) | ||
| 223 | + assert selected.type.dtype == ir.DataType.INT64 | ||
| 218 | 224 | ||
| 219 | 225 | ||
| 220 | def test_inline_helper_loop_guard_folds_constant_false(): | 226 | def test_inline_helper_loop_guard_folds_constant_false(): |
| @@ -51,16 +51,15 @@ def test_non_vf_accepts_negative_start(start): | |||
| 51 | kernel.to_kernel_def().parse_target_program(ir.SectionKind.Vector) | 51 | kernel.to_kernel_def().parse_target_program(ir.SectionKind.Vector) |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | -def test_non_vf_rejects_stop_beyond_int64(): | 54 | +def test_non_vf_rejects_folded_stop_beyond_int64(): |
| 55 | - """A value in (INT64_MAX, UINT64_MAX] parses as a folded uint64 constant; the range check | 55 | + """An INT64 constant expression rejects overflow before range lowering.""" |
| 56 | - must recover its logical value and reject it against the int64 loop-variable bound.""" | ||
| 57 | 56 | ||
| 58 | @pl.jit(auto_mutex=False) | 57 | @pl.jit(auto_mutex=False) |
| 59 | def kernel(x: pl.Tensor[[64], pl.DT_FP32]): | 58 | def kernel(x: pl.Tensor[[64], pl.DT_FP32]): |
| 60 | for _ in pl.range(INT64_MAX + 1): | 59 | for _ in pl.range(INT64_MAX + 1): |
| 61 | _y: pl.Tensor[[64], pl.DT_FP32] = pl.tensor.add(x, 1.0) | 60 | _y: pl.Tensor[[64], pl.DT_FP32] = pl.tensor.add(x, 1.0) |
| 62 | 61 | ||
| 63 | - with pytest.raises(FinalRejectionError, match=r"pl\.range\(\) stop must be in"): | 62 | + with pytest.raises(FinalRejectionError, match=r"integer constant must be representable in int64"): |
| 64 | kernel.to_kernel_def().parse_target_program(ir.SectionKind.Vector) | 63 | kernel.to_kernel_def().parse_target_program(ir.SectionKind.Vector) |
| 65 | 64 | ||
| 66 | 65 | ||
| @@ -84,7 +83,7 @@ def test_non_vf_rejects_start_below_storage_band(): | |||
| 84 | for _ in pl.range(INT64_MIN - 1, 10): | 83 | for _ in pl.range(INT64_MIN - 1, 10): |
| 85 | _y: pl.Tensor[[64], pl.DT_FP32] = pl.tensor.add(x, 1.0) | 84 | _y: pl.Tensor[[64], pl.DT_FP32] = pl.tensor.add(x, 1.0) |
| 86 | 85 | ||
| 87 | - with pytest.raises(FinalRejectionError, match=r"integer constant must be in"): | 86 | + with pytest.raises(FinalRejectionError, match=r"integer constant must be representable in int64"): |
| 88 | kernel.to_kernel_def().parse_target_program(ir.SectionKind.Vector) | 87 | kernel.to_kernel_def().parse_target_program(ir.SectionKind.Vector) |
| 89 | 88 | ||
| 90 | 89 | ||
| @@ -241,20 +241,28 @@ def test_integer_outside_the_storage_band_is_rejected(value): | |||
| 241 | @pytest.mark.parametrize( | 241 | @pytest.mark.parametrize( |
| 242 | ("value", "dtype", "stored"), | 242 | ("value", "dtype", "stored"), |
| 243 | [ | 243 | [ |
| 244 | - (INT64_MAX, ir.DataType.INDEX, INT64_MAX), | 244 | + (INT64_MAX, ir.DataType.INT64, INT64_MAX), |
| 245 | - (INT64_MIN, ir.DataType.INDEX, INT64_MIN), | 245 | + (INT64_MIN, ir.DataType.INT64, INT64_MIN), |
| 246 | (INT64_MAX + 1, ir.DataType.UINT64, INT64_MIN), | 246 | (INT64_MAX + 1, ir.DataType.UINT64, INT64_MIN), |
| 247 | (UINT64_MAX, ir.DataType.UINT64, -1), | 247 | (UINT64_MAX, ir.DataType.UINT64, -1), |
| 248 | ], | 248 | ], |
| 249 | ) | 249 | ) |
| 250 | -def test_uint64_band_settles_on_uint64_and_folds(value, dtype, stored): | 250 | +def test_default_integer_literal_uses_int64_or_uint64(value, dtype, stored): |
| 251 | - """A value above INT64_MAX commits the uncommitted INDEX placeholder to UINT64 and folds.""" | 251 | + from pypto_pro.language.parser.diagnostics import make_const_int |
| 252 | + | ||
| 253 | + const = make_const_int(value, span=ir.Span.unknown()) | ||
| 254 | + | ||
| 255 | + assert const.type.dtype == dtype | ||
| 256 | + assert const.value == stored | ||
| 257 | + | ||
| 258 | + | ||
| 259 | +@pytest.mark.parametrize("value", [INT64_MIN, INT64_MAX]) | ||
| 260 | +def test_explicit_legacy_index_dtype_is_preserved(value): | ||
| 252 | from pypto_pro.language.parser.diagnostics import make_const_int | 261 | from pypto_pro.language.parser.diagnostics import make_const_int |
| 253 | 262 | ||
| 254 | const = make_const_int(value, ir.DataType.INDEX, span=ir.Span.unknown()) | 263 | const = make_const_int(value, ir.DataType.INDEX, span=ir.Span.unknown()) |
| 255 | 264 | ||
| 256 | - assert const.type.dtype == dtype | 265 | + assert const.type.dtype == ir.DataType.INDEX |
| 257 | - assert const.value == stored | ||
| 258 | 266 | ||
| 259 | 267 | ||
| 260 | def test_named_dtype_is_taken_at_its_word(): | 268 | def test_named_dtype_is_taken_at_its_word(): |
| @@ -79,12 +79,12 @@ def test_resolve_dynamic_policy_and_int_variable_mixed(): | |||
| 79 | assert tensor_type.shape[1].value == 64 | 79 | assert tensor_type.shape[1].value == 64 |
| 80 | 80 | ||
| 81 | 81 | ||
| 82 | -def test_dynamic_policy_has_index_scalar_type(): | 82 | +def test_dynamic_policy_has_int64_scalar_type(): |
| 83 | resolver = _make_resolver(closure_vars={"pl": pl}) | 83 | resolver = _make_resolver(closure_vars={"pl": pl}) |
| 84 | node = ast.parse("pl.Tensor[[pl.DYNAMIC], pl.DT_FP32]", mode="eval").body | 84 | node = ast.parse("pl.Tensor[[pl.DYNAMIC], pl.DT_FP32]", mode="eval").body |
| 85 | tensor_type = resolver.resolve_param_type(node, parameter_name="x") | 85 | tensor_type = resolver.resolve_param_type(node, parameter_name="x") |
| 86 | assert isinstance(tensor_type.shape[0].type, ir.ScalarType) | 86 | assert isinstance(tensor_type.shape[0].type, ir.ScalarType) |
| 87 | - assert tensor_type.shape[0].type.dtype == DataType.INDEX | 87 | + assert tensor_type.shape[0].type.dtype == DataType.INT64 |
| 88 | 88 | ||
| 89 | 89 | ||
| 90 | def test_parse_shape_with_scope_variable(): | 90 | def test_parse_shape_with_scope_variable(): |
| @@ -252,7 +252,7 @@ def test_struct_mixed_dtype_array_fields(): | |||
| 252 | assignments = [stmt for stmt in kernel.body.stmts if isinstance(stmt, ir.AssignStmt)] | 252 | assignments = [stmt for stmt in kernel.body.stmts if isinstance(stmt, ir.AssignStmt)] |
| 253 | struct_assign = next(stmt for stmt in assignments if stmt.var.name == "s_0") | 253 | struct_assign = next(stmt for stmt in assignments if stmt.var.name == "s_0") |
| 254 | types = struct_assign.var.type.types | 254 | types = struct_assign.var.type.types |
| 255 | - assert all(t.dtype == DataType.INDEX for t in types[0].types) | 255 | + assert all(t.dtype == DataType.INT64 for t in types[0].types) |
| 256 | assert all(t.dtype == DataType.FP32 for t in types[1].types) | 256 | assert all(t.dtype == DataType.FP32 for t in types[1].types) |
| 257 | assert all(t.dtype == DataType.BOOL for t in types[2].types) | 257 | assert all(t.dtype == DataType.BOOL for t in types[2].types) |
| 258 | 258 | ||
| @@ -113,3 +113,20 @@ def test_tile_slice_rejects_non_unit_step(): | |||
| 113 | 113 | ||
| 114 | with pytest.raises(ParserSyntaxError, match="slice step for axis 0 must be the compile-time integer 1"): | 114 | with pytest.raises(ParserSyntaxError, match="slice step for axis 0 must be the compile-time integer 1"): |
| 115 | _parse_vector_kernel(kernel) | 115 | _parse_vector_kernel(kernel) |
| 116 | + | ||
| 117 | + | ||
| 118 | +def test_tile_slice_with_dynamic_valid_shape(): | ||
| 119 | + @pl.jit(auto_mutex=False) | ||
| 120 | + def kernel(rows: pl.DT_INT64, cols: pl.DT_INT64): | ||
| 121 | + tile_type = pl.TileType( | ||
| 122 | + shape=[8, 64], | ||
| 123 | + dtype=pl.DT_FP32, | ||
| 124 | + target_memory=pl.MemorySpace.Vec, | ||
| 125 | + valid_shape=[-1, -1], | ||
| 126 | + ) | ||
| 127 | + tile = pl.make_tile(tile_type, addr=0, size=2048) | ||
| 128 | + with pl.section_vector(): | ||
| 129 | + pl.set_validshape(tile, [rows, cols]) | ||
| 130 | + _sub = tile[1:, :] | ||
| 131 | + | ||
| 132 | + _parse_vector_kernel(kernel) | ||
| @@ -89,7 +89,7 @@ def test_tiling_scalar_dtypes_are_correct(): | |||
| 89 | assert isinstance(tuple_type, ir.TupleType) | 89 | assert isinstance(tuple_type, ir.TupleType) |
| 90 | elem_types = tuple_type.types | 90 | elem_types = tuple_type.types |
| 91 | # Scalar fields become scalar tuple elements in declaration order. | 91 | # Scalar fields become scalar tuple elements in declaration order. |
| 92 | - assert elem_types[0].dtype == DataType.INDEX | 92 | + assert elem_types[0].dtype == DataType.INT64 |
| 93 | assert elem_types[1].dtype == DataType.FP32 | 93 | assert elem_types[1].dtype == DataType.FP32 |
| 94 | assert elem_types[2].dtype == DataType.BOOL | 94 | assert elem_types[2].dtype == DataType.BOOL |
| 95 | 95 | ||
| @@ -302,7 +302,7 @@ def test_array_field_dtypes(): | |||
| 302 | assert isinstance(kernel, ir.Function) | 302 | assert isinstance(kernel, ir.Function) |
| 303 | assert len(kernel.params) == 2 | 303 | assert len(kernel.params) == 2 |
| 304 | elem_types = kernel.params[1].type.types | 304 | elem_types = kernel.params[1].type.types |
| 305 | - assert all(t.dtype == DataType.INDEX for t in elem_types[0].types) | 305 | + assert all(t.dtype == DataType.INT64 for t in elem_types[0].types) |
| 306 | assert all(t.dtype == DataType.FP32 for t in elem_types[1].types) | 306 | assert all(t.dtype == DataType.FP32 for t in elem_types[1].types) |
| 307 | assert all(t.dtype == DataType.BOOL for t in elem_types[2].types) | 307 | assert all(t.dtype == DataType.BOOL for t in elem_types[2].types) |
| 308 | 308 | ||
| @@ -33,7 +33,7 @@ def test_array_type_creation(): | |||
| 33 | assert is_tiling_class(TilingData) is True | 33 | assert is_tiling_class(TilingData) is True |
| 34 | fields = get_tiling_fields(TilingData) | 34 | fields = get_tiling_fields(TilingData) |
| 35 | assert isinstance(fields["offsets"], ArrayFieldInfo) | 35 | assert isinstance(fields["offsets"], ArrayFieldInfo) |
| 36 | - assert fields["offsets"].dtype == DataType.INDEX | 36 | + assert fields["offsets"].dtype == DataType.INT64 |
| 37 | assert fields["offsets"].size == 4 | 37 | assert fields["offsets"].size == 4 |
| 38 | 38 | ||
| 39 | 39 | ||
| @@ -126,7 +126,7 @@ def test_get_tiling_fields_returns_array_field_info(): | |||
| 126 | assert "offsets" in fields | 126 | assert "offsets" in fields |
| 127 | info = fields["offsets"] | 127 | info = fields["offsets"] |
| 128 | assert isinstance(info, ArrayFieldInfo) | 128 | assert isinstance(info, ArrayFieldInfo) |
| 129 | - assert info.dtype == DataType.INDEX | 129 | + assert info.dtype == DataType.INT64 |
| 130 | assert info.size == 3 | 130 | assert info.size == 3 |
| 131 | 131 | ||
| 132 | 132 | ||
| @@ -138,7 +138,7 @@ def test_get_tiling_fields_mixed(): | |||
| 138 | 138 | ||
| 139 | fields = get_tiling_fields(TilingData) | 139 | fields = get_tiling_fields(TilingData) |
| 140 | assert isinstance(fields["n"], ScalarFieldInfo) | 140 | assert isinstance(fields["n"], ScalarFieldInfo) |
| 141 | - assert fields["n"].dtype == DataType.INDEX | 141 | + assert fields["n"].dtype == DataType.INT64 |
| 142 | assert isinstance(fields["offsets"], ArrayFieldInfo) | 142 | assert isinstance(fields["offsets"], ArrayFieldInfo) |
| 143 | assert fields["offsets"].dtype == DataType.FP32 | 143 | assert fields["offsets"].dtype == DataType.FP32 |
| 144 | assert fields["offsets"].size == 2 | 144 | assert fields["offsets"].size == 2 |
| @@ -70,7 +70,7 @@ def test_get_tiling_fields_maps_scalar_fields_and_preserves_order(): | |||
| 70 | 70 | ||
| 71 | assert list(fields.keys()) == ["n", "scale", "enabled"] | 71 | assert list(fields.keys()) == ["n", "scale", "enabled"] |
| 72 | assert fields == { | 72 | assert fields == { |
| 73 | - "n": ScalarFieldInfo(DataType.INDEX), | 73 | + "n": ScalarFieldInfo(DataType.INT64), |
| 74 | "scale": ScalarFieldInfo(DataType.FP32), | 74 | "scale": ScalarFieldInfo(DataType.FP32), |
| 75 | "enabled": ScalarFieldInfo(DataType.BOOL), | 75 | "enabled": ScalarFieldInfo(DataType.BOOL), |
| 76 | } | 76 | } |
| @@ -79,8 +79,8 @@ def test_get_tiling_fields_maps_scalar_fields_and_preserves_order(): | |||
| 79 | def test_get_tiling_fields_maps_array_fields(): | 79 | def test_get_tiling_fields_maps_array_fields(): |
| 80 | fields = get_tiling_fields(MixedTiling) | 80 | fields = get_tiling_fields(MixedTiling) |
| 81 | 81 | ||
| 82 | - assert fields["n"] == ScalarFieldInfo(DataType.INDEX) | 82 | + assert fields["n"] == ScalarFieldInfo(DataType.INT64) |
| 83 | - assert fields["offsets"] == ArrayFieldInfo(DataType.INDEX, 4) | 83 | + assert fields["offsets"] == ArrayFieldInfo(DataType.INT64, 4) |
| 84 | assert fields["scales"] == ArrayFieldInfo(DataType.FP32, 2) | 84 | assert fields["scales"] == ArrayFieldInfo(DataType.FP32, 2) |
| 85 | 85 | ||
| 86 | 86 | ||