mirror of
https://github.com/fumiama/base16384-sycl.git
synced 2026-06-23 22:10:24 +08:00
optimize: project structure
This commit is contained in:
4
.vscode/c_cpp_properties.json
vendored
4
.vscode/c_cpp_properties.json
vendored
@@ -20,7 +20,7 @@
|
|||||||
"-fsycl"
|
"-fsycl"
|
||||||
],
|
],
|
||||||
"cStandard": "c17",
|
"cStandard": "c17",
|
||||||
"cppStandard": "c++17",
|
"cppStandard": "c++20",
|
||||||
"intelliSenseMode": "windows-clang-x64",
|
"intelliSenseMode": "windows-clang-x64",
|
||||||
"configurationProvider": "ms-vscode.cmake-tools"
|
"configurationProvider": "ms-vscode.cmake-tools"
|
||||||
},
|
},
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"-fsycl"
|
"-fsycl"
|
||||||
],
|
],
|
||||||
"cStandard": "c17",
|
"cStandard": "c17",
|
||||||
"cppStandard": "c++17",
|
"cppStandard": "c++20",
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
"configurationProvider": "ms-vscode.cmake-tools"
|
"configurationProvider": "ms-vscode.cmake-tools"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,18 @@ endif()
|
|||||||
|
|
||||||
find_package(IntelSYCL REQUIRED)
|
find_package(IntelSYCL REQUIRED)
|
||||||
|
|
||||||
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
set(COMPILE_FLAGS "-fsycl -Wall ${WIN_FLAG}")
|
set(COMPILE_FLAGS "-fsycl -Wall ${WIN_FLAG}")
|
||||||
set(LINK_FLAGS "-fsycl")
|
set(LINK_FLAGS "-fsycl")
|
||||||
|
|
||||||
|
add_subdirectory(libs)
|
||||||
|
message(STATUS "Collected libs: ${B14LIBS}")
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
message(STATUS "Collected tests: ${B14TESTS}")
|
||||||
|
|
||||||
|
foreach(TARGET_NAME ${B14TESTS})
|
||||||
|
target_link_libraries(${TARGET_NAME} ${B14LIBS})
|
||||||
|
endforeach()
|
||||||
|
|||||||
16
include/errors.hpp
Normal file
16
include/errors.hpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef _ERRORS_HPP_
|
||||||
|
#define _ERRORS_HPP_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
errors_code_ok,
|
||||||
|
errors_code_sync_sycl_exception,
|
||||||
|
errors_code_std_exception,
|
||||||
|
errors_code_unknown_exception,
|
||||||
|
} errors_code_enum_t;
|
||||||
|
|
||||||
|
// failed try to exec fn, catch and print .what() when exception is thrown.
|
||||||
|
errors_code_enum_t failed(std::function<void(void)> fn);
|
||||||
|
|
||||||
|
#endif
|
||||||
17
libs/CMakeLists.txt
Normal file
17
libs/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
file(GLOB CPP_FILES "*.cpp")
|
||||||
|
|
||||||
|
set(LOCAL_B14LIBS "")
|
||||||
|
|
||||||
|
foreach(CPP_FILE ${CPP_FILES})
|
||||||
|
# name without .cpp
|
||||||
|
get_filename_component(TARGET_NAME ${CPP_FILE} NAME_WE)
|
||||||
|
message(STATUS "Add lib: ${TARGET_NAME}")
|
||||||
|
add_library(${TARGET_NAME} STATIC ${CPP_FILE})
|
||||||
|
|
||||||
|
set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS}")
|
||||||
|
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
|
||||||
|
|
||||||
|
list(APPEND LOCAL_B14LIBS ${TARGET_NAME})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(B14LIBS ${LOCAL_B14LIBS} PARENT_SCOPE)
|
||||||
29
libs/errors.cpp
Normal file
29
libs/errors.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "errors.hpp"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sycl/sycl.hpp>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept has_what_concept_t = requires(T t) { t.what(); };
|
||||||
|
|
||||||
|
template <has_what_concept_t T>
|
||||||
|
void print_what(T e, std::string msg) {
|
||||||
|
std::cerr << msg << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
errors_code_enum_t failed(std::function<void(void)> fn) {
|
||||||
|
try {
|
||||||
|
fn();
|
||||||
|
} catch (sycl::exception &e) {
|
||||||
|
print_what(e, "Caught sync SYCL exception: ");
|
||||||
|
return errors_code_sync_sycl_exception;
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
print_what(e, "Caught std exception: ");
|
||||||
|
return errors_code_std_exception;
|
||||||
|
} catch (...) {
|
||||||
|
std::cerr << "Caught unknown exception." << std::endl;
|
||||||
|
return errors_code_unknown_exception;
|
||||||
|
}
|
||||||
|
return errors_code_ok;
|
||||||
|
}
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
file(GLOB CPP_FILES "*.cpp")
|
file(GLOB CPP_FILES "*.cpp")
|
||||||
|
|
||||||
|
set(LOCAL_B14TESTS "")
|
||||||
|
|
||||||
foreach(CPP_FILE ${CPP_FILES})
|
foreach(CPP_FILE ${CPP_FILES})
|
||||||
# name without .cpp
|
# name without .cpp
|
||||||
get_filename_component(TARGET_NAME ${CPP_FILE} NAME_WE)
|
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})
|
add_executable(${TARGET_NAME} ${CPP_FILE})
|
||||||
|
|
||||||
set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS}")
|
set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS}")
|
||||||
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
|
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
|
||||||
|
|
||||||
add_test(NAME test_${TARGET_NAME} COMMAND ${TARGET_NAME})
|
add_test(NAME test_${TARGET_NAME} COMMAND ${TARGET_NAME})
|
||||||
|
list(APPEND LOCAL_B14TESTS ${TARGET_NAME})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
set(B14TESTS ${LOCAL_B14TESTS} PARENT_SCOPE)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "errors.hpp"
|
||||||
|
|
||||||
static const int N = 4;
|
static const int N = 4;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -29,23 +31,15 @@ int main() {
|
|||||||
int *data = sycl::malloc_shared<int>(N, q);
|
int *data = sycl::malloc_shared<int>(N, q);
|
||||||
for (int i = 0; i < N; i++) data[i] = i;
|
for (int i = 0; i < N; i++) data[i] = i;
|
||||||
|
|
||||||
try {
|
auto errn = failed([&]() {
|
||||||
q.single_task<class MyClass>([=]() {
|
q.parallel_for(sycl::range<1>(1), [=](sycl::id<1>) {
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
data[i] *= 2;
|
data[i] *= 2;
|
||||||
}
|
}
|
||||||
}).wait();
|
}).wait();
|
||||||
} catch (sycl::exception &e) {
|
});
|
||||||
// Do something to output or handle the exception
|
|
||||||
std::cout << "Caught sync SYCL exception: " << e.what() << "\n";
|
if (errn) return errn;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < N; i++) std::cout << data[i] << std::endl;
|
for (int i = 0; i < N; i++) std::cout << data[i] << std::endl;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user