[libc-commits] [PATCH] D149894: [libc] Add RPC utility functions for handling the lanes

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu May 4 12:54:15 PDT 2023


jhuber6 created this revision.
jhuber6 added a reviewer: JonChesterfield.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

Split this into separate patch. It provides utility function that let
us operate on the lanes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149894

Files:
  libc/src/__support/RPC/rpc_util.h


Index: libc/src/__support/RPC/rpc_util.h
===================================================================
--- libc/src/__support/RPC/rpc_util.h
+++ libc/src/__support/RPC/rpc_util.h
@@ -9,12 +9,16 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_RPC_RPC_UTILS_H
 #define LLVM_LIBC_SRC_SUPPORT_RPC_RPC_UTILS_H
 
+#include "src/__support/GPU/utils.h"
 #include "src/__support/macros/attributes.h"
 #include "src/__support/macros/properties/architectures.h"
 
 namespace __llvm_libc {
 namespace rpc {
 
+/// Maximum amount of data a single lane can use.
+constexpr uint64_t MAX_LANE_SIZE = 64;
+
 /// Suspend the thread briefly to assist the thread scheduler during busy loops.
 LIBC_INLINE void sleep_briefly() {
 #if defined(LIBC_TARGET_ARCH_IS_NVPTX) && __CUDA_ARCH__ >= 700
@@ -26,6 +30,25 @@
 #endif
 }
 
+/// Get the first active thread inside the lane.
+LIBC_INLINE uint64_t get_first_lane_id(uint64_t lane_mask) {
+  return __builtin_ffsl(lane_mask) - 1;
+}
+
+/// Conditional that is only true for a single thread in a lane.
+LIBC_INLINE bool is_first_lane(uint64_t lane_mask) {
+  return gpu::get_lane_id() == get_first_lane_id(lane_mask);
+}
+
+/// Conditional to indicate if this process is running on the GPU.
+LIBC_INLINE constexpr bool is_process_gpu() {
+#if defined(LIBC_TARGET_ARCH_IS_GPU)
+  return true;
+#else
+  return false;
+#endif
+}
+
 } // namespace rpc
 } // namespace __llvm_libc
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149894.519619.patch
Type: text/x-patch
Size: 1397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230504/c33af11e/attachment.bin>


More information about the libc-commits mailing list