From e9e944479c3ffb3d04a72f527e7350e613b085ce Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Wed, 4 Oct 2023 01:17:54 +0300 Subject: [PATCH] Fixes #544: Better obtainable log/string handling: * 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' --- src/cuda/rtc/compilation_output.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cuda/rtc/compilation_output.hpp b/src/cuda/rtc/compilation_output.hpp index a0458f5f..e1a86cea 100644 --- a/src/cuda/rtc/compilation_output.hpp +++ b/src/cuda/rtc/compilation_output.hpp @@ -311,8 +311,14 @@ class compilation_output_base_t { dynarray log() const { size_t size = program::detail_::get_log_size(program_handle_, program_name_.c_str()); - dynarray result(size); + ::std::vector result(size+1); + if (size == 0) { return result; } program::detail_::get_log(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; } ///@} @@ -399,6 +405,7 @@ class compilation_output_t : public compilation_output_base_t result(size); + if (size == 0) { return result; } program::detail_::get_ptx(result.data(), program_handle_, program_name_.c_str()); return result; } @@ -444,6 +451,7 @@ class compilation_output_t : public compilation_output_base_t(program_handle_, program_name_.c_str()); dynarray result(size); + if (size == 0) { return result; } program::detail_::get_cubin(result.data(), program_handle_, program_name_.c_str()); return result; } @@ -493,6 +501,7 @@ class compilation_output_t : public compilation_output_base_t result(size); + if (size == 0) { return result; } program::detail_::get_lto_ir(result.data(), program_handle_, program_name_.c_str()); return result; } @@ -584,6 +593,7 @@ class compilation_output_t : public compilation_output_base_t { { size_t size = program::detail_::get_cubin_size(program_handle_, program_name_.c_str()); dynarray result(size); + if (size == 0) { return result; } program::detail_::get_cubin(result.data(), program_handle_, program_name_.c_str()); return result; }