/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/get_id.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/get_id.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/get_id.hpp Source File
get_id.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved.
3 
4 #pragma once
5 
6 #include "ck/ck.hpp"
7 
8 namespace ck {
9 
10 #if defined(CK_ENABLE_DYNAMIC_WARP_SIZE)
11 __device__ constexpr index_t get_warp_size()
12 {
13 #if defined(__HIP_DEVICE_COMPILE__)
14 #if defined(__GFX9__)
15  return 64;
16 #else
17  return 32;
18 #endif
19 #else
20  return 64;
21 #endif
22 }
23 
24 inline __host__ index_t get_warp_size()
25 {
26 #if !(defined(__HIPCC_RTC__) || defined(CK_CODE_GEN_RTC))
27  int device = 0;
28  int result = 0;
29  auto status = hipGetDevice(&device);
30  if(status == hipSuccess)
31  {
32  status = hipDeviceGetAttribute(&result, hipDeviceAttributeWarpSize, device);
33  if(status == hipSuccess)
34  {
35  return result;
36  }
37  }
38 #endif
39  return 64;
40 }
41 #else
42 __host__ __device__ constexpr index_t get_warp_size()
43 {
44 #if defined(__GFX9__) || !defined(__HIP_DEVICE_COMPILE__)
45  return 64;
46 #else
47  return 32;
48 #endif
49 }
50 #endif
51 
52 __device__ index_t get_thread_local_1d_id() { return threadIdx.x; }
53 
54 __device__ index_t get_thread_global_1d_id() { return blockIdx.x * blockDim.x + threadIdx.x; }
55 
56 __device__ index_t get_warp_local_1d_id() { return threadIdx.x / get_warp_size(); }
57 
58 __device__ index_t get_block_1d_id() { return blockIdx.x; }
59 
60 __device__ index_t get_grid_size() { return gridDim.x; }
61 
62 __device__ index_t get_block_size() { return blockDim.x; }
63 
64 } // namespace ck
Definition: ck.hpp:267
__device__ index_t get_warp_local_1d_id()
Definition: get_id.hpp:56
__device__ index_t get_grid_size()
Definition: get_id.hpp:60
__host__ constexpr __device__ index_t get_warp_size()
Definition: get_id.hpp:42
__device__ index_t get_block_size()
Definition: get_id.hpp:62
__device__ index_t get_block_1d_id()
Definition: get_id.hpp:58
__device__ index_t get_thread_global_1d_id()
Definition: get_id.hpp:54
int32_t index_t
Definition: ck.hpp:298
__device__ index_t get_thread_local_1d_id()
Definition: get_id.hpp:52