Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
get_sm_id.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
21
23// Get SM function
25
26namespace sham {
27
28#if defined(__SYCL_DEVICE_ONLY__) && defined(__NVPTX__)
29 #define SHAMROCK_INTRISICS_GET_SMID_AVAILABLE
30
31 DEVICE_ATTRIBUTE_ON_ACPP inline u32 get_sm_id() {
32 u32 ret;
33 #if __has_builtin(__nvvm_read_ptx_sreg_smid)
34 ret = __nvvm_read_ptx_sreg_smid();
35 #else
36 asm("mov.u32 %0, %%smid;" : "=r"(ret));
37 #endif
38 return ret;
39 }
40
41 // from https://github.com/ROCm/ROCm/issues/2059
42 // HW_REG_HW_ID is replaced by HW_REG_HW_ID1 & HW_REG_HW_ID2 on >gfx9
43#elif defined(__SYCL_DEVICE_ONLY__) && defined(__AMDGCN__) && defined(__GFX9__)
44 #define SHAMROCK_INTRISICS_GET_SMID_AVAILABLE
45 // from https://github.com/ROCm/ROCm/issues/2059
46 DEVICE_ATTRIBUTE_ON_ACPP inline u32 get_sm_id() {
47 uint cu_id;
48 asm volatile("s_getreg_b32 %0, hwreg(HW_REG_HW_ID, 8, 4)" : "=s"(cu_id));
49 return cu_id;
50 }
51
52#elif defined(__SYCL_DEVICE_ONLY__) && defined(__AMDGCN__) && defined(__GFX10__) \
53 || defined(__GFX11__)
54 #define SHAMROCK_INTRISICS_GET_SMID_AVAILABLE
55 DEVICE_ATTRIBUTE_ON_ACPP inline u32 get_sm_id() {
56 uint cu_id;
57 asm volatile("s_getreg_b32 %0, hwreg(HW_REG_HW_ID1, 10, 4)" : "=s"(cu_id));
58 return cu_id;
59 }
60
61#elif defined(_IS_ACPP_SSCP)
62 #define SHAMROCK_INTRISICS_GET_SMID_AVAILABLE
63
64 inline u32 get_sm_id() {
65 u32 ret = -1;
66
67 namespace jit = sycl::AdaptiveCpp_jit;
68
69 #if __has_builtin(__nvvm_read_ptx_sreg_smid)
70 __acpp_if_target_sscp(
71 jit::compile_if(
72 jit::reflect<jit::reflection_query::target_vendor_id>() == jit::vendor_id::nvidia,
73 [&]() {
74 ret = __nvvm_read_ptx_sreg_smid();
75 }););
76
77 #else
78 __acpp_if_target_sscp(
79 jit::compile_if(
80 jit::reflect<jit::reflection_query::target_vendor_id>() == jit::vendor_id::nvidia,
81 [&]() {
82 asm("mov.u32 %0, %%smid;" : "=r"(ret));
83 }););
84 #endif
85
86 return ret;
87 }
88
89#elif defined(__ACPP__) && ACPP_LIBKERNEL_IS_DEVICE_PASS_HOST && defined(linux)
90 // #define SHAMROCK_INTRISICS_GET_SMID_AVAILABLE
91 //
92 // inline u32 get_sm_id() {
93 // u32 ret;
94 // ret = 2;
95 // return ret;
96 //}
97
98#else
103 inline u32 get_sm_id();
104#endif
105
106} // namespace sham
constexpr const char * uint
Specific internal energy u.
std::uint32_t u32
32 bit unsigned integer
This file implement the GPU core timeline tool from A. Richermoz, F. Neyret 2024.
This file implement the GPU core timeline tool from A. Richermoz, F. Neyret 2024.
namespace for backends this one is named only sham since shambackends is too long to write
u32 get_sm_id()
Return the SM (Streaming Multiprocessor) ID of the calling thread, or equivalent if implemented.