fineg74 1611a23a5b
[OFFLOAD] Add spirv implementation for named barrier (#180393)
This change adds implementation for named barriers for SPIRV backend.
Since there is no built in API/intrinsics for named barrier in SPIRV,
the implementation loosely follows implementation for AMD
2026-03-27 20:14:09 +01:00

41 lines
877 B
C++

// RUN: %libomptarget-compilexx-and-run-generic
// RUN: %libomptarget-compileoptxx-and-run-generic
#include <cassert>
#include <iostream>
#include <stdexcept>
int main(int argc, char *argv[]) {
int a = 0;
std::cout << "outside a = " << a << " addr " << &a << std::endl;
#pragma omp target map(tofrom : a) depend(out : a) nowait
{
int sum = 0;
for (int i = 0; i < 100000; i++)
sum++;
a = 1;
}
#pragma omp task depend(inout : a) shared(a)
{
std::cout << "a = " << a << " addr " << &a << std::endl;
if (a != 1)
throw std::runtime_error("wrong result!");
a = 2;
}
#pragma omp task depend(inout : a) shared(a)
{
std::cout << "a = " << a << " addr " << &a << std::endl;
if (a != 2)
throw std::runtime_error("wrong result!");
a = 3;
}
#pragma omp taskwait
assert(a == 3 && "wrong result!");
return 0;
}