Skip to content
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

Extend helper assert with generic comparison and print message on success #383

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 2 additions & 6 deletions Code_Exercises/Advanced_Data_Flow/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ void test_buffer() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 4.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 4.0f; });
}

void test_usm() {
Expand Down Expand Up @@ -118,9 +116,7 @@ void test_usm() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 4.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 4.0f; });
}

int main() {
Expand Down
4 changes: 1 addition & 3 deletions Code_Exercises/Advanced_Data_Flow/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,5 @@ int main() {
out[i] = tmp[i] / 2.0f;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 4.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 4.0f; });
}
24 changes: 6 additions & 18 deletions Code_Exercises/Asynchronous_Execution/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ void test_buffer_event_wait() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}

void test_buffer_queue_wait() {
Expand Down Expand Up @@ -98,9 +96,7 @@ void test_buffer_queue_wait() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}

void test_buffer_buffer_destruction() {
Expand Down Expand Up @@ -137,9 +133,7 @@ void test_buffer_buffer_destruction() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}

void test_usm_event_wait() {
Expand Down Expand Up @@ -189,9 +183,7 @@ void test_usm_event_wait() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}

void test_usm_queue_wait() {
Expand Down Expand Up @@ -239,9 +231,7 @@ void test_usm_queue_wait() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}

void test_buffer_host_accessor() {
Expand Down Expand Up @@ -277,9 +267,7 @@ void test_buffer_host_accessor() {
{
auto hostAccR = bufR.get_host_access(sycl::read_only); // Copy-to-host

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(hostAccR[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(hostAccR, [](size_t i) { return i * 2; });
}

} // Copy-back
Expand Down
4 changes: 2 additions & 2 deletions Code_Exercises/Asynchronous_Execution/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@

void test_usm() {
// Use your code from the "Data Parallelism" exercise to start
SYCLACADEMY_ASSERT(true);
SYCLACADEMY_ASSERT_EQUAL(/*output data*/ 0, /*expected data*/ 0);
}

void test_buffer() {
// Use your code from the "Data Parallelism" exercise to start
SYCLACADEMY_ASSERT(true);
SYCLACADEMY_ASSERT_EQUAL(/*output data*/ 0, /*expected data*/ 0);
}

int main() {
Expand Down
4 changes: 1 addition & 3 deletions Code_Exercises/Data_Parallelism/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,5 @@ int main() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == static_cast<float>(i) * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2.0f; });
}
4 changes: 1 addition & 3 deletions Code_Exercises/Data_Parallelism/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,5 @@ int main() {
r[i] = a[i] + b[i];
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == static_cast<float>(i) * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2.0f; });
}
8 changes: 2 additions & 6 deletions Code_Exercises/Data_and_Dependencies/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ void test_buffer() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 2.0f; });
}

void test_usm() {
Expand Down Expand Up @@ -156,9 +154,7 @@ void test_usm() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 2.0f; });
}

int main() {
Expand Down
4 changes: 1 addition & 3 deletions Code_Exercises/Data_and_Dependencies/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,5 @@ int main() {
out[i] = inB[i] + inC[i];
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 2.0f; });
}
2 changes: 1 addition & 1 deletion Code_Exercises/Device_Discovery/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ int main() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

SYCLACADEMY_ASSERT(r == 42);
SYCLACADEMY_ASSERT_EQUAL(r, 42);
}
2 changes: 1 addition & 1 deletion Code_Exercises/Device_Discovery/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ int main() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

SYCLACADEMY_ASSERT(r == 42);
SYCLACADEMY_ASSERT_EQUAL(r, 42);
}
8 changes: 2 additions & 6 deletions Code_Exercises/In_Order_Queue/solution_vector_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ void test_buffer() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 2.0f; });
}

void test_usm() {
Expand Down Expand Up @@ -160,9 +158,7 @@ void test_usm() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(out[i] == i * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(out, [](size_t i) { return i * 2.0f; });
}

int main() {
Expand Down
2 changes: 1 addition & 1 deletion Code_Exercises/In_Order_Queue/source_vector_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@

int main() {
// Use the "Data and Dependencies" exercise solution to start
SYCLACADEMY_ASSERT(true);
SYCLACADEMY_ASSERT_EQUAL(/*output data*/ 0, /*expected data*/ 0);
}
4 changes: 2 additions & 2 deletions Code_Exercises/Managing_Data/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void test_usm() {
sycl::free(dev_B, defaultQueue);
sycl::free(dev_R, defaultQueue);

SYCLACADEMY_ASSERT(r == 42);
SYCLACADEMY_ASSERT_EQUAL(r, 42);
}

void test_buffer() {
Expand All @@ -65,7 +65,7 @@ void test_buffer() {
.wait();
}

SYCLACADEMY_ASSERT(r == 42);
SYCLACADEMY_ASSERT_EQUAL(r, 42);
}

int main() {
Expand Down
4 changes: 2 additions & 2 deletions Code_Exercises/Managing_Data/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void test_usm() {
// Task: Compute a+b on the SYCL device using USM
r = a + b;

SYCLACADEMY_ASSERT(r == 42);
SYCLACADEMY_ASSERT_EQUAL(r, 42);
}

void test_buffer() {
Expand All @@ -63,7 +63,7 @@ void test_buffer() {
// accessor memory model
r = a + b;

SYCLACADEMY_ASSERT(r == 42);
SYCLACADEMY_ASSERT_EQUAL(r, 42);
}

int main() {
Expand Down
4 changes: 1 addition & 3 deletions Code_Exercises/Matrix_Transpose/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,5 @@ int main() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (auto i = 0; i < N * N; ++i) {
SYCLACADEMY_ASSERT(A_T[i] == A_T_comparison[i]);
}
SYCLACADEMY_ASSERT_EQUAL(A_T, A_T_comparison);
}
4 changes: 1 addition & 3 deletions Code_Exercises/Matrix_Transpose/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,5 @@ int main() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (auto i = 0; i < N * N; ++i) {
SYCLACADEMY_ASSERT(A_T[i] == A_T_comparison[i]);
}
SYCLACADEMY_ASSERT_EQUAL(A_T, A_T_comparison);
}
4 changes: 1 addition & 3 deletions Code_Exercises/Multiple_Devices/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,5 @@ int main() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == static_cast<float>(i) * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2.0f; });
}
4 changes: 1 addition & 3 deletions Code_Exercises/Multiple_Devices/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,5 @@ int main() {
r[dataSizeFirst + i] = a[dataSizeFirst + i] + b[dataSizeFirst + i];
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == static_cast<float>(i) * 2.0f);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2.0f; });
}
8 changes: 2 additions & 6 deletions Code_Exercises/ND_Range_Kernel/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ void test_item() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}

void test_nd_item() {
Expand Down Expand Up @@ -91,9 +89,7 @@ void test_nd_item() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}

int main() {
Expand Down
4 changes: 1 addition & 3 deletions Code_Exercises/ND_Range_Kernel/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,5 @@ int main() {
r[i] = a[i] + b[i];
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2; });
}
4 changes: 1 addition & 3 deletions Code_Exercises/Using_USM/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,5 @@ int main() {
std::cout << "Exception caught: " << e.what() << std::endl;
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2.0f; });
}
4 changes: 1 addition & 3 deletions Code_Exercises/Using_USM/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ int main() {
r[i] = a[i] + b[i];
}

for (int i = 0; i < dataSize; ++i) {
SYCLACADEMY_ASSERT(r[i] == i * 2);
}
SYCLACADEMY_ASSERT_EQUAL(r, [](size_t i) { return i * 2.0f; });
}
Loading
Loading