Skip to content

[SYCL][CUDA] Replace assert with CHECK #1302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions sycl/test/basic_tests/accessor/accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "../../helpers.hpp"
#include <CL/sycl.hpp>
#include <cassert>

namespace sycl {
using namespace cl::sycl;
Expand Down Expand Up @@ -77,19 +77,19 @@ int main() {
auto acc_src = buf_src.get_access<sycl::access::mode::read>();
auto acc_dst = buf_dst.get_access<sycl::access::mode::read_write>();

assert(!acc_src.is_placeholder());
assert(acc_src.get_size() == sizeof(src));
assert(acc_src.get_count() == 2);
assert(acc_src.get_range() == sycl::range<1>(2));
CHECK(!acc_src.is_placeholder());
CHECK(acc_src.get_size() == sizeof(src));
CHECK(acc_src.get_count() == 2);
CHECK(acc_src.get_range() == sycl::range<1>(2));

// Make sure that operator[] is defined for both size_t and id<1>.
// Implicit conversion from IdxSzT to size_t guarantees that no
// implicit conversion from size_t to id<1> will happen.
assert(acc_src[IdxSzT(0)] + acc_src[IdxID1(1)] == 10);
CHECK(acc_src[IdxSzT(0)] + acc_src[IdxID1(1)] == 10);

acc_dst[0] = acc_src[0] + acc_src[IdxID1(0)];
acc_dst[id1] = acc_src[1] + acc_src[IdxSzT(1)];
assert(dst[0] == 6 && dst[1] == 14);
CHECK(dst[0] == 6 && dst[1] == 14);
}

// Three-dimensional host accessor.
Expand All @@ -101,18 +101,18 @@ int main() {
sycl::buffer<int, 3> buf(data, sycl::range<3>(2, 3, 4));
auto acc = buf.get_access<sycl::access::mode::read_write>();

assert(!acc.is_placeholder());
assert(acc.get_size() == sizeof(data));
assert(acc.get_count() == 24);
assert(acc.get_range() == sycl::range<3>(2, 3, 4));
CHECK(!acc.is_placeholder());
CHECK(acc.get_size() == sizeof(data));
CHECK(acc.get_count() == 24);
CHECK(acc.get_range() == sycl::range<3>(2, 3, 4));

for (int i = 0; i < 2; ++i)
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 4; ++k)
acc[IdxID3(i, j, k)] += acc[sycl::id<3>(i, j, k)];
}
for (int i = 0; i < 24; ++i) {
assert(data[i] == 2 * i);
CHECK(data[i] == 2 * i);
}
}
int data = 5;
Expand All @@ -125,16 +125,16 @@ int main() {

Queue.submit([&](sycl::handler &cgh) {
auto acc = buf.get_access<sycl::access::mode::read_write>(cgh);
assert(!acc.is_placeholder());
assert(acc.get_size() == sizeof(int));
assert(acc.get_count() == 1);
assert(acc.get_range() == sycl::range<1>(1));
CHECK(!acc.is_placeholder());
CHECK(acc.get_size() == sizeof(int));
CHECK(acc.get_count() == 1);
CHECK(acc.get_range() == sycl::range<1>(1));
cgh.single_task<class kernel>(
[=]() { acc[IdxSzT(0)] += acc[IdxID1(0)]; });
});
Queue.wait();
}
assert(data == 10);
CHECK(data == 10);

// Device accessor with 2-dimensional subscript operators.
{
Expand All @@ -158,7 +158,7 @@ int main() {
for (int j = 0; j < 3; j++) {
std::cout << "array[" << i << "][" << j << "]=" << array[i][j]
<< std::endl;
assert(array[i][j] == i * 3 + j);
CHECK(array[i][j] == i * 3 + j);
}
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ int main() {
for (int k = 0; k < 4; k++) {
std::cout << "array[" << i << "][" << j << "][" << k
<< "]=" << array[i][j][k] << std::endl;
assert(array[i][j][k] == k + 4 * (j + 3 * i));
CHECK(array[i][j][k] == k + 4 * (j + 3 * i));
}
}
}
Expand All @@ -211,7 +211,7 @@ int main() {

auto host_acc = buf.get_access<sycl::access::mode::read>();
for (int i = 0; i != 3; ++i)
assert(host_acc[i] == 42);
CHECK(host_acc[i] == 42);

} catch (cl::sycl::exception e) {
std::cout << "SYCL exception caught: " << e.what();
Expand Down Expand Up @@ -262,7 +262,7 @@ int main() {
}
for (int i = 0; i < 10; i++) {
std::cout << "array[" << i << "]=" << array[i] << std::endl;
assert(array[i] == 333);
CHECK(array[i] == 333);
}
}
}
Expand Down Expand Up @@ -296,8 +296,8 @@ int main() {
for (int i = 0; i < 10; i++) {
std::cout << "array1[" << i << "]=" << array1[i] << std::endl;
std::cout << "array2[" << i << "]=" << array2[i] << std::endl;
assert(array1[i] == 333);
assert(array2[i] == 666);
CHECK(array1[i] == 333);
CHECK(array2[i] == 666);
}
}
}
Expand Down Expand Up @@ -326,7 +326,7 @@ int main() {
}
for (int i = 0; i < 10; i++) {
std::cout << "array[" << i << "]=" << array[i] << std::endl;
assert(array[i] == 333);
CHECK(array[i] == 333);
}
}
}
Expand Down Expand Up @@ -374,7 +374,7 @@ int main() {
});
});
}
assert(data == 399);
CHECK(data == 399);
} catch (sycl::exception e) {
std::cout << "SYCL exception caught: " << e.what();
return 1;
Expand Down Expand Up @@ -424,8 +424,8 @@ int main() {
sycl::access::target::host_buffer>
acc6(buf3, sycl::range<1>(1));

assert(acc4 == 2);
assert(acc5[0] == 4);
assert(acc6[0] == 6);
CHECK(acc4 == 2);
CHECK(acc5[0] == 4);
CHECK(acc6[0] == 6);
}
}
12 changes: 6 additions & 6 deletions sycl/test/basic_tests/buffer/buffer_full_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "../../helpers.hpp"
#include <CL/sycl.hpp>
#include <cassert>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <cassert>

Do we still need this include?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn’t be necessary - I will fix this on Monday.


Expand Down Expand Up @@ -50,9 +50,9 @@ void check_copy_device_to_host(cl::sycl::queue &Queue) {
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j)
if (offset <= i && i < offset + 2 && offset <= j && j < offset + 2) {
assert(acc[i][j] == 15);
CHECK(acc[i][j] == 15);
} else {
assert(acc[i][j] == 13);
CHECK(acc[i][j] == 13);
}
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ void check_fill(cl::sycl::queue &Queue) {
{
auto acc_1 = buf_1.get_access<cl::sycl::access::mode::read>();
for (int i = 0; i < size; ++i)
assert(expected_res_1[i] == acc_1[i]);
CHECK(expected_res_1[i] == acc_1[i]);
}
}

Expand Down Expand Up @@ -121,10 +121,10 @@ void check_copy_host_to_device(cl::sycl::queue &Queue) {

// check that there was no data corruption/loss
for (int i = 0; i < size; ++i)
assert(expected_res_1[i] == acc_1[i]);
CHECK(expected_res_1[i] == acc_1[i]);

for (int i = 0; i < size / 2; ++i)
assert(expected_res_2[i] == acc_2[i]);
CHECK(expected_res_2[i] == acc_2[i]);
}

cl::sycl::buffer<float, 2> buf_3({size, size});
Expand Down
14 changes: 7 additions & 7 deletions sycl/test/basic_tests/buffer/reinterpret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//
//===----------------------------------------------------------------------===//

#include "../../helpers.hpp"
#include <CL/sycl.hpp>

#include <climits>

// This tests verifies basic cases of using cl::sycl::buffer::reinterpret
Expand Down Expand Up @@ -130,7 +130,7 @@ int main() {
cl::sycl::id<1>{offset}, cl::sycl::range<1>{sub_buf_size}, val);

for (std::size_t i = 0; i < sub_buf_size + offset; ++i) {
assert(data[i] == expected_data[i] &&
CHECK(data[i] == expected_data[i] &&
"1D sub buffer int->char reinterpret failed");
}
}
Expand All @@ -153,7 +153,7 @@ int main() {
cl::sycl::id<1>{offset}, cl::sycl::range<1>{sub_buf_size}, val);

for (std::size_t i = 0; i < sub_buf_size + offset; ++i) {
assert(data[i] == expected_data[i] &&
CHECK(data[i] == expected_data[i] &&
"1D sub buffer char->int reinterpret failed");
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ int main() {

for (std::size_t i = 0; i < rows; ++i)
for (std::size_t j = 0; j < cols; ++j)
assert(data[i * cols + j] == expected_data[i * cols + j] &&
CHECK(data[i * cols + j] == expected_data[i * cols + j] &&
"2D->1D->sub buffer reinterpret failed");
}

Expand Down Expand Up @@ -227,7 +227,7 @@ int main() {

for (std::size_t i = 0; i < buf_row; ++i)
for (std::size_t j = 0; j < buf_col; ++j)
assert(data[i * buf_col + j] == expected_data[i * buf_col + j] &&
CHECK(data[i * buf_col + j] == expected_data[i * buf_col + j] &&
"2D sub buffer int->char reinterpret failed");
}

Expand All @@ -252,8 +252,8 @@ int main() {

for (std::size_t i = 0; i < buf_row; ++i)
for (std::size_t j = 0; j < buf_col; ++j)
assert(data[i * buf_col + j] == expected_data[i * buf_col + j] &&
"2D sub buffer int->char reinterpret failed");
CHECK(data[i * buf_col + j] == expected_data[i * buf_col + j] &&
"2D sub buffer int->char reinterpret failed");
}

return failed;
Expand Down
Loading