1
0
mirror of https://github.com/fumiama/base16384-sycl.git synced 2026-06-17 17:10:30 +08:00

optimize: project structure

This commit is contained in:
源文雨
2025-09-28 16:12:45 +08:00
parent 949438b794
commit ad1df2bb98
7 changed files with 87 additions and 16 deletions

View File

@@ -1,13 +1,18 @@
file(GLOB CPP_FILES "*.cpp")
set(LOCAL_B14TESTS "")
foreach(CPP_FILE ${CPP_FILES})
# name without .cpp
get_filename_component(TARGET_NAME ${CPP_FILE} NAME_WE)
message(STATUS "Add test ${TARGET_NAME}")
message(STATUS "Add test: ${TARGET_NAME}")
add_executable(${TARGET_NAME} ${CPP_FILE})
set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS}")
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
add_test(NAME test_${TARGET_NAME} COMMAND ${TARGET_NAME})
list(APPEND LOCAL_B14TESTS ${TARGET_NAME})
endforeach()
set(B14TESTS ${LOCAL_B14TESTS} PARENT_SCOPE)

View File

@@ -5,6 +5,8 @@
#include <windows.h>
#endif
#include "errors.hpp"
static const int N = 4;
int main() {
@@ -29,23 +31,15 @@ int main() {
int *data = sycl::malloc_shared<int>(N, q);
for (int i = 0; i < N; i++) data[i] = i;
try {
q.single_task<class MyClass>([=]() {
auto errn = failed([&]() {
q.parallel_for(sycl::range<1>(1), [=](sycl::id<1>) {
for (int i = 0; i < N; i++) {
data[i] *= 2;
}
}).wait();
} catch (sycl::exception &e) {
// Do something to output or handle the exception
std::cout << "Caught sync SYCL exception: " << e.what() << "\n";
return 1;
} catch (std::exception &e) {
std::cout << "Caught std exception: " << e.what() << "\n";
return 2;
} catch (...) {
std::cout << "Caught unknown exception\n";
return 3;
}
});
if (errn) return errn;
for (int i = 0; i < N; i++) std::cout << data[i] << std::endl;