Skip to content

Commit

Permalink
Fix bug #411: Drop occurrences of std:: namespace prefix without
Browse files Browse the repository at this point in the history
qualification by a `::` prefix (which potentially clashes with NVIDIA's standard library constructs)
  • Loading branch information
Eyal Rozenberg committed Oct 6, 2022
1 parent d2fa0f7 commit 77edfe3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/cuda/api/detail/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <optional>
#include <any>
namespace cuda {
using std::optional;
using std::nullopt;
using ::std::optional;
using ::std::nullopt;
} // namespace cuda
#elif __cplusplus >= 201402L
namespace cuda {
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/api/kernel_launch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void launch(
*
* @tparam SpanOfConstVoidPtrLike
* Type of the container for the marshalled arguments; typically, this
* would be `span<const void*>` - but it can be an `std::vector`, or
* would be `span<const void*>` - but it can be an `::std::vector`, or
* have non-const `void*` elements etc.
* @param stream
* Proxy for the stream on which to enqueue the kernel launch; may be the
Expand Down
10 changes: 5 additions & 5 deletions src/cuda/nvrtc/compilation_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,26 @@ struct compilation_options_t {
/**
* Extra options for the PTX compiler (a.k.a. "PTX optimizing assembler").
*/
std::string ptxas;
::std::string ptxas;

/**
* A sequence of directories to be searched for headers. These paths are searched _after_ the
* list of headers given to nvrtcCreateProgram.
*
* @note The members here are `std::string`'s rather than `const char*` or `std::string_view`'s,
* @note The members here are `::std::string`'s rather than `const char*` or `::std::string_view`'s,
* since this class is a value-type, and cannot rely someone else keeping these strings alive.
*
* @todo In C++17, consider making the elements `std::filesystem::path`'s.
* @todo In C++17, consider making the elements `::std::filesystem::path`'s.
*/
::std::vector<::std::string> additional_include_paths;

/**
* Header files to preinclude during preprocessing of the source.
*
* @note The members here are `std::string`'s rather than `const char*` or `std::string_view`'s,
* @note The members here are `::std::string`'s rather than `const char*` or `::std::string_view`'s,
* since this class is a value-type, and cannot rely someone else keeping these strings alive.
*
* @todo In C++17, consider making the elements `std::filesystem::path`'s.
* @todo In C++17, consider making the elements `::std::filesystem::path`'s.
*
* @todo Check how these strings are interpreted. Do they need quotation marks? brackets? full paths?
*/
Expand Down
6 changes: 3 additions & 3 deletions src/cuda/nvrtc/compilation_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ inline size_t get_cubin_size(program::handle_t program_handle, const char* progr
auto status = nvrtcGetCUBINSize(program_handle, &size);
throw_if_error(status, "Failed obtaining NVRTC program output CUBIN size");
if (size == 0) {
throw std::runtime_error("CUBIN requested for a program compiled for a virtual architecture only: "
+ identify(program_handle, program_name));
throw ::std::runtime_error("CUBIN requested for a program compiled for a virtual architecture only: "
+ identify(program_handle, program_name));
}
return size;
}
Expand All @@ -103,7 +103,7 @@ inline void get_cubin(char* buffer, program::handle_t program_handle, const char
{
auto status = nvrtcGetCUBIN(program_handle, buffer);
throw_if_error(status, "Failed obtaining NVRTC program output CUBIN for "
+ identify(program_handle, program_name));
+ identify(program_handle, program_name));
}

#endif // CUDA_VERSION >= 11010
Expand Down
28 changes: 14 additions & 14 deletions src/cuda/nvrtc/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,32 @@ class program_t {
template <typename String>
static inline void check_string_type()
{
using no_cref_string_type = typename std::remove_const<typename std::remove_reference<String>::type>::type;
using no_cref_string_type = typename ::std::remove_const<typename ::std::remove_reference<String>::type>::type;
static_assert(
std::is_same<no_cref_string_type, const char*>::value or
std::is_same<no_cref_string_type, char*>::value or
std::is_same<String, const std::string&>::value or
std::is_same<String, std::string&>::value,
::std::is_same<no_cref_string_type, const char*>::value or
::std::is_same<no_cref_string_type, char*>::value or
::std::is_same<String, const ::std::string&>::value or
::std::is_same<String, ::std::string&>::value,
"Cannot use this type for a named header name or source; use char*, const char* or a "
"reference to a string you own"
);
}

// Note: All methods involved in adding headers - which eventually call one of the
// three adders of each kind here - are written carefully to support both C-style strings
// and lvalue references to std::string's - but _not_ rvalue strings or rvalue string
// and lvalue references to ::std::string's - but _not_ rvalue strings or rvalue string
// references, as the latter are not owned by the caller, and this class' code does not
// make a copy or take ownership. If you make any changes, you must be very careful not
// to _copy_ anything by mistake, but rather carry forward reference-types all the way
// to here.

void add_header_name_ (const char* name) { headers_.names.emplace_back(name); }
void add_header_name_ (const std::string& name) { add_header_name_(name.c_str()); }
void add_header_name_ (std::string&& name) = delete;
void add_header_name_ (const char* name) { headers_.names.emplace_back(name); }
void add_header_name_ (const ::std::string& name) { add_header_name_(name.c_str()); }
void add_header_name_ (::std::string&& name) = delete;

void add_header_source_(const char* source) { headers_.sources.emplace_back(source); }
void add_header_source_(const std::string& source) { add_header_source_(source.c_str()); }
void add_header_source_(std::string&& source) = delete;
void add_header_source_(const char* source) { headers_.sources.emplace_back(source); }
void add_header_source_(const ::std::string& source) { add_header_source_(source.c_str()); }
void add_header_source_(::std::string&& source) = delete;

public: // mutators
template <typename String1, typename String2>
Expand All @@ -205,15 +205,15 @@ class program_t {
}

template <typename String1, typename String2>
program_t& add_header(const std::pair<String1, String2>& name_and_source)
program_t& add_header(const ::std::pair<String1, String2>& name_and_source)
{
add_header_name_(name_and_source.first);
add_header_source_(name_and_source.second);
return *this;
}

template <typename String1, typename String2>
program_t& add_header(std::pair<String1, String2>&& name_and_source)
program_t& add_header(::std::pair<String1, String2>&& name_and_source)
{
check_string_type<String1>();
check_string_type<String2>();
Expand Down

0 comments on commit 77edfe3

Please sign in to comment.