Skip to content

Commit e6b8094

Browse files
illsilinassistant-librarian[bot]
authored andcommitted
[rocm-libraries] ROCm/rocm-libraries#5921 (commit 032ac1b)
[CK] fix clang lifetimebound errors with staging compiler (#5921) ## Motivation The ROCm staging compiler (newer Clang) enforces `[[clang::lifetimebound]]` annotations on methods that return references or pointers to internal object data. Without these annotations, the staging compiler emits compilation errors for container accessor methods across the CK and CK Tile namespaces. ## Technical Details Adds `[[clang::lifetimebound]]` to all reference/pointer-returning accessors in core container types: **`ck::` namespace:** - `Array` -- `At()`, `operator[]`, `operator()`, `begin()`, `end()` - `index_array` -- `operator[]` - `StaticallyIndexedArray_v2` -- `At()`, `operator[]`, `operator()` - `IndexLookupTable` -- `operator[]` **`ck_tile::` namespace:** - `array` -- `get(i)`, `at()`, `operator[]`, `operator()` - `static_array` -- `operator[]` - `thread_buffer` -- `get(i)`, `at()`, `operator[]`, `operator()` - `make_kernel()` -- parameter pack Also removes the unused `instance_index` variable from `batched_gemm_reduce_fp16.cpp` and simplifies its argument parsing accordingly. ## Test Plan - Compile with the staging compiler to verify all lifetimebound errors are resolved - Existing tests pass unchanged -- the attribute is a compile-time annotation with no runtime effect ## Test Result <!-- Briefly summarize test outcomes. --> ## Submission Checklist - [x] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent 2dcae9d commit e6b8094

12 files changed

Lines changed: 83 additions & 72 deletions

File tree

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,8 +1317,8 @@ pipeline {
13171317
description: "Build CK and run tests on gfx12 (default: ON)")
13181318
booleanParam(
13191319
name: "NINJA_BUILD_TRACE",
1320-
defaultValue: false,
1321-
description: "Generate a ninja build trace (default: OFF)")
1320+
defaultValue: true,
1321+
description: "Generate a ninja build trace (default: ON)")
13221322
booleanParam(
13231323
name: "NINJA_FTIME_TRACE",
13241324
defaultValue: false,

include/ck/tensor_description/tensor_space_filling_curve.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct IndexLookupTable
2424
MultiIndex<nDim> data[NumAccesses > 0 ? NumAccesses : 1];
2525

2626
__host__ __device__ constexpr const MultiIndex<nDim>& operator[](index_t i) const
27+
[[clang::lifetimebound]]
2728
{
2829
return data[i];
2930
}

include/ck/utility/array.hpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@ struct Array
2424

2525
__host__ __device__ static constexpr index_t Size() { return NSize; }
2626

27-
__host__ __device__ constexpr const TData& At(index_t i) const { return mData[i]; }
27+
__host__ __device__ constexpr const TData& At(index_t i) const [[clang::lifetimebound]]
28+
{
29+
return mData[i];
30+
}
2831

29-
__host__ __device__ constexpr TData& At(index_t i) { return mData[i]; }
32+
__host__ __device__ constexpr TData& At(index_t i) [[clang::lifetimebound]] { return mData[i]; }
3033

31-
__host__ __device__ constexpr const TData& operator[](index_t i) const { return At(i); }
34+
__host__ __device__ constexpr const TData& operator[](index_t i) const [[clang::lifetimebound]]
35+
{
36+
return At(i);
37+
}
3238

33-
__host__ __device__ constexpr TData& operator()(index_t i) { return At(i); }
39+
__host__ __device__ constexpr TData& operator()(index_t i) [[clang::lifetimebound]]
40+
{
41+
return At(i);
42+
}
3443

3544
template <typename... Args>
3645
__host__ constexpr auto Emplace(index_t i, Args&&... args)
@@ -50,10 +59,16 @@ struct Array
5059

5160
return *this;
5261
}
53-
__host__ __device__ constexpr const TData* begin() const { return &mData[0]; }
54-
__host__ __device__ constexpr const TData* end() const { return &mData[NSize]; }
55-
__host__ __device__ constexpr TData* begin() { return &mData[0]; }
56-
__host__ __device__ constexpr TData* end() { return &mData[NSize]; }
62+
__host__ __device__ constexpr const TData* begin() const [[clang::lifetimebound]]
63+
{
64+
return &mData[0];
65+
}
66+
__host__ __device__ constexpr const TData* end() const [[clang::lifetimebound]]
67+
{
68+
return &mData[NSize];
69+
}
70+
__host__ __device__ constexpr TData* begin() [[clang::lifetimebound]] { return &mData[0]; }
71+
__host__ __device__ constexpr TData* end() [[clang::lifetimebound]] { return &mData[NSize]; }
5772
};
5873

5974
// empty Array

include/ck/utility/sequence.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,15 @@ struct index_array
403403
{
404404
index_t data[N > 0 ? N : 1];
405405

406-
__host__ __device__ constexpr index_t& operator[](index_t i) { return data[i]; }
407-
__host__ __device__ constexpr const index_t& operator[](index_t i) const { return data[i]; }
406+
__host__ __device__ constexpr index_t& operator[](index_t i) [[clang::lifetimebound]]
407+
{
408+
return data[i];
409+
}
410+
__host__ __device__ constexpr const index_t& operator[](index_t i) const
411+
[[clang::lifetimebound]]
412+
{
413+
return data[i];
414+
}
408415
};
409416

410417
/**

include/ck/utility/statically_indexed_array.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct StaticallyIndexedArray_v2
6969

7070
// read access
7171
template <index_t I>
72-
__host__ __device__ constexpr const auto& At(Number<I>) const
72+
__host__ __device__ constexpr const auto& At(Number<I>) const [[clang::lifetimebound]]
7373
{
7474
static_assert(I < N, "wrong! out of range");
7575

@@ -78,7 +78,7 @@ struct StaticallyIndexedArray_v2
7878

7979
// write access
8080
template <index_t I>
81-
__host__ __device__ constexpr auto& At(Number<I>)
81+
__host__ __device__ constexpr auto& At(Number<I>) [[clang::lifetimebound]]
8282
{
8383
static_assert(I < N, "wrong! out of range");
8484

@@ -87,14 +87,14 @@ struct StaticallyIndexedArray_v2
8787

8888
// read access
8989
template <index_t I>
90-
__host__ __device__ constexpr const auto& operator[](Number<I> i) const
90+
__host__ __device__ constexpr const auto& operator[](Number<I> i) const [[clang::lifetimebound]]
9191
{
9292
return At(i);
9393
}
9494

9595
// write access
9696
template <index_t I>
97-
__host__ __device__ constexpr auto& operator()(Number<I> i)
97+
__host__ __device__ constexpr auto& operator()(Number<I> i) [[clang::lifetimebound]]
9898
{
9999
return At(i);
100100
}

include/ck_tile/core/container/array.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,23 @@ struct array
103103
// clang-format off
104104
CK_TILE_HOST_DEVICE constexpr auto& get() { return data; }
105105
CK_TILE_HOST_DEVICE constexpr const auto& get() const { return data; }
106-
CK_TILE_HOST_DEVICE constexpr auto& get(index_t i) { return data[i]; }
107-
CK_TILE_HOST_DEVICE constexpr const auto& get(index_t i) const { return data[i]; }
106+
CK_TILE_HOST_DEVICE constexpr auto& get(index_t i) [[clang::lifetimebound]] { return data[i]; }
107+
CK_TILE_HOST_DEVICE constexpr const auto& get(index_t i) const [[clang::lifetimebound]] { return data[i]; }
108108
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& get() { return data[I]; }
109109
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& get() const { return data[I]; }
110-
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& get(number<I>) { return data[I]; }
110+
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& get(number<I>)[[clang::lifetimebound]] { return data[I]; }
111111
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& get(number<I>) const { return data[I]; }
112112

113113
CK_TILE_HOST_DEVICE constexpr auto& at(index_t i) { return get(i); }
114-
CK_TILE_HOST_DEVICE constexpr const auto& at(index_t i) const { return get(i); }
115-
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at() { return get(I); }
116-
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at() const { return get(I); }
117-
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at(number<I>) { return get(I); }
118-
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at(number<I>) const { return get(I); }
119-
120-
CK_TILE_HOST_DEVICE constexpr const value_type& operator[](index_t i) const { return get(i); }
121-
CK_TILE_HOST_DEVICE constexpr value_type& operator[](index_t i) { return get(i); }
122-
CK_TILE_HOST_DEVICE constexpr value_type& operator()(index_t i) { return get(i); } // TODO: compatible
114+
CK_TILE_HOST_DEVICE constexpr const auto& at(index_t i) const [[clang::lifetimebound]] { return get(i); }
115+
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at() [[clang::lifetimebound]] { return get(I); }
116+
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at() const [[clang::lifetimebound]] { return get(I); }
117+
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at(number<I>) [[clang::lifetimebound]] { return get(I); }
118+
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at(number<I>) const [[clang::lifetimebound]] { return get(I); }
119+
120+
CK_TILE_HOST_DEVICE constexpr const value_type& operator[](index_t i) const [[clang::lifetimebound]] { return get(i); }
121+
CK_TILE_HOST_DEVICE constexpr value_type& operator[](index_t i) [[clang::lifetimebound]] { return get(i); }
122+
CK_TILE_HOST_DEVICE constexpr value_type& operator()(index_t i) [[clang::lifetimebound]] { return get(i); } // TODO: compatible
123123
#if 0
124124
template <typename ArrayLike>
125125
CK_TILE_HOST_DEVICE constexpr auto operator=(const ArrayLike& arr)

include/ck_tile/core/container/static_array.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ struct static_array
2727
T elems[N > 0 ? N : 1];
2828

2929
// Basic constexpr accessors
30-
CK_TILE_HOST_DEVICE constexpr const T& operator[](index_t i) const { return elems[i]; }
31-
CK_TILE_HOST_DEVICE constexpr T& operator[](index_t i) { return elems[i]; }
30+
CK_TILE_HOST_DEVICE constexpr const T& operator[](index_t i) const [[clang::lifetimebound]]
31+
{
32+
return elems[i];
33+
}
34+
CK_TILE_HOST_DEVICE constexpr T& operator[](index_t i) [[clang::lifetimebound]]
35+
{
36+
return elems[i];
37+
}
3238

3339
CK_TILE_HOST_DEVICE static constexpr index_t size() { return N; }
3440
};

include/ck_tile/core/container/thread_buffer.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ struct thread_buffer {
5454
CK_TILE_HOST_DEVICE static constexpr auto size() { return N; }
5555
CK_TILE_HOST_DEVICE auto & get() {return data; }
5656
CK_TILE_HOST_DEVICE const auto & get() const {return data; }
57-
CK_TILE_HOST_DEVICE auto & get(index_t i) {return data[i]; }
58-
CK_TILE_HOST_DEVICE const auto & get(index_t i) const {return data[i]; }
59-
CK_TILE_HOST_DEVICE constexpr const auto& operator[](index_t i) const { return get(i); }
60-
CK_TILE_HOST_DEVICE constexpr auto& operator[](index_t i) { return get(i); }
61-
CK_TILE_HOST_DEVICE constexpr auto& operator()(index_t i) { return get(i); } // TODO: compatible
62-
CK_TILE_HOST_DEVICE constexpr auto& at(index_t i) { return get(i); }
63-
CK_TILE_HOST_DEVICE constexpr const auto& at(index_t i) const { return get(i); }
64-
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at() { return get(I); }
65-
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at() const { return get(I); }
66-
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at(number<I>) { return get(I); }
67-
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at(number<I>) const { return get(I); }
57+
CK_TILE_HOST_DEVICE auto & get(index_t i) [[clang::lifetimebound]] {return data[i]; }
58+
CK_TILE_HOST_DEVICE const auto & get(index_t i) const [[clang::lifetimebound]] {return data[i]; }
59+
CK_TILE_HOST_DEVICE constexpr const auto& operator[](index_t i) const [[clang::lifetimebound]] {return get(i); }
60+
CK_TILE_HOST_DEVICE constexpr auto& operator[](index_t i) [[clang::lifetimebound]] { return get(i); }
61+
CK_TILE_HOST_DEVICE constexpr auto& operator()(index_t i) [[clang::lifetimebound]] { return get(i); } // TODO: compatible
62+
CK_TILE_HOST_DEVICE constexpr auto& at(index_t i) [[clang::lifetimebound]] { return get(i); }
63+
CK_TILE_HOST_DEVICE constexpr const auto& at(index_t i) const [[clang::lifetimebound]] { return get(i); }
64+
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at() [[clang::lifetimebound]] { return get(I); }
65+
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at() const [[clang::lifetimebound]] { return get(I); }
66+
template <index_t I> CK_TILE_HOST_DEVICE constexpr auto& at(number<I>) [[clang::lifetimebound]] { return get(I); }
67+
template <index_t I> CK_TILE_HOST_DEVICE constexpr const auto& at(number<I>) const [[clang::lifetimebound]] { return get(I); }
6868

6969
template <typename X_,
7070
typename std::enable_if<has_same_scalar_type<value_type, X_>::value, bool>::type = false>

include/ck_tile/host/kernel_launch.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ template <int MinBlockPerCu = CK_TILE_MIN_BLOCK_PER_CU,
8787
typename Attr = void,
8888
typename KernelImpl,
8989
typename... Args>
90-
CK_TILE_HOST auto
91-
make_kernel(KernelImpl /*f*/, dim3 grid_dim, dim3 block_dim, std::size_t lds_byte, Args... args)
90+
CK_TILE_HOST auto make_kernel(KernelImpl /*f*/,
91+
dim3 grid_dim,
92+
dim3 block_dim,
93+
std::size_t lds_byte,
94+
[[clang::lifetimebound]] Args... args)
9295
{
9396
const auto kernel = []() {
9497
if constexpr(std::is_void_v<Attr>)

test/batched_gemm_reduce/batched_gemm_reduce_fp16.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
#include "profiler/profile_batched_gemm_reduce_impl.hpp"
1313

14-
static ck::index_t param_mask = 0xffff;
15-
static ck::index_t instance_index = -1;
14+
static ck::index_t param_mask = 0xffff;
1615
struct GemmParams
1716
{
1817
ck::index_t M;
@@ -105,15 +104,14 @@ int main(int argc, char** argv)
105104
{
106105
testing::InitGoogleTest(&argc, argv);
107106
if(argc == 1) {}
108-
else if(argc == 3)
107+
else if(argc == 2)
109108
{
110-
param_mask = strtol(argv[1], nullptr, 0);
111-
instance_index = atoi(argv[2]);
109+
param_mask = strtol(argv[1], nullptr, 0);
112110
}
113111
else
114112
{
115113
std::cout << "Usage of " << argv[0] << std::endl;
116-
std::cout << "Arg1,2: param_mask instance_index(-1 means all)" << std::endl;
114+
std::cout << "Arg1: param_mask " << std::endl;
117115
}
118116
return RUN_ALL_TESTS();
119117
}

0 commit comments

Comments
 (0)