@@ -71,6 +71,38 @@ inline void register_global(handle_t<cuda_cpp> program_handle, const char *globa
7171 + " with " + identify<cuda_cpp>(program_handle));
7272}
7373
74+ inline ::std::string get_concatenated_options (const const_cstrings_span& raw_options)
75+ {
76+ static ::std::ostringstream oss;
77+ oss.str (" " );
78+ for (const auto option: raw_options) {
79+ oss << " \" " << option << ' \" ' ;
80+ }
81+ return oss.str ();
82+ }
83+
84+ template <source_kind_t Kind>
85+ inline void maybe_handle_invalid_option (
86+ status_t <Kind>,
87+ const char *,
88+ const const_cstrings_span&,
89+ handle_t <Kind>)
90+ { }
91+
92+ template <>
93+ inline void maybe_handle_invalid_option<cuda_cpp>(
94+ status_t <cuda_cpp> status,
95+ const char * program_name,
96+ const const_cstrings_span& raw_options,
97+ handle_t <cuda_cpp> program_handle)
98+ {
99+ if (status == (status_t <cuda_cpp>) status::named_t <cuda_cpp>::invalid_option) {
100+ throw rtc::runtime_error<cuda_cpp>::with_message_override (status,
101+ " Compilation options rejected when compiling " + identify<cuda_cpp>(program_handle, program_name) + ' :'
102+ + get_concatenated_options (raw_options));
103+ }
104+ }
105+
74106template <source_kind_t Kind>
75107inline compilation_output_t <Kind> compile (
76108 const char * program_name,
@@ -84,11 +116,14 @@ inline compilation_output_t<Kind> compile(
84116#endif // CUDA_VERSION >= 11010
85117 (status_t <Kind>) nvrtcCompileProgram ((handle_t <cuda_cpp>)program_handle, (int ) raw_options.size (), raw_options.data ());
86118 bool succeeded = is_success<Kind>(status);
87- if (not (succeeded or (status == (status_t <Kind>) status::named_t <Kind>::compilation_failure))) {
88- throw rtc::runtime_error<Kind>(status, " Failed invoking compiler for " + identify<Kind>(program_handle));
119+ switch (status) {
120+ case status::named_t <Kind>::success:
121+ case status::named_t <Kind>::compilation_failure:
122+ return compilation_output::detail_::wrap<Kind>(program_handle, program_name, succeeded, do_take_ownership);
123+ default :
124+ maybe_handle_invalid_option<Kind>(status, program_name, raw_options, program_handle);
125+ throw rtc::runtime_error<Kind>(status, " Failed invoking compiler for " + identify<Kind>(program_handle, program_name));
89126 }
90- constexpr bool do_own_handle{true };
91- return compilation_output::detail_::wrap<Kind>(program_handle, program_name, succeeded, do_own_handle);
92127}
93128
94129// Note: The program_source _cannot_ be nullptr; if all of your source code is preincluded headers,
0 commit comments