-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][Test] Unify the code in AOT tests
All SYCL code is thus moved into a separate file, which is shared by config-specific RUN lines of the original LIT files. Signed-off-by: Artem Gindinson <artem.gindinson@intel.com>
- Loading branch information
1 parent
358ae27
commit c1bf3b4
Showing
6 changed files
with
74 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <CL/sycl.hpp> | ||
|
||
#include <array> | ||
#include <iostream> | ||
|
||
constexpr cl::sycl::access::mode sycl_read = cl::sycl::access::mode::read; | ||
constexpr cl::sycl::access::mode sycl_write = cl::sycl::access::mode::write; | ||
|
||
template <typename T> | ||
class SimpleVadd; | ||
|
||
template <typename T, size_t N> | ||
void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB, | ||
std::array<T, N> &VC) { | ||
cl::sycl::queue deviceQueue([](cl::sycl::exception_list ExceptionList) { | ||
for (cl::sycl::exception_ptr_class ExceptionPtr : ExceptionList) { | ||
try { | ||
std::rethrow_exception(ExceptionPtr); | ||
} catch (cl::sycl::exception &E) { | ||
std::cerr << E.what(); | ||
} catch (...) { | ||
std::cerr << "Unknown async exception was caught." << std::endl; | ||
} | ||
} | ||
}); | ||
|
||
cl::sycl::range<1> numOfItems{N}; | ||
cl::sycl::buffer<T, 1> bufferA(VA.data(), numOfItems); | ||
cl::sycl::buffer<T, 1> bufferB(VB.data(), numOfItems); | ||
cl::sycl::buffer<T, 1> bufferC(VC.data(), numOfItems); | ||
|
||
deviceQueue.submit([&](cl::sycl::handler &cgh) { | ||
auto accessorA = bufferA.template get_access<sycl_read>(cgh); | ||
auto accessorB = bufferB.template get_access<sycl_read>(cgh); | ||
auto accessorC = bufferC.template get_access<sycl_write>(cgh); | ||
|
||
cgh.parallel_for<class SimpleVadd<T>>(numOfItems, | ||
[=](cl::sycl::id<1> wiID) { | ||
accessorC[wiID] = accessorA[wiID] + accessorB[wiID]; | ||
}); | ||
}); | ||
|
||
deviceQueue.wait_and_throw(); | ||
} | ||
|
||
int main() { | ||
const size_t array_size = 4; | ||
std::array<cl::sycl::cl_int, array_size> A = {{1, 2, 3, 4}}, | ||
B = {{1, 2, 3, 4}}, C; | ||
std::array<cl::sycl::cl_float, array_size> D = {{1.f, 2.f, 3.f, 4.f}}, | ||
E = {{1.f, 2.f, 3.f, 4.f}}, F; | ||
simple_vadd(A, B, C); | ||
simple_vadd(D, E, F); | ||
for (unsigned int i = 0; i < array_size; i++) { | ||
if (C[i] != A[i] + B[i]) { | ||
std::cout << "The results are incorrect (element " << i << " is " << C[i] | ||
<< "!\n"; | ||
return 1; | ||
} | ||
if (F[i] != D[i] + E[i]) { | ||
std::cout << "The results are incorrect (element " << i << " is " << F[i] | ||
<< "!\n"; | ||
return 1; | ||
} | ||
} | ||
std::cout << "The results are correct!\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.