[libc-commits] [libc] [libc] Fix lane-id utility function not using built-in (PR #84902)

via libc-commits libc-commits at lists.llvm.org
Tue Mar 12 05:25:05 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

Summary:
Previously we got the lane-id from taking the global thread ID and
taking off the bottom 5 bits. This works but is inefficient compared to
the NVPTX intrinsic simply dedicated to get this value.


---
Full diff: https://github.com/llvm/llvm-project/pull/84902.diff


1 Files Affected:

- (modified) libc/src/__support/GPU/nvptx/utils.h (+1-1) 


``````````diff
diff --git a/libc/src/__support/GPU/nvptx/utils.h b/libc/src/__support/GPU/nvptx/utils.h
index a92c8847b6ecdf..fe9da4e8e6cb01 100644
--- a/libc/src/__support/GPU/nvptx/utils.h
+++ b/libc/src/__support/GPU/nvptx/utils.h
@@ -97,7 +97,7 @@ LIBC_INLINE uint32_t get_lane_size() { return 32; }
 
 /// Returns the id of the thread inside of a CUDA warp executing together.
 [[clang::convergent]] LIBC_INLINE uint32_t get_lane_id() {
-  return get_thread_id() & (get_lane_size() - 1);
+  return __nvvm_read_ptx_sreg_laneid();
 }
 
 /// Returns the bit-mask of active threads in the current warp.

``````````

</details>


https://github.com/llvm/llvm-project/pull/84902


More information about the libc-commits mailing list