This patch adds: - a new kernel `void single_counter(int32_t init_loop, int32_t addend, uint32_t *init_val, uint32_t *out)` - a new test suite `olLaunchKernelSingleCounterSyncEventTest`, with two tests The test `SuccessSyncEvent` verifies whether `olSyncEvent(Event)` awaits the completion of `Event`. The test `SuccessTwoQueues` checks the correctness of the synchronization between queues using events. Enqueueing the kernel on the queue `Q1` should produce `Result1`, which is used as an initial value for the queue `Q2`. Therefore, before executing any future work, `Q2` should wait for the event `Event1`, which is created after submitting work on `Q1`. The required synchronization is ensured by `olWaitEvents(Q2, &Event1, 1)`. If `Q2` uses the value passed as `Result1` before the work on `Q1` has completed, the result of the kernel enqueued on `Q2` would be incorrect.
24 lines
573 B
C++
24 lines
573 B
C++
#include <gpuintrin.h>
|
|
#include <stdint.h>
|
|
|
|
extern "C" __gpu_kernel void single_counter(int32_t init_loop, int32_t addend,
|
|
uint32_t *init_val, uint32_t *out) {
|
|
|
|
if (__gpu_thread_id(0) != 0) {
|
|
return;
|
|
}
|
|
|
|
volatile int32_t counter = init_loop;
|
|
|
|
// We save the value at the beginning of the function in order to verify later
|
|
// whether the previously submitted kernel has finished before the new
|
|
// enqueue.
|
|
uint32_t local_sum = *init_val;
|
|
|
|
while (counter--) {
|
|
local_sum += addend;
|
|
}
|
|
|
|
*out = local_sum;
|
|
}
|