MCPcopy Create free account
hub / github.com/blender/cycles / oneapi_run_test_kernel

Function oneapi_run_test_kernel

src/kernel/device/oneapi/kernel.cpp:90–148  ·  view source on GitHub ↗

NOTE(@nsirgien): Execution of this simple kernel will check basic functionality like * memory allocations, memory transfers and execution of kernel with USM memory. */

Source from the content-addressed store, hash-verified

88/* NOTE(@nsirgien): Execution of this simple kernel will check basic functionality like
89 * memory allocations, memory transfers and execution of kernel with USM memory. */
90bool oneapi_run_test_kernel(SyclQueue *queue_)
91{
92 assert(queue_);
93 sycl::queue *queue = reinterpret_cast<sycl::queue *>(queue_);
94 const size_t N = 8;
95 const size_t memory_byte_size = sizeof(int) * N;
96
97 bool is_computation_correct = true;
98 try {
99 int *A_host = (int *)sycl::aligned_alloc_host(16, memory_byte_size, *queue);
100
101 for (size_t i = (size_t)0; i < N; i++) {
102 A_host[i] = rand() % 32;
103 }
104
105 int *A_device = (int *)sycl::malloc_device(memory_byte_size, *queue);
106 int *B_device = (int *)sycl::malloc_device(memory_byte_size, *queue);
107
108 queue->memcpy(A_device, A_host, memory_byte_size);
109 queue->wait_and_throw();
110
111 queue->submit([&](sycl::handler &cgh) {
112 cgh.parallel_for(N, [=](sycl::id<1> idx) { B_device[idx] = A_device[idx] + idx.get(0); });
113 });
114 queue->wait_and_throw();
115
116 int *B_host = (int *)sycl::aligned_alloc_host(16, memory_byte_size, *queue);
117
118 queue->memcpy(B_host, B_device, memory_byte_size);
119 queue->wait_and_throw();
120
121 for (size_t i = (size_t)0; i < N; i++) {
122 const int expected_result = i + A_host[i];
123 if (B_host[i] != expected_result) {
124 is_computation_correct = false;
125 if (s_error_cb) {
126 s_error_cb(("Incorrect result in test kernel execution - expected " +
127 std::to_string(expected_result) + ", got " + std::to_string(B_host[i]))
128 .c_str(),
129 s_error_user_ptr);
130 }
131 }
132 }
133
134 sycl::free(A_host, *queue);
135 sycl::free(B_host, *queue);
136 sycl::free(A_device, *queue);
137 sycl::free(B_device, *queue);
138 queue->wait_and_throw();
139 }
140 catch (const sycl::exception &e) {
141 if (s_error_cb) {
142 s_error_cb(e.what(), s_error_user_ptr);
143 }
144 return false;
145 }
146
147 return is_computation_correct;

Callers 1

load_kernelsMethod · 0.85

Calls 1

to_stringFunction · 0.85

Tested by

no test coverage detected