Skip to content

Commit 3069c2b

Browse files
Ryker0627assistant-librarian[bot]
authored andcommitted
[rocm-libraries] ROCm/rocm-libraries#6073 (commit a538084)
[hipTensor] Add compiling options for unary ops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Motivation Add compiling options for unary ops and make hipTensor compiling fast ## Technical Details This PR resolves an issue where the introduction of unary ops in contraction caused hipTensor compile times to increase by 3–4x. A new compile-time option, HIPTENSOR_INLINE_UNARY_OPS, has been added to control this behavior. When set to ON, the switch_op method in the HiptensorUnaryOp class is compiled inline, which was identified as the root cause of the compile time regression. When set to OFF, switch_op is compiled with noinline, restoring compile times to their baseline levels prior to the addition of unary op support. The default value of HIPTENSOR_INLINE_UNARY_OPS is OFF. ## Test Plan run normal tests. test compiling when HIPTENSOR_INLINE_UNARY_OPS is OFF or ON. ## Test Result all tests passed. ## Submission Checklist - [ ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent 1b417a5 commit 3069c2b

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ if(CMAKE_PROJECT_NAME STREQUAL "hiptensor")
7474
option(HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR "Set hiptensor default strides to column major" ON)
7575
option(BUILD_OFFLOAD_COMPRESS "Build hiptensor with offload compression" ON)
7676
option(HIPTENSOR_CODE_COVERAGE "Build with code coverage flags (clang only)" OFF)
77+
option(HIPTENSOR_INLINE_UNARY_OPS "Inline all unary ops for best runtime performance (slower compilation)" OFF)
7778
endif()
7879

7980
# Setup output paths
@@ -157,6 +158,13 @@ else()
157158
endif()
158159
message(STATUS "HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR=${HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR}")
159160

161+
if(HIPTENSOR_INLINE_UNARY_OPS)
162+
add_compile_definitions(HIPTENSOR_INLINE_UNARY_OPS=1)
163+
else()
164+
add_compile_definitions(HIPTENSOR_INLINE_UNARY_OPS=0)
165+
endif()
166+
message(STATUS "HIPTENSOR_INLINE_UNARY_OPS=${HIPTENSOR_INLINE_UNARY_OPS}")
167+
160168
# Setup HIP
161169
find_package(hip REQUIRED)
162170
math(EXPR hip_VERSION_FLAT "(${hip_VERSION_MAJOR} * 1000 + ${hip_VERSION_MINOR}) * 100000 + ${hip_VERSION_PATCH}")

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ For more detailed information, please refer to the [hipTensor installation guide
3434

3535
### Project options
3636

37-
| Option | Description | Default Value |
38-
|-------------------------------------|---------------------------------------------------------|---------------------------------------------------------|
39-
| GPU_TARGETS | Build code for specific GPU target(s) | gfx908;gfx90a;gfx942;gfx950;gfx11-generic;gfx12-generic |
40-
| HIPTENSOR_BUILD_TESTS | Build the tests | ON |
41-
| HIPTENSOR_BUILD_SAMPLES | Build the samples | ON |
42-
| HIPTENSOR_BUILD_COMPRESSED_DBG | Enable compressed debug symbols | ON |
43-
| HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR | Set the hipTensor default data layout to column major | ON |
37+
| Option | Description | Default Value |
38+
|-------------------------------------|--------------------------------------------------------------------------|---------------------------------------------------------|
39+
| GPU_TARGETS | Build code for specific GPU target(s) | gfx908;gfx90a;gfx942;gfx950;gfx11-generic;gfx12-generic |
40+
| HIPTENSOR_BUILD_TESTS | Build the tests | ON |
41+
| HIPTENSOR_BUILD_SAMPLES | Build the samples | ON |
42+
| HIPTENSOR_BUILD_COMPRESSED_DBG | Enable compressed debug symbols | ON |
43+
| HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR | Set the hipTensor default data layout to column major | ON |
44+
| HIPTENSOR_INLINE_UNARY_OPS | Inline all unary ops for best runtime performance (slower compilation) | OFF |
4445

4546
### Example configurations
4647

docs/install/installation.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ Here are the available options to build the hipTensor library, with or without c
184184
* - ``HIPTENSOR_DEFAULT_STRIDES_COL_MAJOR``
185185
- Set the hipTensor default data layout to column major
186186
- ``ON``
187+
* - ``HIPTENSOR_INLINE_UNARY_OPS``
188+
- Inline all contraction unary ops for best runtime performance (slower compilation)
189+
- ``OFF``
187190

188191
Here are some example project configurations:
189192

library/src/include/hiptensor_element_wise_operation.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
#include <ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp>
3737
#include <hiptensor/hiptensor_types.h>
3838

39+
#if HIPTENSOR_INLINE_UNARY_OPS
40+
#define HIPTENSOR_UNARY_INLINE
41+
#else
42+
#define HIPTENSOR_UNARY_INLINE __attribute__((noinline))
43+
#endif
44+
3945
namespace ck
4046
{
4147
namespace tensor_operation
@@ -179,7 +185,7 @@ namespace ck
179185
= default;
180186

181187
template <typename T>
182-
__host__ __device__ void switch_op(T& y, T const& x) const
188+
__host__ __device__ HIPTENSOR_UNARY_INLINE void switch_op(T& y, T const& x) const
183189
{
184190
switch(op_type)
185191
{

0 commit comments

Comments
 (0)