Remove ban on using string_cast with CUDA host code #1041
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
string_cast.hpp merely detects whether the current compiler is NVCC (originally based on
if defined(__CUDACC__)
in glm/simd/platform.h) and throws an error if it is. This means string_cast.hpp cannot be included in any header which might ever be used in a CUDA project.Of course,
glm::to_string
can't be used in device (GPU) code. However, the current approach to stop this is both incorrect and unnecessary.__CUDACC__
will be defined in both host and device code compilation, andglm::to_string
can obviously be used in host code. The correct define is__CUDA_ARCH__
(will be defined only if compiling device code). However, there's no problem ifglm::to_string
is defined (the header is included) while compiling device code, as long as it's not actually used in the device code. So, throwing an error if__CUDA_ARCH__
is defined would still prevent string_cast.hpp from being included in CUDA projects.There's actually no need for any manual check to see if
glm::to_string
is being used in device code, because the compiler will already check for that. It returns a std::string, which itself can't be used in device code, so it's unlikely a developer would try. And if they did, there would be errors that bothglm::to_string
and all the needed std::string constructors, stream operators, etc. are host-only functions.