[Compiler] Addressing new compiler warnings (#3640)

* [Compiler] Addressing new compiler warnings

Clang enables new lifetime warnings in production and we see build
errors due to this with the staging compiler.

The attributes added in this PR are suggested by the compiler. However,
I'm not very familiar with the code base, so the changes may be
incorrect.

* Update some more instances

* Adds file-level ignores via clang diagnostic pragma

The number of instances was large, so I decided to use file-level scope
to disable the warning via pragma clang diagnostic ignored.

It also showed this warning coming from the gtest dependency. For that,
I did add the respective command line flag to the CMake variables. I
don't know if this is acceptable or not.

* This adds the remaining instances

For a build on gfx90a.

* fix clang format

* Adding couple more instances from gfx1200 build

* Fixed another few instances

---------

Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com>
Co-authored-by: illsilin_amdeng <Illia.Silin@amd.com>
This commit is contained in:
Jan Patrick Lehr
2026-02-02 18:39:48 +01:00
committed by GitHub
parent e6bcd192d4
commit 069500464d
50 changed files with 228 additions and 43 deletions

View File

@@ -6,6 +6,9 @@
#include "ck/utility/common_header.hpp"
#include "ck/utility/multi_index.hpp"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wlifetime-safety-intra-tu-suggestions"
namespace ck {
template <typename LowLength>
@@ -29,7 +32,10 @@ struct PassThrough
__host__ __device__ static constexpr index_t GetNumOfUpperDimension() { return 1; }
__host__ __device__ constexpr const auto& GetUpperLengths() const { return up_lengths_; }
__host__ __device__ constexpr const auto& GetUpperLengths() const [[clang::lifetimebound]]
{
return up_lengths_;
}
template <typename LowIdx, typename UpIdx>
__host__ __device__ static constexpr void CalculateLowerIndex(LowIdx& idx_low,
@@ -305,7 +311,10 @@ struct RightPad
__host__ __device__ static constexpr index_t GetNumOfUpperDimension() { return 1; }
__host__ __device__ constexpr const auto& GetUpperLengths() const { return up_lengths_; }
__host__ __device__ constexpr const auto& GetUpperLengths() const [[clang::lifetimebound]]
{
return up_lengths_;
}
template <typename LowIdx, typename UpIdx>
__host__ __device__ static constexpr void CalculateLowerIndex(LowIdx& idx_low,
@@ -403,7 +412,10 @@ struct Embed
__host__ __device__ static constexpr index_t GetNumOfUpperDimension() { return NDimUp; }
__host__ __device__ constexpr const auto& GetUpperLengths() const { return up_lengths_; }
__host__ __device__ constexpr const auto& GetUpperLengths() const [[clang::lifetimebound]]
{
return up_lengths_;
}
template <typename LowIdx, typename UpIdx>
__host__ __device__ constexpr void CalculateLowerIndex(LowIdx& idx_low,
@@ -1074,7 +1086,10 @@ struct Merge_v2_magic_division
__host__ __device__ static constexpr index_t GetNumOfUpperDimension() { return 1; }
__host__ __device__ constexpr const auto& GetUpperLengths() const { return up_lengths_; }
__host__ __device__ constexpr const auto& GetUpperLengths() const [[clang::lifetimebound]]
{
return up_lengths_;
}
template <typename LowIdx, typename UpIdx>
__host__ __device__ constexpr void CalculateLowerIndex(LowIdx& idx_low,
@@ -1366,7 +1381,10 @@ struct Merge_v3_division_mod
__host__ __device__ static constexpr index_t GetNumOfUpperDimension() { return 1; }
__host__ __device__ constexpr const auto& GetUpperLengths() const { return up_lengths_; }
__host__ __device__ constexpr const auto& GetUpperLengths() const [[clang::lifetimebound]]
{
return up_lengths_;
}
template <typename LowIdx, typename UpIdx>
__host__ __device__ constexpr void CalculateLowerIndex(LowIdx& idx_low,
@@ -1480,7 +1498,10 @@ struct UnMerge
__host__ __device__ static constexpr index_t GetNumOfUpperDimension() { return NDimUp; }
__host__ __device__ constexpr const auto& GetUpperLengths() const { return up_lengths_; }
__host__ __device__ constexpr const auto& GetUpperLengths() const [[clang::lifetimebound]]
{
return up_lengths_;
}
template <typename LowIdx, typename UpIdx>
__host__ __device__ constexpr void CalculateLowerIndex(LowIdx& idx_low,
@@ -1640,7 +1661,10 @@ struct ConvBwdDataImplicitGemmOutTransform
__host__ __device__ static constexpr index_t GetNumOfUpperDimension() { return 3; }
__host__ __device__ constexpr const auto& GetUpperLengths() const { return up_lengths_; }
__host__ __device__ constexpr const auto& GetUpperLengths() const [[clang::lifetimebound]]
{
return up_lengths_;
}
template <typename UpIdx>
__host__ __device__ constexpr auto CalculateLowerIndexN(const UpIdx& idx_up) const
@@ -2236,3 +2260,4 @@ struct Xor
}
};
} // namespace ck
#pragma clang diagnostic pop

View File

@@ -23,7 +23,10 @@ struct TensorAdaptor
{
__host__ __device__ static constexpr index_t GetNumOfTransform() { return Transforms::Size(); }
__host__ __device__ constexpr const auto& GetTransforms() const { return transforms_; }
__host__ __device__ constexpr const auto& GetTransforms() const [[clang::lifetimebound]]
{
return transforms_;
}
__host__ __device__ static constexpr auto GetLowerDimensionHiddenIdss()
{

View File

@@ -7,6 +7,8 @@
#include "ck/utility/sequence_helper.hpp"
#include "ck/tensor_description/multi_index_transform.hpp"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wlifetime-safety-intra-tu-suggestions"
namespace ck {
template <index_t NDimHidden, typename VisibleDimensionIds>
@@ -179,7 +181,10 @@ struct TensorDescriptor
}
// TODO make these private
__host__ __device__ constexpr const auto& GetTransforms() const { return transforms_; }
__host__ __device__ constexpr const auto& GetTransforms() const [[clang::lifetimebound]]
{
return transforms_;
}
__host__ __device__ static constexpr auto GetLowerDimensionIdss()
{
@@ -253,9 +258,12 @@ struct TensorCoordinate
__host__ __device__ constexpr index_t GetOffset() const { return idx_hidden_[Number<0>{}]; }
// TODO make these private
__host__ __device__ constexpr const auto& GetHiddenIndex() const { return idx_hidden_; }
__host__ __device__ constexpr const auto& GetHiddenIndex() const [[clang::lifetimebound]]
{
return idx_hidden_;
}
__host__ __device__ auto& GetHiddenIndex() { return idx_hidden_; }
__host__ __device__ auto& GetHiddenIndex() [[clang::lifetimebound]] { return idx_hidden_; }
__host__ __device__ constexpr auto GetVisibleIndex() const
{
@@ -284,7 +292,7 @@ struct TensorCoordinateStep
__host__ __device__ constexpr const auto& GetIndexDiff() const { return GetVisibleIndexDiff(); }
// TODO make these private
__host__ __device__ constexpr const auto& GetVisibleIndexDiff() const
__host__ __device__ constexpr const auto& GetVisibleIndexDiff() const [[clang::lifetimebound]]
{
return idx_diff_visible_;
}
@@ -613,3 +621,4 @@ using TensorCoordinateStep_t = decltype(make_tensor_coordinate_step(
TensorDesc{}, MultiIndex<remove_cvref_t<TensorDesc>::GetNumOfDimension()>{}));
} // namespace ck
#pragma clang diagnostic pop