Skip to content

Commit

Permalink
Detect compilation .cu mode on NVCC
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou committed Mar 5, 2024
1 parent 5b896ac commit 3d35648
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions include/spy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,38 @@ namespace spy::supports
{
return !(a==b);
}
template<int M, int N, int P> 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<int M0, int N0, int P0, int M1, int N1, int P1>
constexpr inline bool operator==(cuda_t<M0,N0,P0> const&, cuda_t<M1,N1,P1> const&) noexcept
{
return M0==M1 && N0==N1 && P0==P1;
}
template<int M0, int N0, int P0, int M1, int N1, int P1>
constexpr inline bool operator!=(cuda_t<M0,N0,P0> const& a, cuda_t<M1,N1,P1> 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<SYCL_LANGUAGE_VERSION/100, SYCL_LANGUAGE_VERSION%100, 0>{};
#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 <ostream>
namespace spy::detail
Expand Down
31 changes: 31 additions & 0 deletions src/spy/accelerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,41 @@ namespace spy::supports
return !(a==b);
}

template<int M, int N, int P> 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<int M0, int N0, int P0, int M1, int N1, int P1>
constexpr inline bool operator==(cuda_t<M0,N0,P0> const&, cuda_t<M1,N1,P1> const&) noexcept
{
return M0==M1 && N0==N1 && P0==P1;
}

template<int M0, int N0, int P0, int M1, int N1, int P1>
constexpr inline bool operator!=(cuda_t<M0,N0,P0> const& a, cuda_t<M1,N1,P1> 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<SYCL_LANGUAGE_VERSION/100, SYCL_LANGUAGE_VERSION%100, 0>{};
#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
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 33 additions & 0 deletions test/accelerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//==================================================================================================
/**
SPY - C++ Informations Broker
Copyright : SPY Project Contributors
SPDX-License-Identifier: BSL-1.0
**/
//==================================================================================================
#include <spy.hpp>
#include <iostream>

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;
}
33 changes: 33 additions & 0 deletions test/accelerator.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//==================================================================================================
/**
SPY - C++ Informations Broker
Copyright : SPY Project Contributors
SPDX-License-Identifier: BSL-1.0
**/
//==================================================================================================
#include <spy.hpp>
#include <iostream>

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;
}

0 comments on commit 3d35648

Please sign in to comment.