Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 2b21583

Browse files
v-klochkovkbobrovs
andauthored
[ESIMD] Fix several non-critical errors/warnings in LIT tests (#546)
* [ESIMD] Fix several non-critical errors/warnings in LIT tests 1. Added sycl::free() where needed 2. Replaced exception::get_cl_code() to avoid warnings. In about half of places the call was used incorrectly (returned non-zero value instead of zero/false); 3. Removed usages of "cl::" prefix; 4. Replaced some other deprecated APIs. Signed-off-by: Vyacheslav N Klochkov <[email protected]> Co-authored-by: kbobrovs <[email protected]>
1 parent a479325 commit 2b21583

34 files changed

+254
-276
lines changed

SYCL/ESIMD/accessor_gather_scatter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ template <typename T, unsigned VL, unsigned STRIDE> bool test(queue q) {
7070
cgh.parallel_for(glob_range, kernel);
7171
});
7272
e.wait();
73-
} catch (cl::sycl::exception const &e) {
73+
} catch (sycl::exception const &e) {
7474
std::cout << "SYCL exception caught: " << e.what() << '\n';
7575
delete[] A;
76-
return e.get_cl_code();
76+
return false; // not success
7777
}
7878

7979
int err_cnt = 0;

SYCL/ESIMD/accessor_load_store.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ template <typename T> bool test(queue q, size_t size) {
6262
Kernel<T> kernel(acc);
6363
cgh.parallel_for(glob_range, kernel);
6464
});
65-
} catch (cl::sycl::exception const &e) {
65+
} catch (sycl::exception const &e) {
6666
std::cout << "SYCL exception caught: " << e.what() << '\n';
6767
delete[] A;
68-
return e.get_cl_code();
68+
return false; // not success
6969
}
7070

7171
int err_cnt = 0;

SYCL/ESIMD/api/simd_binop_integer_promotion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ template <typename T> bool test(queue q) {
7474
});
7575
});
7676
q.wait_and_throw();
77-
} catch (cl::sycl::exception const &e) {
77+
} catch (sycl::exception const &e) {
7878
std::cout << "SYCL exception caught: " << e.what() << '\n';
79-
return e.get_cl_code();
79+
return false; // not success
8080
}
8181

8282
int err_cnt = 0;

SYCL/ESIMD/api/simd_memory_access.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ template <typename T, int N, bool IsAcc> bool test(queue q, size_t size) {
7979
std::cout << "Testing T=" << typeid(T).name() << ", N=" << N
8080
<< " using accessor=" << IsAcc << "...\n";
8181
T *A;
82-
if constexpr (IsAcc) {
82+
if constexpr (IsAcc)
8383
A = new T[size];
84-
} else {
85-
A = reinterpret_cast<T *>(sycl::malloc_shared(size, q));
86-
}
84+
else
85+
A = sycl::malloc_shared<T>(size, q);
8786

8887
for (unsigned i = 0; i < size; ++i) {
8988
A[i] = i; // should not be zero to test `copy_from` really works
@@ -108,10 +107,10 @@ template <typename T, int N, bool IsAcc> bool test(queue q, size_t size) {
108107
});
109108
}
110109
q.wait_and_throw();
111-
} catch (cl::sycl::exception const &e) {
110+
} catch (sycl::exception const &e) {
112111
std::cout << "SYCL exception caught: " << e.what() << '\n';
113112
free_mem<IsAcc>(A, q);
114-
return e.get_cl_code();
113+
return false; // not success
115114
}
116115

117116
int err_cnt = 0;

SYCL/ESIMD/api/simd_negation_operator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ bool test(queue q, const std::array<T, VL> &input,
5353
});
5454
});
5555
q.wait_and_throw();
56-
} catch (cl::sycl::exception const &e) {
56+
} catch (sycl::exception const &e) {
5757
std::cout << "SYCL exception caught: " << e.what() << '\n';
58-
return e.get_cl_code();
58+
return false; // not success
5959
}
6060

6161
int err_cnt = 0;

SYCL/ESIMD/api/simd_subscript_operator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ int main(int argc, char **argv) {
6767
});
6868
});
6969
q.wait_and_throw();
70-
} catch (cl::sycl::exception const &e) {
70+
} catch (sycl::exception const &e) {
7171
std::cout << "SYCL exception caught: " << e.what() << '\n';
72-
return e.get_cl_code();
72+
return 1;
7373
}
7474

7575
int err_cnt = 0;

SYCL/ESIMD/api/simd_view_copy_move_assign.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ template <class T> bool test(queue q, std::string str, T funcUnderTest) {
6363
});
6464
});
6565
q.wait_and_throw();
66-
} catch (cl::sycl::exception const &e) {
66+
} catch (sycl::exception const &e) {
6767
std::cout << "SYCL exception caught: " << e.what() << '\n';
68-
return e.get_cl_code();
68+
return false; // not success
6969
}
7070

7171
int err_cnt = 0;

SYCL/ESIMD/api/simd_view_negation_operator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ bool test(queue q, const std::array<T, VL> &input,
5454
});
5555
});
5656
q.wait_and_throw();
57-
} catch (cl::sycl::exception const &e) {
57+
} catch (sycl::exception const &e) {
5858
std::cout << "SYCL exception caught: " << e.what() << '\n';
59-
return e.get_cl_code();
59+
return false; // not success
6060
}
6161

6262
int err_cnt = 0;

SYCL/ESIMD/api/simd_view_subscript_operator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ int main(int argc, char **argv) {
6969
});
7070
});
7171
q.wait_and_throw();
72-
} catch (cl::sycl::exception const &e) {
72+
} catch (sycl::exception const &e) {
7373
std::cout << "SYCL exception caught: " << e.what() << '\n';
74-
return e.get_cl_code();
74+
return 1;
7575
}
7676

7777
int err_cnt = 0;

SYCL/ESIMD/api/slm_gather_scatter_rgba.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ template <typename T, unsigned VL, auto CH_MASK> struct Kernel {
5858
slm_scatter_rgba<T, VL, CH_MASK>(byteOffsets, valsIn);
5959

6060
// Load back values from SLM. They will be transposed back to SOA.
61-
simd<uint16_t, VL> pred = 1;
61+
simd_mask<VL> pred = 1;
6262
pred[VL - MASKED_LANE_NUM_REV] = 0; // mask out the last lane
6363
simd<T, VL *numChannels> valsOut =
6464
slm_gather_rgba<T, VL, CH_MASK>(byteOffsets, pred);

SYCL/ESIMD/esimd_test_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ inline auto createExceptionHandler() {
5656
for (auto ep : l) {
5757
try {
5858
std::rethrow_exception(ep);
59-
} catch (cl::sycl::exception &e0) {
59+
} catch (sycl::exception &e0) {
6060
std::cout << "sycl::exception: " << e0.what() << std::endl;
6161
} catch (std::exception &e) {
6262
std::cout << "std::exception: " << e.what() << std::endl;

SYCL/ESIMD/fp_args_size/Inputs/fp_args_size_common.hpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,16 @@ int main(void) {
4040

4141
auto dev = q.get_device();
4242
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
43-
auto ctx = q.get_context();
4443

45-
a_data_t *A = static_cast<a_data_t *>(
46-
sycl::malloc_shared(SIZE * sizeof(a_data_t), dev, ctx));
44+
a_data_t *A = sycl::malloc_shared<a_data_t>(SIZE, q);
4745
for (int i = 0; i < SIZE; i++)
4846
A[i] = (a_data_t)1;
4947

50-
b_data_t *B = static_cast<b_data_t *>(
51-
sycl::malloc_shared(SIZE * sizeof(b_data_t), dev, ctx));
48+
b_data_t *B = sycl::malloc_shared<b_data_t>(SIZE, q);
5249
for (int i = 0; i < SIZE; i++)
5350
B[i] = (b_data_t)i;
5451

55-
c_data_t *C = static_cast<c_data_t *>(
56-
sycl::malloc_shared(SIZE * sizeof(c_data_t), dev, ctx));
52+
c_data_t *C = sycl::malloc_shared<c_data_t>(SIZE, q);
5753
memset(C, 0, SIZE * sizeof(c_data_t));
5854

5955
try {
@@ -85,22 +81,22 @@ int main(void) {
8581
});
8682

8783
qq.wait();
88-
} catch (cl::sycl::exception const &e) {
84+
} catch (sycl::exception const &e) {
8985
std::cout << "SYCL exception caught: " << e.what() << std::endl;
90-
sycl::free(A, ctx);
91-
sycl::free(B, ctx);
92-
sycl::free(C, ctx);
93-
return e.get_cl_code();
86+
sycl::free(A, q);
87+
sycl::free(B, q);
88+
sycl::free(C, q);
89+
return 1;
9490
}
9591

9692
unsigned err_cnt = 0;
9793
for (int i = 0; i < SIZE; i++)
9894
if (C[i] != A[i] + B[i])
9995
err_cnt++;
10096

101-
sycl::free(A, ctx);
102-
sycl::free(B, ctx);
103-
sycl::free(C, ctx);
97+
sycl::free(A, q);
98+
sycl::free(B, q);
99+
sycl::free(C, q);
104100

105101
if (err_cnt > 0) {
106102
std::cout << "FAILED" << std::endl;

SYCL/ESIMD/histogram.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,16 @@ int main(int argc, char *argv[]) {
8383
property::queue::enable_profiling{});
8484

8585
auto dev = q.get_device();
86-
auto ctxt = q.get_context();
87-
unsigned char *srcY =
88-
static_cast<unsigned char *>(malloc_shared(width * height, dev, ctxt));
89-
unsigned int *bins = static_cast<unsigned int *>(
90-
malloc_shared(NUM_BINS * sizeof(unsigned int), dev, ctxt));
91-
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
92-
93-
uint range_width = width / BLOCK_WIDTH;
94-
uint range_height = height / BLOCK_HEIGHT;
95-
86+
unsigned char *srcY = malloc_shared<unsigned char>(width * height, q);
9687
if (srcY == NULL) {
9788
std::cerr << "Out of memory\n";
9889
exit(1);
9990
}
91+
unsigned int *bins = malloc_shared<unsigned int>(NUM_BINS, q);
92+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
93+
94+
uint range_width = width / BLOCK_WIDTH;
95+
uint range_height = height / BLOCK_HEIGHT;
10096

10197
// Initializes input.
10298
unsigned int input_size = width * height;
@@ -106,12 +102,16 @@ int main(int argc, char *argv[]) {
106102
FILE *f = fopen(input_file, "rb");
107103
if (f == NULL) {
108104
std::cerr << "Error opening file " << input_file;
105+
free(srcY, q);
106+
free(bins, q);
109107
std::exit(1);
110108
}
111109

112110
unsigned int cnt = fread(srcY, sizeof(unsigned char), input_size, f);
113111
if (cnt != input_size) {
114112
std::cerr << "Error reading input from " << input_file;
113+
free(srcY, q);
114+
free(bins, q);
115115
std::exit(1);
116116
}
117117
} else {
@@ -128,9 +128,9 @@ int main(int argc, char *argv[]) {
128128
memset(cpuHistogram, 0, sizeof(cpuHistogram));
129129
histogram_CPU(width, height, srcY, cpuHistogram);
130130

131-
cl::sycl::image<2> Img(srcY, image_channel_order::rgba,
132-
image_channel_type::unsigned_int32,
133-
range<2>{width / sizeof(uint4), height});
131+
sycl::image<2> Img(srcY, image_channel_order::rgba,
132+
image_channel_type::unsigned_int32,
133+
range<2>{width / sizeof(uint4), height});
134134

135135
// Start Timer
136136
esimd_test::Timer timer;
@@ -154,7 +154,7 @@ int main(int argc, char *argv[]) {
154154
nd_range<1> Range(GlobalRange, LocalRange);
155155

156156
auto e = q.submit([&](handler &cgh) {
157-
auto readAcc = Img.get_access<uint4, cl::sycl::access::mode::read>(cgh);
157+
auto readAcc = Img.get_access<uint4, access::mode::read>(cgh);
158158

159159
cgh.parallel_for<class Hist>(
160160
Range, [=](nd_item<1> ndi) SYCL_ESIMD_KERNEL {
@@ -204,8 +204,8 @@ int main(int argc, char *argv[]) {
204204
src = histogram.select<8, 1>(i);
205205

206206
#ifdef __SYCL_DEVICE_ONLY__
207-
flat_atomic<atomic_op::add, unsigned int, 8>(bins, offset, src,
208-
1);
207+
atomic_update<atomic_op::add, unsigned int, 8>(bins, offset,
208+
src, 1);
209209
offset += 8 * sizeof(unsigned int);
210210
#else
211211
simd<unsigned int, 8> vals;
@@ -226,8 +226,10 @@ int main(int argc, char *argv[]) {
226226
// SYCL will enqueue and run the kernel. Recall that the buffer's data is
227227
// given back to the host at the end of scope.
228228
// make sure data is given back to the host at the end of this scope
229-
} catch (cl::sycl::exception const &e) {
230-
std::cout << "SYCL exception caught: " << e.what() << '\n';
229+
} catch (sycl::exception const &e) {
230+
std::cerr << "SYCL exception caught: " << e.what() << '\n';
231+
free(srcY, q);
232+
free(bins, q);
231233
return 1;
232234
}
233235

@@ -240,13 +242,14 @@ int main(int argc, char *argv[]) {
240242
writeHist(bins);
241243
writeHist(cpuHistogram);
242244
// Checking Histogram
243-
if (checkHistogram(cpuHistogram, bins)) {
244-
std::cerr << "PASSED\n";
245-
return 0;
246-
} else {
245+
bool Success = checkHistogram(cpuHistogram, bins);
246+
free(srcY, q);
247+
free(bins, q);
248+
249+
if (!Success) {
247250
std::cerr << "FAILED\n";
248251
return 1;
249252
}
250-
253+
std::cout << "PASSED\n";
251254
return 0;
252255
}

0 commit comments

Comments
 (0)