test cuda: add more comment / macro check
* checks both `__NVCC__` and `__CUDACC__` More comments for CMake and CUDA source file.
This commit is contained in:
parent
ba82f542d6
commit
be279261ff
@ -10,20 +10,26 @@
|
|||||||
# And we can't sure most of the CUDA projects are using those latest
|
# And we can't sure most of the CUDA projects are using those latest
|
||||||
# because the latest C++ standard for NVCC is C++ 14 at this moment.
|
# because the latest C++ standard for NVCC is C++ 14 at this moment.
|
||||||
#
|
#
|
||||||
# In conclusion, this test will use older version of CMake,
|
# In conclusion,
|
||||||
# and rely on 'find_package(CUDA)'. For its version, do follow the Root CMakeLists.txt.
|
# this test should follow the version of the Root CMakeLists.txt
|
||||||
|
# and rely on 'find_package(CUDA)'.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# This part is for future update
|
||||||
#
|
#
|
||||||
# cmake_minimum_required(VERSION 3.10)
|
# cmake_minimum_required(VERSION 3.10)
|
||||||
# project(fmt-cuda-test LANGUAGES CXX CUDA) # see 'enable_language(CUDA)'
|
# project(fmt-cuda-test LANGUAGES CXX CUDA) # see 'enable_language(CUDA)'
|
||||||
cmake_minimum_required(VERSION 3.1) # for C++ 14
|
#
|
||||||
|
|
||||||
|
# Follow the Root CMakeLists.txt
|
||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
project(fmt-cuda-test LANGUAGES CXX)
|
project(fmt-cuda-test LANGUAGES CXX)
|
||||||
|
|
||||||
# find from ${PROJECT_BINARY_DIR}
|
# See 'test/CMakeLists.txt'. It's using ${PROJECT_BINARY_DIR}
|
||||||
find_package(FMT REQUIRED)
|
find_package(FMT REQUIRED)
|
||||||
|
|
||||||
# The environment variables(CUDA_BIN_PATH & CUDA_PATH) must be specified at this point
|
# The environment variables (CUDA_BIN_PATH & CUDA_PATH) must be specified
|
||||||
find_package(CUDA REQUIRED)
|
find_package(CUDA REQUIRED)
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -44,12 +50,12 @@ endif()
|
|||||||
|
|
||||||
#
|
#
|
||||||
# In this test, we will assume that
|
# In this test, we will assume that
|
||||||
# the user is going to pre-compile CUDA source codes
|
# the user is going to compile CUDA source codes with some libraries.
|
||||||
# with some libraries (including this 'fmt').
|
# Of course, it's 'fmt' in this case.
|
||||||
#
|
#
|
||||||
# In addition to that,
|
# In addition to that,
|
||||||
# this test will invoke both C++ Host compiler and NVCC
|
# this test will invoke both C++ Host compiler and NVCC by providing
|
||||||
# by providing another (non-CUDA) C++ source code
|
# another (non-CUDA) C++ source code
|
||||||
#
|
#
|
||||||
cuda_add_executable(fmt-in-cuda-test
|
cuda_add_executable(fmt-in-cuda-test
|
||||||
cuda-cpp14.cu
|
cuda-cpp14.cu
|
||||||
@ -62,12 +68,11 @@ cuda_add_executable(fmt-in-cuda-test
|
|||||||
set_target_properties(fmt-in-cuda-test
|
set_target_properties(fmt-in-cuda-test
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
CXX_STANDARD 14 # Notice this is for C++ code
|
CXX_STANDARD 14 # Notice this is for C++ code
|
||||||
POSITION_INDEPENDENT_CODE ON
|
|
||||||
)
|
)
|
||||||
# target_compile_features(fmt-in-cuda-test
|
target_compile_features(fmt-in-cuda-test
|
||||||
# PRIVATE
|
PRIVATE
|
||||||
# cxx_std_14 # just make sure of the property is available
|
cxx_std_14 # just make sure of the property
|
||||||
# )
|
)
|
||||||
|
|
||||||
get_target_property(cuda_standard
|
get_target_property(cuda_standard
|
||||||
fmt-in-cuda-test CUDA_STANDARD
|
fmt-in-cuda-test CUDA_STANDARD
|
||||||
@ -91,10 +96,13 @@ target_link_libraries(fmt-in-cuda-test
|
|||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
#
|
#
|
||||||
# MSVC places incorrect '__cplusplus' macro. Follow the guideline.
|
# This part is for (non-CUDA) C++ code.
|
||||||
|
# MSVC can define incorrect '__cplusplus' macro.
|
||||||
|
# Fix for the issue is to use additional compiler flag.
|
||||||
#
|
#
|
||||||
# https://github.com/Microsoft/vscode-cpptools/issues/2595
|
# See Also:
|
||||||
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||||
|
# https://github.com/Microsoft/vscode-cpptools/issues/2595
|
||||||
#
|
#
|
||||||
target_compile_options(fmt-in-cuda-test
|
target_compile_options(fmt-in-cuda-test
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
static_assert(__cplusplus >= 201402L, "expect C++ 2014");
|
//
|
||||||
|
// The purpose of this part is to ensure NVCC's host compiler also supports
|
||||||
|
// the standard version. See 'cuda-cpp14.cu'.
|
||||||
|
//
|
||||||
|
// https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros
|
||||||
|
//
|
||||||
|
static_assert(__cplusplus >= 201402L, "expect C++ 2014 for host compiler");
|
||||||
|
|
||||||
auto make_message_cpp() -> std::string{
|
auto make_message_cpp() -> std::string {
|
||||||
return fmt::format("host compiler\t: __cplusplus == {}", __cplusplus);
|
return fmt::format("host compiler \t: __cplusplus == {}", __cplusplus);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,31 @@
|
|||||||
|
|
||||||
//
|
//
|
||||||
// nvcc -x cu -std=c++14 ..\test\cuda-test\include_test.cu -I"../include" -Xcompiler /Zc:__cplusplus -l"fmtd" -L"../build/Debug"
|
// Direct NVCC command line example:
|
||||||
|
//
|
||||||
|
// nvcc.exe ./cuda-cpp14.cu -x cu -I"../include" -l"fmtd" -L"../build/Debug" \
|
||||||
|
// -std=c++14 -Xcompiler /std:c++14 -Xcompiler /Zc:__cplusplus
|
||||||
//
|
//
|
||||||
|
|
||||||
//
|
//
|
||||||
// Ensure that we are using the expected standard
|
// Ensure that we are using the latest C++ standard for NVCC
|
||||||
|
// The version is C++14
|
||||||
|
//
|
||||||
|
// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#c-cplusplus-language-support
|
||||||
// https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros
|
// https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros
|
||||||
//
|
//
|
||||||
static_assert(__cplusplus >= 201402L, "expect C++ 2014 for nvcc");
|
static_assert(__cplusplus >= 201402L, "expect C++ 2014 for nvcc");
|
||||||
|
|
||||||
#if defined(__CUDACC__)
|
//
|
||||||
# define FMT_DEPRECATED
|
// https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-identification-macro
|
||||||
|
//
|
||||||
|
// __NVCC__ is for NVCC compiler
|
||||||
|
// __CUDACC__ is for CUDA(.cu) source code
|
||||||
|
//
|
||||||
|
// Since we don't know the actual case in this header, checking both macro
|
||||||
|
// will prevent possible pitfalls ...
|
||||||
|
//
|
||||||
|
#if defined(__NVCC__) || defined(__CUDACC__)
|
||||||
|
# define FMT_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
@ -22,11 +37,11 @@ using namespace std;
|
|||||||
extern auto make_message_cpp() -> std::string;
|
extern auto make_message_cpp() -> std::string;
|
||||||
extern auto make_message_cuda() -> std::string;
|
extern auto make_message_cuda() -> std::string;
|
||||||
|
|
||||||
int main(int, char*[]){
|
int main(int, char*[]) {
|
||||||
cout << make_message_cuda() << endl;
|
cout << make_message_cuda() << endl;
|
||||||
cout << make_message_cpp() << endl;
|
cout << make_message_cpp() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto make_message_cuda() -> std::string{
|
auto make_message_cuda() -> std::string {
|
||||||
return fmt::format("nvcc \t: __cplusplus == {}", __cplusplus);
|
return fmt::format("nvcc compiler \t: __cplusplus == {}", __cplusplus);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user