Skip to content

Commit

Permalink
Fixes #544, regards #539: Better obtainable log/string handling:
Browse files Browse the repository at this point in the history
* Not trying to make an actual retrieval API call for a size-0 buffer/string (or size-1 compilation log, since it's just the trailing '\0')
* Ensuring our buffer for the compilation log accommodates the trailing '\0'
  • Loading branch information
eyalroz committed Oct 3, 2023
1 parent d46a65c commit 64eb3ec
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cuda/rtc/compilation_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,14 @@ class compilation_output_base_t {
dynarray<char> log() const
{
size_t size = program::detail_::get_log_size<source_kind>(program_handle_, program_name_.c_str());
dynarray<char> result(size);
::std::vector<char> result(size+1);
if (size == 0) { return result; }
program::detail_::get_log<source_kind>(result.data(), program_handle_, program_name_.c_str());
// Q: Isn't it kind of "cheating" to use an ::std::vector, then return it as a dynarray? What
// if we get a proper dynarray which doesn't alias ::std::vector?
// A: Well, kind of; it would mean we might have to copy. However - a proper dynarray might
// allow us to construct it with an arbitrary buffer, or a larger dynarray etc. - and
// then we could ensure the allocation happens only once.
return result;
}
///@}
Expand Down Expand Up @@ -399,6 +405,7 @@ class compilation_output_t<cuda_cpp> : public compilation_output_base_t<cuda_cpp
{
size_t size = program::detail_::get_ptx_size(program_handle_, program_name_.c_str());
dynarray<char> result(size);
if (size == 0) { return result; }
program::detail_::get_ptx(result.data(), program_handle_, program_name_.c_str());
return result;
}
Expand Down Expand Up @@ -444,6 +451,7 @@ class compilation_output_t<cuda_cpp> : public compilation_output_base_t<cuda_cpp
{
size_t size = program::detail_::get_cubin_size<source_kind>(program_handle_, program_name_.c_str());
dynarray<char> result(size);
if (size == 0) { return result; }
program::detail_::get_cubin<source_kind>(result.data(), program_handle_, program_name_.c_str());
return result;
}
Expand Down Expand Up @@ -493,6 +501,7 @@ class compilation_output_t<cuda_cpp> : public compilation_output_base_t<cuda_cpp
{
size_t size = program::detail_::get_lto_ir_size(program_handle_, program_name_.c_str());
dynarray<char> result(size);
if (size == 0) { return result; }
program::detail_::get_lto_ir(result.data(), program_handle_, program_name_.c_str());
return result;
}
Expand Down Expand Up @@ -584,6 +593,7 @@ class compilation_output_t<ptx> : public compilation_output_base_t<ptx> {
{
size_t size = program::detail_::get_cubin_size<source_kind>(program_handle_, program_name_.c_str());
dynarray<char> result(size);
if (size == 0) { return result; }
program::detail_::get_cubin<source_kind>(result.data(), program_handle_, program_name_.c_str());
return result;
}
Expand Down

0 comments on commit 64eb3ec

Please sign in to comment.