homer512

CUDA producer-consumer pipe

Aug 21st, 2024
9,462
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | Source Code | 0 0
  1. __device__ float produce(int iteration, unsigned idx);
  2.  
  3. __device__ void consume(int iteration, unsigned idx, float value);
  4.  
  5. __global__ void kernel(int iterations)
  6. {
  7.     /*
  8.      * Tuning parameters: Number of samples to buffer
  9.      * and number of producer vs. consumer threads
  10.      */
  11.     constexpr unsigned bufsize = 128;
  12.     const unsigned producer_count = 32;
  13.     const unsigned consumer_count = blockDim.x - producer_count;
  14.     /*
  15.      * Simple double-buffer setup to make a producer-consumer pipeline
  16.      */
  17.     __shared__ float buf[2][bufsize];
  18.     const bool is_producer = threadIdx.x < producer_count;
  19.     /*
  20.      * Fill first buffer. This can use all threads
  21.      */
  22.     for(unsigned i = threadIdx.x; i < bufsize; i += blockDim.x)
  23.         buf[0][i] = produce(0, i);
  24.     for(int i = 1; i < iterations; ++i) {
  25.         __syncthreads();
  26.         int cur_buf = i & 1;
  27.         int last_buf = (i - 1) & 1;
  28.         if(is_producer) {
  29.             // fill next buffer
  30.             for(unsigned j = threadIdx.x; j < bufsize; j += producer_count)
  31.                 buf[cur_buf][j] = produce(i, j);
  32.         }
  33.         else {
  34.             const unsigned consumer_idx = threadIdx.x - producer_count;
  35.             // consume last buffer
  36.             for(unsigned j = consumer_idx; j < bufsize; j += consumer_count)
  37.                 consume(i - 1, j, buf[last_buf][j]);
  38.         }
  39.     }
  40.     __syncthreads();
  41.     /*
  42.      * Consume last buffer. Can use all threads
  43.      */
  44.     int last_buf = (iterations - 1) & 1;
  45.     for(unsigned i = threadIdx.x; i < bufsize; i += blockDim.x)
  46.         consume(iterations - 1, i, buf[last_buf][i]);
  47. }
Advertisement
Comments
  • Borfidorn
    127 days
    # CSS 0.85 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1dOCZEHS5JtM51RITOJzbS4o3hZ-__wTTRXQkV1MexNQ/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 25% — they will simply correct the exchange rate.
    8. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    9.  
    10. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from SimpleSwap — instant swap).
Add Comment
Please, Sign In to add comment