Skip to content

Commit 4d2fbd0

Browse files
committed
assert trivially copyable type
1 parent fe281f4 commit 4d2fbd0

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

include/triton_jit/triton_kernel.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ class TritonJITFunction;
1313

1414
template <typename T>
1515
T get_next_multiple_of(T pos, T step) {
16-
if (pos % step == 0) return pos;
17-
18-
while (pos % step) {
19-
pos++;
20-
}
21-
return pos;
16+
return ((pos + step - 1) / step) * step;
2217
}
2318

2419
struct ParameterBuffer {
@@ -34,11 +29,13 @@ struct ParameterBuffer {
3429

3530
template <typename T>
3631
void push_arg(T &&v) {
37-
size_t align = alignof(T);
32+
using U = std::decay_t<T>;
33+
static_assert(std::is_trivially_copyable_v<U>, "Non trivially copyable type");
34+
size_t align = alignof(U);
3835
size_t offset = get_next_multiple_of(this->cursor_, align);
3936
this->offsets_.push_back(offset);
4037

41-
size_t size = sizeof(T);
38+
size_t size = sizeof(U);
4239
this->buff_.resize(offset + size);
4340
std::byte *ptr = this->buff_.data() + offset;
4441
std::memcpy(ptr, &v, size);

0 commit comments

Comments
 (0)