Retrieving a program build log might be impossible
Closed this issue · 14 comments
The build log of a program might contain nul
characters. Currently if it does, there is no way to retrieve the log as Program::get_build_log()
only returns Err(-9999)
( CSTRING_UTF8_CONVERSION_ERROR
) when it encounters a nul
.
A potential fix could be something along the lines of the following code, which strips away all nul
characters.
diff --git a/src/program.rs b/src/program.rs
index 7cd8541..3b8271c 100644
--- a/src/program.rs
+++ b/src/program.rs
@@ -304,7 +304,14 @@ impl Program {
pub fn get_build_log(&self, device: cl_device_id) -> Result<CString, cl_int> {
get_program_build_info(self.program, device, ProgramBuildInfo::CL_PROGRAM_BUILD_LOG)?
.to_str()
- .map_err(|_| error_codes::CSTRING_UTF8_CONVERSION_ERROR)
+ .or_else(|nul_error| {
+ Ok(CString::new(
+ std::str::from_utf8(&nul_error.into_vec())
+ .unwrap()
+ .replace('\0', ""),
+ )
+ .unwrap())
+ })
}
pub fn get_build_binary_type(&self, device: cl_device_id) -> Result<cl_uint, cl_int> {
When reading the spec it also seems that usually strings don't contain any nul
characters within the string (and if they could (like CL_PROGRAM_SOURCE they are stripped away. So it won't make sense to change the general approach of returning Cstring
s.
Thank you for considering this potential issue Volker. However, I believe that this issue cannot occur in practice.
The OpenCL API is a C
API. nul
characters are string terminators in C
. Therefore, it is not possible for a C
string to contain a nul
character,. By definition, a nul
character marks the end of a C
string.
Also, please note:
.map_err(|_| error_codes::CSTRING_UTF8_CONVERSION_ERROR)
has replaced unwrap()
as you suggested and as described in issue #5.
I think it makes sense in this case, as it highlights an issue with the OpenCL API without crashing the program.
However, I believe that this issue cannot occur in practice.
The reason I opened this issue is that it happens in practice. Reproducing it locally might be difficult as the code expects certain types of graphic cards. Would it help if I give you the bytes of the error message?
Sorry for the long paste, but here is the error I'm getting (I've put in a manual line break to make it clear where the nul
is:
NulError(5394, [60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 53, 56, 58, 52, 48, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 33, 70, 114, 95, 103, 116, 101, 40, 97, 44, 32, 98, 41, 41, 32, 114, 101, 115, 32, 61, 32, 70, 114, 95, 97, 100, 100, 95, 40, 114, 101, 115, 44, 32, 70, 114, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 54, 53, 58, 49, 56, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 114, 95, 103, 116, 101, 40, 114, 101, 115, 44, 32, 70, 114, 95, 80, 41, 41, 32, 114, 101, 115, 32, 61, 32, 70, 114, 95, 115, 117, 98, 95, 40, 114, 101, 115, 44, 32, 70, 114, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 54, 53, 58, 52, 52, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 114, 95, 103, 116, 101, 40, 114, 101, 115, 44, 32, 70, 114, 95, 80, 41, 41, 32, 114, 101, 115, 32, 61, 32, 70, 114, 95, 115, 117, 98, 95, 40, 114, 101, 115, 44, 32, 70, 114, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 56, 55, 58, 50, 54, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 32, 32, 70, 114, 95, 109, 97, 99, 95, 119, 105, 116, 104, 95, 99, 97, 114, 114, 121, 40, 109, 44, 32, 70, 114, 95, 80, 46, 118, 97, 108, 91, 48, 93, 44, 32, 116, 91, 48, 93, 44, 32, 38, 99, 97, 114, 114, 121, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 56, 57, 58, 51, 57, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 32, 32, 32, 32, 116, 91, 106, 32, 45, 32, 49, 93, 32, 61, 32, 70, 114, 95, 109, 97, 99, 95, 119, 105, 116, 104, 95, 99, 97, 114, 114, 121, 40, 109, 44, 32, 70, 114, 95, 80, 46, 118, 97, 108, 91, 106, 93, 44, 32, 116, 91, 106, 93, 44, 32, 38, 99, 97, 114, 114, 121, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 57, 56, 58, 50, 49, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 114, 95, 103, 116, 101, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 114, 95, 80, 41, 41, 32, 114, 101, 115, 117, 108, 116, 32, 61, 32, 70, 114, 95, 115, 117, 98, 95, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 114, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 57, 56, 58, 53, 51, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 114, 95, 103, 116, 101, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 114, 95, 80, 41, 41, 32, 114, 101, 115, 117, 108, 116, 32, 61, 32, 70, 114, 95, 115, 117, 98, 95, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 114, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 57, 49, 58, 53, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 97, 114, 114, 97, 121, 32, 105, 110, 100, 101, 120, 32, 45, 49, 32, 105, 115, 32, 98, 101, 102, 111, 114, 101, 32, 116, 104, 101, 32, 98, 101, 103, 105, 110, 110, 105, 110, 103, 32, 111, 102, 32, 116, 104, 101, 32, 97, 114, 114, 97, 121, 10, 32, 32, 32, 32, 116, 91, 70, 114, 95, 76, 73, 77, 66, 83, 32, 45, 32, 49, 93, 32, 61, 32, 70, 114, 95, 97, 100, 100, 95, 119, 105, 116, 104, 95, 99, 97, 114, 114, 121, 40, 116, 91, 70, 114, 95, 76, 73, 77, 66, 83, 93, 44, 32, 38, 99, 97, 114, 114, 121, 41, 59, 10, 32, 32, 32, 32, 94, 32, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 49, 55, 55, 58, 51, 58, 32, 110, 111, 116, 101, 58, 32, 97, 114, 114, 97, 121, 32, 39, 116, 39, 32, 100, 101, 99, 108, 97, 114, 101, 100, 32, 104, 101, 114, 101, 10, 32, 32, 70, 114, 95, 108, 105, 109, 98, 32, 116, 91, 70, 114, 95, 76, 73, 77, 66, 83, 32, 43, 32, 50, 93, 32, 61, 32, 123, 48, 125, 59, 10, 32, 32, 94, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 49, 58, 49, 55, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 108, 105, 109, 98, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 108, 105, 109, 98, 32, 117, 108, 111, 110, 103, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 50, 49, 53, 58, 49, 54, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 114, 95, 103, 116, 101, 40, 97, 44, 32, 70, 114, 95, 80, 41, 41, 32, 97, 32, 61, 32, 70, 114, 95, 115, 117, 98, 95, 40, 97, 44, 32, 70, 114, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 50, 49, 53, 58, 51, 56, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 114, 95, 103, 116, 101, 40, 97, 44, 32, 70, 114, 95, 80, 41, 41, 32, 97, 32, 61, 32, 70, 114, 95, 115, 117, 98, 95, 40, 97, 44, 32, 70, 114, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 56, 53, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 114, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 114, 95, 80, 32, 40, 40, 70, 114, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 49, 52, 58, 52, 48, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 33, 70, 113, 95, 103, 116, 101, 40, 97, 44, 32, 98, 41, 41, 32, 114, 101, 115, 32, 61, 32, 70, 113, 95, 97, 100, 100, 95, 40, 114, 101, 115, 44, 32, 70, 113, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 50, 49, 58, 49, 56, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 113, 95, 103, 116, 101, 40, 114, 101, 115, 44, 32, 70, 113, 95, 80, 41, 41, 32, 114, 101, 115, 32, 61, 32, 70, 113, 95, 115, 117, 98, 95, 40, 114, 101, 115, 44, 32, 70, 113, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 50, 49, 58, 52, 52, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 113, 95, 103, 116, 101, 40, 114, 101, 115, 44, 32, 70, 113, 95, 80, 41, 41, 32, 114, 101, 115, 32, 61, 32, 70, 113, 95, 115, 117, 98, 95, 40, 114, 101, 115, 44, 32, 70, 113, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 52, 51, 58, 50, 54, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 32, 32, 70, 113, 95, 109, 97, 99, 95, 119, 105, 116, 104, 95, 99, 97, 114, 114, 121, 40, 109, 44, 32, 70, 113, 95, 80, 46, 118, 97, 108, 91, 48, 93, 44, 32, 116, 91, 48, 93, 44, 32, 38, 99, 97, 114, 114, 121, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 52, 53, 58, 51, 57, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 32, 32, 32, 32, 116, 91, 106, 32, 45, 32, 49, 93, 32, 61, 32, 70, 113, 95, 109, 97, 99, 95, 119, 105, 116, 104, 95, 99, 97, 114, 114, 121, 40, 109, 44, 32, 70, 113, 95, 80, 46, 118, 97, 108, 91, 106, 93, 44, 32, 116, 91, 106, 93, 44, 32, 38, 99, 97, 114, 114, 121, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 53, 52, 58, 50, 49, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 113, 95, 103, 116, 101, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 113, 95, 80, 41, 41, 32, 114, 101, 115, 117, 108, 116, 32, 61, 32, 70, 113, 95, 115, 117, 98, 95, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 113, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 53, 52, 58, 53, 51, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 113, 95, 103, 116, 101, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 113, 95, 80, 41, 41, 32, 114, 101, 115, 117, 108, 116, 32, 61, 32, 70, 113, 95, 115, 117, 98, 95, 40, 114, 101, 115, 117, 108, 116, 44, 32, 70, 113, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 52, 55, 58, 53, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 97, 114, 114, 97, 121, 32, 105, 110, 100, 101, 120, 32, 45, 49, 32, 105, 115, 32, 98, 101, 102, 111, 114, 101, 32, 116, 104, 101, 32, 98, 101, 103, 105, 110, 110, 105, 110, 103, 32, 111, 102, 32, 116, 104, 101, 32, 97, 114, 114, 97, 121, 10, 32, 32, 32, 32, 116, 91, 70, 113, 95, 76, 73, 77, 66, 83, 32, 45, 32, 49, 93, 32, 61, 32, 70, 113, 95, 97, 100, 100, 95, 119, 105, 116, 104, 95, 99, 97, 114, 114, 121, 40, 116, 91, 70, 113, 95, 76, 73, 77, 66, 83, 93, 44, 32, 38, 99, 97, 114, 114, 121, 41, 59, 10, 32, 32, 32, 32, 94, 32, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 51, 51, 58, 51, 58, 32, 110, 111, 116, 101, 58, 32, 97, 114, 114, 97, 121, 32, 39, 116, 39, 32, 100, 101, 99, 108, 97, 114, 101, 100, 32, 104, 101, 114, 101, 10, 32, 32, 70, 113, 95, 108, 105, 109, 98, 32, 116, 91, 70, 113, 95, 76, 73, 77, 66, 83, 32, 43, 32, 50, 93, 32, 61, 32, 123, 48, 125, 59, 10, 32, 32, 94, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 51, 55, 58, 49, 55, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 108, 105, 109, 98, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 108, 105, 109, 98, 32, 117, 108, 111, 110, 103, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 55, 49, 58, 49, 54, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 113, 95, 103, 116, 101, 40, 97, 44, 32, 70, 113, 95, 80, 41, 41, 32, 97, 32, 61, 32, 70, 113, 95, 115, 117, 98, 95, 40, 97, 44, 32, 70, 113, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 53, 55, 49, 58, 51, 56, 58, 32, 119, 97, 114, 110, 105, 110, 103, 58, 32, 101, 120, 99, 101, 115, 115, 32, 101, 108, 101, 109, 101, 110, 116, 115, 32, 105, 110, 32, 97, 114, 114, 97, 121, 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 114, 10, 32, 32, 105, 102, 40, 70, 113, 95, 103, 116, 101, 40, 97, 44, 32, 70, 113, 95, 80, 41, 41, 32, 97, 32, 61, 32, 70, 113, 95, 115, 117, 98, 95, 40, 97, 44, 32, 70, 113, 95, 80, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 10, 60, 107, 101, 114, 110, 101, 108, 62, 58, 52, 52, 49, 58, 50, 51, 58, 32, 110, 111, 116, 101, 58, 32, 101, 120, 112, 97, 110, 100, 101, 100, 32, 102, 114, 111, 109, 32, 109, 97, 99, 114, 111, 32, 39, 70, 113, 95, 80, 39, 10, 35, 100, 101, 102, 105, 110, 101, 32, 70, 113, 95, 80, 32, 40, 40, 70, 113, 41, 123, 32, 123, 32, 54, 52, 53, 49, 51, 32, 125, 32, 125, 41, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 94, 126, 126, 126, 126, 10,
0, 69, 114, 114, 111, 114, 58, 32, 69, 109, 112, 116, 121, 32, 112, 97, 114, 97, 109, 101, 116, 101, 114, 32, 116, 121, 112, 101, 115, 32, 97, 114, 101, 32, 110, 111, 116, 32, 115, 117, 112, 112, 111, 114, 116, 101, 100, 10])
I can understand that all my issues and PRs seem to be totally random. The reason is that I try to get our code base working with opencl3
(porting over from ocl
). I try to upstream as much as possible as to me the most powerful feature of open source it's the collaboration between interested parties.
I try my best making clear why I need those changes (I didn't do a good job on the original message).
I prepared a branch of the real world example. As I said, you'd need to have one of the supported GPUs, but perhaps you have one. In order to see the output, as mentioned above run:
$ git clone --branch tmp-opencl3-issue-8 https://github.com/filecoin-project/bellperson
$ cd bellperson
$ cargo test --no-default-features --features gpu,blst --lib -- --nocapture groth16::tests::test_xordemo
Sorry, I should have guessed that this was a real problem!
Also, this is not the first log message to have extra nulls. @jsatka fixed an issue with multiple trailing nulls in the cl3
repo. So, clearly some devices aren't conforming to the spec...
I think that your original proposal was along the right lines. Unfortunately, I'm away from home and can't fix it at the moment. Would you like to submit a pull request with the unwrap
s replace by map
s or expect
s?
@kenba sure, I'm happy to do a PR. I've a question though. Should this only go into the get_build_log()
as it is a known source of the problem? Or should the to_str()
in cl3
be changed to just replace all nul
s instead of just the trailing ones?
Scanning all strings all the time sounds like a bit of waste, though I think I would do it directly in to_str()
. If it then later turns out it is a too big of a performance hit, it can be changed. I find correctness/robustness more important than saving on theoretic (not benchmarked) performance gains.
The reason I opened this issue is that it happens in practice.
I have also encountered this issue in practice and think this is a good initiative!
Thanks @jsatka it's good to know that you've also encountered this issue. It's clearly one that's worth resolving!
I've had a think about how best to resolve this issue. And I think that you are right @vmx; the best solution may involve changing CString
handling in cl3 , instead of (or maybe in addition to) handling it in this library. To that end, I've raised cl3 #2 to track this issue in that library.
My preference is to leave the Program get_build_log
method unchanged and provide new methods that can be used handle CSTRING_UTF8_CONVERSION_ERROR
error_codes when they occur.
So far I've changed how the cl3
InfoType
handles strings (it now considers them as VecUchar
s) and provided a new unsafe method: to_str_unchecked
to create a CString
using from_vec_unchecked
. I've also created a new unsafe method get_build_log_unchecked
in opencl3::Program
which calls to_str_unchecked
.
My changes can be found in the develop
branches of both libraries.
Please try them out and let me know if they work. If not you can replace the "unchecked" functions with functions to replace the nul
s with spaces, etc. as you proposed @vmx.
I've commented on the commit (perhaps opening a PR would make future discussions easier): ddd4260#r48441299
Thanks for your comments Volker. Perhaps you are right, I should have opened a PR to make discussions easier, I'm just not used to raising PRs on my own repo.
Your interpretation of *_unchecked()
methods sounds reasonable to me. They are not the correct solution to this issue, I have removed them.
I would prefer to solve the issue in this library instead of the cl3
library.
I designed the cl3
library to be a simple wrapper around the OpenCL API. In hindsight, I can see that I made a mistake by providing the InfoType::to_str
method and creating a new error type for when a VecUchar
is not a valid CString
.
I should just provided the InfoType::to_vec_uchar
method and performed string conversion in this library.
However, now that the InfoType::to_str
method exists, I agree that it should return a valid CString
as you propose.
So I have amended the InfoType::to_str
method to transform the remaining nul
s to spaces after dropping the trailing nul
s.
The changes can be found in the develop
branches of both libraries, as before.
What do you think now?
I'm just not used to raising PRs on my own repo.
There's lots of thing to learn when suddenly random strangers contribute :)
However, now that the
InfoType::to_str
method exists, I agree that it should return a validCString
as you propose.
[…]
I should just provided theInfoType::to_vec_uchar
method and performed string conversion in this library.
I wouldn't mind if the decision is to remove it again. I think this library is young enough to still make those changes. So if you feel strongly about it, I'd say make this change and remove to_str()
from cl3
. Though it would probably lead to some kind of to_str()
call in all functions in opencl3
that are using it, so I'm not sure if it would be worth it (it may be worth a try though).
So I have amended the InfoType::to_str method to transform the remaining nuls to spaces after dropping the trailing nuls.
Looks good, I left a comment which simplifies the code a bit: kenba/cl3@6e9853c#r48451836
The changes can be found in the
develop
branches of both libraries, as before.
Looks like the opencl3
develop
branch doesn't contain any changes anymore, that sounds good to me.
Thank you @vmx. I'm always happy to learn new things and I'm very happy that the libraries are useful to you.
I've incorporated the change that you proposed to the to_str
function.
I'll copy the changes over to main and publish a new version of cl3
on crates.io
soon.
I'll consider moving to_str()
from cl3
to opencl3
later. I'm currently considering how best to implement: Clone, Send and Sync. :)
Thanks a lot, this should fix the issue. I'll have a closer look at it next week.
I want to confirm that I'm now able to get the build log. I've seen that there are some related upcoming changes I'll have a look at now.