Skip to content

Commit b3be72a

Browse files
authored
Remove catch2 dependency and add clang format (#367)
* Remove catch2 dependency * Add clang format file * Use SYCLACADEMY_ASSERT macro defined in header Match the assert() impl without NDEBUG.
1 parent da26c98 commit b3be72a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+711
-678
lines changed

.clang-format

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Language: Cpp
2+
BasedOnStyle: LLVM
3+
AccessModifierOffset: -1
4+
BreakInheritanceList: BeforeComma
5+
BreakConstructorInitializers: BeforeComma
6+
Cpp11BracedListStyle: false
7+
PointerAlignment: Left
8+
SpaceBeforeCpp11BracedList: true

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ endif()
110110
# Exercises
111111

112112
enable_testing()
113-
add_subdirectory(External/Catch2)
114113
add_subdirectory(Code_Exercises)
115114

116115
# Create the Image directory

Code_Exercises/Advanced_Data_Flow/solution.cpp

+29-27
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
99
*/
1010

11-
//#define SYCL_ACADEMY_USING_COMPUTECPP
12-
13-
#define CATCH_CONFIG_MAIN
14-
#include <catch2/catch.hpp>
15-
11+
#include "../helpers.hpp"
1612
#include <sycl/sycl.hpp>
1713

1814
class kernel_a_1;
@@ -22,13 +18,14 @@ class kernel_b_2;
2218

2319
int usm_selector(const sycl::device& dev) {
2420
if (dev.has(sycl::aspect::usm_device_allocations)) {
25-
if (dev.has(sycl::aspect::gpu)) return 2;
21+
if (dev.has(sycl::aspect::gpu))
22+
return 2;
2623
return 1;
2724
}
2825
return -1;
2926
}
3027

31-
TEST_CASE("buffer_accessor_temporary_data", "temporary_data_solution") {
28+
void test_buffer() {
3229
constexpr size_t dataSize = 1024;
3330

3431
float in[dataSize], out[dataSize];
@@ -38,31 +35,31 @@ TEST_CASE("buffer_accessor_temporary_data", "temporary_data_solution") {
3835
}
3936

4037
try {
41-
auto gpuQueue = sycl::queue{sycl::gpu_selector_v};
38+
auto gpuQueue = sycl::queue { sycl::gpu_selector_v };
4239

43-
auto bufIn = sycl::buffer{in, sycl::range{dataSize}};
44-
auto bufInt = sycl::buffer<float>{sycl::range{dataSize}};
45-
auto bufOut = sycl::buffer<float>{sycl::range{dataSize}};
40+
auto bufIn = sycl::buffer { in, sycl::range { dataSize } };
41+
auto bufInt = sycl::buffer<float> { sycl::range { dataSize } };
42+
auto bufOut = sycl::buffer<float> { sycl::range { dataSize } };
4643

4744
bufIn.set_final_data(nullptr);
4845
bufOut.set_final_data(out);
4946

5047
gpuQueue.submit([&](sycl::handler& cgh) {
51-
sycl::accessor accIn{bufIn, cgh, sycl::read_only};
52-
sycl::accessor accOut{bufInt, cgh, sycl::write_only};
48+
sycl::accessor accIn { bufIn, cgh, sycl::read_only };
49+
sycl::accessor accOut { bufInt, cgh, sycl::write_only };
5350

54-
cgh.parallel_for<kernel_a_1>(sycl::range{dataSize}, [=](sycl::id<1> idx) {
55-
accOut[idx] = accIn[idx] * 8.0f;
56-
});
51+
cgh.parallel_for<kernel_a_1>(
52+
sycl::range { dataSize },
53+
[=](sycl::id<1> idx) { accOut[idx] = accIn[idx] * 8.0f; });
5754
});
5855

5956
gpuQueue.submit([&](sycl::handler& cgh) {
60-
sycl::accessor accIn{bufInt, cgh, sycl::read_only};
61-
sycl::accessor accOut{bufOut, cgh, sycl::write_only};
57+
sycl::accessor accIn { bufInt, cgh, sycl::read_only };
58+
sycl::accessor accOut { bufOut, cgh, sycl::write_only };
6259

63-
cgh.parallel_for<kernel_b_1>(sycl::range{dataSize}, [=](sycl::id<1> idx) {
64-
accOut[idx] = accIn[idx] / 2.0f;
65-
});
60+
cgh.parallel_for<kernel_b_1>(
61+
sycl::range { dataSize },
62+
[=](sycl::id<1> idx) { accOut[idx] = accIn[idx] / 2.0f; });
6663
});
6764

6865
gpuQueue.wait_and_throw();
@@ -71,11 +68,11 @@ TEST_CASE("buffer_accessor_temporary_data", "temporary_data_solution") {
7168
}
7269

7370
for (int i = 0; i < dataSize; ++i) {
74-
REQUIRE(out[i] == i * 4.0f);
71+
SYCLACADEMY_ASSERT(out[i] == i * 4.0f);
7572
}
7673
}
7774

78-
TEST_CASE("usm_temporary_data", "temporary_data_solution") {
75+
void test_usm() {
7976
constexpr size_t dataSize = 1024;
8077

8178
float in[dataSize], out[dataSize];
@@ -85,7 +82,7 @@ TEST_CASE("usm_temporary_data", "temporary_data_solution") {
8582
}
8683

8784
try {
88-
auto usmQueue = sycl::queue{usm_selector};
85+
auto usmQueue = sycl::queue { usm_selector };
8986

9087
auto devicePtrIn = sycl::malloc_device<float>(dataSize, usmQueue);
9188
auto devicePtrInt = sycl::malloc_device<float>(dataSize, usmQueue);
@@ -94,13 +91,13 @@ TEST_CASE("usm_temporary_data", "temporary_data_solution") {
9491
auto e1 = usmQueue.memcpy(devicePtrIn, in, sizeof(float) * dataSize);
9592

9693
auto e2 = usmQueue.parallel_for<kernel_a_2>(
97-
sycl::range{dataSize}, e1, [=](sycl::id<1> idx) {
94+
sycl::range { dataSize }, e1, [=](sycl::id<1> idx) {
9895
auto globalId = idx[0];
9996
devicePtrInt[globalId] = devicePtrIn[globalId] * 8.0f;
10097
});
10198

10299
auto e3 = usmQueue.parallel_for<kernel_b_2>(
103-
sycl::range{dataSize}, e2, [=](sycl::id<1> idx) {
100+
sycl::range { dataSize }, e2, [=](sycl::id<1> idx) {
104101
auto globalId = idx[0];
105102
devicePtrOut[globalId] = devicePtrInt[globalId] / 2.0f;
106103
});
@@ -122,6 +119,11 @@ TEST_CASE("usm_temporary_data", "temporary_data_solution") {
122119
}
123120

124121
for (int i = 0; i < dataSize; ++i) {
125-
REQUIRE(out[i] == i * 4.0f);
122+
SYCLACADEMY_ASSERT(out[i] == i * 4.0f);
126123
}
127124
}
125+
126+
int main() {
127+
test_usm();
128+
test_buffer();
129+
}

Code_Exercises/Advanced_Data_Flow/source.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@
4141
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only};
4242
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init};
4343
* // 2. Enqueue a parallel for:
44-
* cgh.parallel_for<class mykernel>(sycl::range{n}, [=](sycl::id<1> i) {
44+
* cgh.parallel_for<class mykernel>(sycl::range{n}, [=](sycl::id<1> i)
45+
{
4546
* // Do something
4647
* });
4748
*
4849
*/
4950

50-
#define CATCH_CONFIG_MAIN
51-
#include <catch2/catch.hpp>
51+
#include "../helpers.hpp"
5252

53-
TEST_CASE("temporary_data", "temporary_data_source") {
53+
int main() {
5454
constexpr size_t dataSize = 1024;
5555

5656
float in[dataSize], out[dataSize], tmp[dataSize];
@@ -60,20 +60,20 @@ TEST_CASE("temporary_data", "temporary_data_source") {
6060
out[i] = 0.0f;
6161
}
6262

63-
// Task: run these kernels on a SYCL device, minimising the memory transfers between the host and device
63+
// Task: run these kernels on a SYCL device, minimising the memory transfers
64+
// between the host and device
6465

6566
// Kernel A
6667
for (int i = 0; i < dataSize; ++i) {
6768
tmp[i] = in[i] * 8.0f;
6869
}
6970

70-
7171
// Kernel B
7272
for (int i = 0; i < dataSize; ++i) {
7373
out[i] = tmp[i] / 2.0f;
7474
}
7575

7676
for (int i = 0; i < dataSize; ++i) {
77-
REQUIRE(out[i] == i * 4.0f);
77+
SYCLACADEMY_ASSERT(out[i] == i * 4.0f);
7878
}
7979
}

0 commit comments

Comments
 (0)