ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

threads.c (1331B)


      1 /* See LICENSE for license details. */
      2 thread_static ThreadContext *thread_context_local = 0;
      3 
      4 #define lane_context(ctx)             thread_context_select((ctx))
      5 #define lane_index()                 (thread_context_local->lane_context.index)
      6 #define lane_count()                 (thread_context_local->lane_context.count)
      7 #define lane_sync()                   thread_context_barrier_wait(0, 0, 0)
      8 #define lane_sync_u64(ptr, src_lane)  thread_context_barrier_wait((ptr), sizeof(*(ptr)), (src_lane))
      9 #define lane_range(count)             subrange_n_from_n_m_count(lane_index(), lane_count(), (count))
     10 
     11 function void
     12 thread_context_select(ThreadContext *tctx)
     13 {
     14 	thread_context_local = tctx;
     15 }
     16 
     17 function void
     18 thread_context_barrier_wait(void *broadcast, u64 broadcast_size, u64 broadcast_lane_index)
     19 {
     20 	ThreadContext *ctx = thread_context_local;
     21 	u64 broadcast_size_clamped = MIN(broadcast_size, sizeof(ctx->lane_context.broadcast_memory[0]));
     22 	if (broadcast && lane_index() == broadcast_lane_index)
     23 		mem_copy(ctx->lane_context.broadcast_memory, broadcast, broadcast_size_clamped);
     24 
     25 	os_barrier_wait(ctx->lane_context.barrier);
     26 
     27 	if (broadcast && lane_index() != broadcast_lane_index)
     28 		mem_copy(broadcast, ctx->lane_context.broadcast_memory, broadcast_size_clamped);
     29 
     30 	if (broadcast)
     31 		os_barrier_wait(ctx->lane_context.barrier);
     32 }