diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index a4fd184..f46a11c 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -133,6 +133,8 @@ jobs: - name: Compiling Unit Tests run: | mkdir build && cd build + nvcc ../test/accelerator.cu -std=c++17 -I../include -o accelerator.device.exe + nvcc ../test/accelerator.cpp -std=c++17 -I../include -o accelerator.host.exe nvcc ../test/arch.cpp -std=c++17 -I../include -o arch.exe nvcc ../test/compiler.cpp -std=c++17 -I../include -o compiler.exe nvcc ../test/data_model.cpp -std=c++17 -I../include -o data_model.exe @@ -143,7 +145,8 @@ jobs: - name: Running Unit Tests run: | cd build - ./arch.exe && ./compiler.exe && ./data_model.exe && ./libc.exe && ./os.exe && ./simd.exe && ./stdlib.exe + ./accelerator.device.exe && accelerator.host.exe && ./arch.exe && ./compiler.exe && ./data_model.exe && \ + ./libc.exe && ./os.exe && ./simd.exe && ./stdlib.exe ################################################################################################## ## DPC++ Target diff --git a/include/spy.hpp b/include/spy.hpp index 009ca9e..a25d11e 100644 --- a/include/spy.hpp +++ b/include/spy.hpp @@ -30,12 +30,38 @@ namespace spy::supports { return !(a==b); } + template struct cuda_t + { + explicit constexpr operator bool() const noexcept { return M>0 && N>0; } + friend std::ostream& operator<<(std::ostream& os, cuda_t) + { + os << "NVCC CUDA v" << M << '.' << N; + if(P>0) os << '.' << P; + return os; + } + }; + template + constexpr inline bool operator==(cuda_t const&, cuda_t const&) noexcept + { + return M0==M1 && N0==N1 && P0==P1; + } + template + constexpr inline bool operator!=(cuda_t const& a, cuda_t const& b) noexcept + { + return !(a==b); + } #if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER) # define SPY_ACCELERATOR_SUPPORTS_SYCL constexpr inline auto sycl = sycl_t{}; #else constexpr inline auto sycl = sycl_t<-1,-1,-1>{}; #endif +#if defined(__CUDACC__) +# define SPY_ACCELERATOR_SUPPORTS_CUDA + constexpr inline auto cuda = cuda_t<__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, 0>{}; +#else + constexpr inline auto cuda = cuda_t<-1,-1,-1>{}; +#endif } #include namespace spy::detail diff --git a/src/spy/accelerator.hpp b/src/spy/accelerator.hpp index f9f04f6..6eda210 100644 --- a/src/spy/accelerator.hpp +++ b/src/spy/accelerator.hpp @@ -34,10 +34,41 @@ namespace spy::supports return !(a==b); } + template struct cuda_t + { + explicit constexpr operator bool() const noexcept { return M>0 && N>0; } + + friend std::ostream& operator<<(std::ostream& os, cuda_t) + { + os << "NVCC CUDA v" << M << '.' << N; + if(P>0) os << '.' << P; + return os; + } + }; + + template + constexpr inline bool operator==(cuda_t const&, cuda_t const&) noexcept + { + return M0==M1 && N0==N1 && P0==P1; + } + + template + constexpr inline bool operator!=(cuda_t const& a, cuda_t const& b) noexcept + { + return !(a==b); + } + #if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER) # define SPY_ACCELERATOR_SUPPORTS_SYCL constexpr inline auto sycl = sycl_t{}; #else constexpr inline auto sycl = sycl_t<-1,-1,-1>{}; #endif + +#if defined(__CUDACC__) +# define SPY_ACCELERATOR_SUPPORTS_CUDA + constexpr inline auto cuda = cuda_t<__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, 0>{}; +#else + constexpr inline auto cuda = cuda_t<-1,-1,-1>{}; +#endif } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f3236d6..28520a4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -77,6 +77,7 @@ add_dependencies(unit spy.unit) ##================================================================================================== # All tests ##================================================================================================== +generate_test("spy" "accelerator.cpp") generate_test("spy" "arch.cpp") generate_test("spy" "compiler.cpp") generate_test("spy" "data_model.cpp") diff --git a/test/accelerator.cpp b/test/accelerator.cpp new file mode 100644 index 0000000..8cfbe07 --- /dev/null +++ b/test/accelerator.cpp @@ -0,0 +1,33 @@ +//================================================================================================== +/** + SPY - C++ Informations Broker + Copyright : SPY Project Contributors + SPDX-License-Identifier: BSL-1.0 +**/ +//================================================================================================== +#include +#include + +int main() +{ + std::cout << "Check that specified accelerator is supported: " << std::endl; + { + #if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER) + static_assert( spy::supports::sycl ); + std::cout << "Currently compiling with " << spy::supports::sycl << " enabled\n"; + #else + static_assert( !spy::supports::sycl ); + std::cout << "Currently compiling without SYCL enabled\n"; + #endif + } + { + #if defined(__NVCC__) && defined (__CUDACC__) + static_assert( spy::supports::cuda ); + std::cout << "Currently compiling with " << spy::supports::cuda << " enabled\n"; + #else + static_assert( !spy::supports::cuda ); + std::cout << "Currently compiling without CUDA enabled\n"; + #endif + } + std::cout << "Done." << std::endl; +} diff --git a/test/accelerator.cu b/test/accelerator.cu new file mode 100644 index 0000000..8cfbe07 --- /dev/null +++ b/test/accelerator.cu @@ -0,0 +1,33 @@ +//================================================================================================== +/** + SPY - C++ Informations Broker + Copyright : SPY Project Contributors + SPDX-License-Identifier: BSL-1.0 +**/ +//================================================================================================== +#include +#include + +int main() +{ + std::cout << "Check that specified accelerator is supported: " << std::endl; + { + #if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER) + static_assert( spy::supports::sycl ); + std::cout << "Currently compiling with " << spy::supports::sycl << " enabled\n"; + #else + static_assert( !spy::supports::sycl ); + std::cout << "Currently compiling without SYCL enabled\n"; + #endif + } + { + #if defined(__NVCC__) && defined (__CUDACC__) + static_assert( spy::supports::cuda ); + std::cout << "Currently compiling with " << spy::supports::cuda << " enabled\n"; + #else + static_assert( !spy::supports::cuda ); + std::cout << "Currently compiling without CUDA enabled\n"; + #endif + } + std::cout << "Done." << std::endl; +}