Skip to content

Commit 836056e

Browse files
author
Hugh Delaney
committed
Merge remote-tracking branch 'Fraser/fix-build-info-log' into readytomerge-branch
2 parents 8db0b56 + 8b495ad commit 836056e

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

source/adapters/cuda/program.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,24 @@ urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t hDevice,
354354
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
355355

356356
switch (propName) {
357-
case UR_PROGRAM_BUILD_INFO_STATUS: {
357+
case UR_PROGRAM_BUILD_INFO_STATUS:
358358
return ReturnValue(hProgram->BuildStatus);
359-
}
360359
case UR_PROGRAM_BUILD_INFO_OPTIONS:
361360
return ReturnValue(hProgram->BuildOptions.c_str());
362-
case UR_PROGRAM_BUILD_INFO_LOG:
363-
return ReturnValue(hProgram->InfoLog, hProgram->MaxLogSize);
364-
case UR_PROGRAM_BUILD_INFO_BINARY_TYPE: {
365-
return ReturnValue(hProgram->BinaryType);
361+
case UR_PROGRAM_BUILD_INFO_LOG: {
362+
// We only know the maximum log length, which CUDA guarantees will include
363+
// the null terminator.
364+
// To determine the actual length of the log, search for the first
365+
// null terminator, not searching past the known maximum. If that does find
366+
// one, it will return the length excluding the null terminator, so remember
367+
// to include that.
368+
auto LogLen =
369+
std::min(hProgram->MaxLogSize,
370+
strnlen(hProgram->InfoLog, hProgram->MaxLogSize) + 1);
371+
return ReturnValue(hProgram->InfoLog, LogLen);
366372
}
373+
case UR_PROGRAM_BUILD_INFO_BINARY_TYPE:
374+
return ReturnValue(hProgram->BinaryType);
367375
default:
368376
break;
369377
}

source/adapters/hip/program.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,18 @@ urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t,
364364
return ReturnValue(hProgram->BuildStatus);
365365
case UR_PROGRAM_BUILD_INFO_OPTIONS:
366366
return ReturnValue(hProgram->BuildOptions.c_str());
367-
case UR_PROGRAM_BUILD_INFO_LOG:
368-
return ReturnValue(hProgram->InfoLog, hProgram->MAX_LOG_SIZE);
367+
case UR_PROGRAM_BUILD_INFO_LOG: {
368+
// We only know the maximum log length, which (we assume) HIP guarantees
369+
// will include the null terminator, like CUDA does.
370+
// To determine the actual length of the log, search for the first null
371+
// terminator, not searching past the known maximum. If that does find one,
372+
// it will return the length excluding the null terminator, so remember to
373+
// include that.
374+
auto LogLen =
375+
std::min(hProgram->MAX_LOG_SIZE,
376+
strnlen(hProgram->InfoLog, hProgram->MAX_LOG_SIZE) + 1);
377+
return ReturnValue(hProgram->InfoLog, LogLen);
378+
}
369379
case UR_PROGRAM_BUILD_INFO_BINARY_TYPE:
370380
return ReturnValue(hProgram->BinaryType);
371381
default:

test/conformance/program/program_adapter_cuda.match

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ urProgramBuildTest.BuildFailure/NVIDIA_CUDA_BACKEND___{{.*}}_
77
# CUDA doesn't expose kernel numbers or names
88
urProgramGetInfoTest.Success/NVIDIA_CUDA_BACKEND___{{.*}}___UR_PROGRAM_INFO_NUM_KERNELS
99
urProgramGetInfoTest.Success/NVIDIA_CUDA_BACKEND___{{.*}}___UR_PROGRAM_INFO_KERNEL_NAMES
10-
1110
{{OPT}}urProgramSetSpecializationConstantsTest.Success/NVIDIA_CUDA_BACKEND___{{.*}}
1211
{{OPT}}urProgramSetSpecializationConstantsTest.UseDefaultValue/NVIDIA_CUDA_BACKEND___{{.*}}
1312
urProgramSetMultipleSpecializationConstantsTest.MultipleCalls/NVIDIA_CUDA_BACKEND___{{.*}}

test/conformance/program/program_adapter_hip.match

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
urProgramBuildTest.BuildFailure/AMD_HIP_BACKEND___{{.*}}_
22
# HIP hasn't implemented urProgramCreateWithNativeHandleTest
33
{{OPT}}urProgramCreateWithNativeHandleTest.Success/AMD_HIP_BACKEND___{{.*}}_
4-
# This test flakily fails
5-
{{OPT}}urProgramGetBuildInfoSingleTest.LogIsNullTerminated/AMD_HIP_BACKEND___{{.*}}_
64
# HIP doesn't expose kernel numbers or names
75
urProgramGetInfoTest.Success/AMD_HIP_BACKEND___{{.*}}___UR_PROGRAM_INFO_NUM_KERNELS
86
urProgramGetInfoTest.Success/AMD_HIP_BACKEND___{{.*}}___UR_PROGRAM_INFO_KERNEL_NAMES

test/conformance/program/urProgramGetBuildInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ TEST_P(urProgramGetBuildInfoSingleTest, LogIsNullTerminated) {
7575

7676
ASSERT_SUCCESS(urProgramGetBuildInfo(
7777
program, device, UR_PROGRAM_BUILD_INFO_LOG, 0, nullptr, &logSize));
78+
// The size should always include the null terminator.
79+
ASSERT_GT(logSize, 0);
7880
log.resize(logSize);
7981
log[logSize - 1] = 'x';
8082
ASSERT_SUCCESS(urProgramGetBuildInfo(program, device,

0 commit comments

Comments
 (0)