Skip to content

Commit 735c128

Browse files
author
zhangyue
committed
refactor(data_type): pin DataType enum values explicitly
The `AscendC` custom kernels forward `static_cast<int64_t>(input.dtype())` to their `aclrtlaunch_*` entry points and dispatch on the same enum — making `DataType`'s integer values part of a host↔device ABI. Assign explicit values (`kInt8 = 0, …, kFloat64 = 11`) to pin that ABI: reordering or inserting entries above existing ones would silently change the integers seen by device code. No behaviour change at call sites (the enum is still accessed by symbolic name everywhere except the `int64_t` cast).
1 parent 77300e4 commit 735c128

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

src/data_type.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@
1111

1212
namespace infini::ops {
1313

14+
// Element-type tag shared across the project. Values are assigned
15+
// explicitly because they are part of the ABI between the host-side
16+
// launcher wrappers (e.g. `src/ascend/rms_norm/kernel_custom.h`) and the
17+
// `aclrtlaunch_*` device kernels under `src/ascend/custom/**/op_kernel/`
18+
// — the launcher forwards `static_cast<int64_t>(input.dtype())` and the
19+
// kernel dispatches on it. Reordering entries would silently break that
20+
// ABI.
1421
enum class DataType : std::int8_t {
15-
kInt8,
16-
kInt16,
17-
kInt32,
18-
kInt64,
19-
kUInt8,
20-
kUInt16,
21-
kUInt32,
22-
kUInt64,
23-
kFloat16,
24-
kBFloat16,
25-
kFloat32,
26-
kFloat64
22+
kInt8 = 0,
23+
kInt16 = 1,
24+
kInt32 = 2,
25+
kInt64 = 3,
26+
kUInt8 = 4,
27+
kUInt16 = 5,
28+
kUInt32 = 6,
29+
kUInt64 = 7,
30+
kFloat16 = 8,
31+
kBFloat16 = 9,
32+
kFloat32 = 10,
33+
kFloat64 = 11,
2734
};
2835

2936
constexpr ConstexprMap<DataType, std::size_t, 12> kDataTypeToSize{{{

0 commit comments

Comments
 (0)