Open maleadt opened 3 years ago
https://spec.oneapi.com/level-zero/latest/core/api.html#zekernelgetsourceattributes
It looks like the implementation of this API in compute-runtime is not compliant with the specification.
pString
to nullptr
, you can just simply get the string pointer and then calculate the size in the applicationCould you open an issue in compute-runtime github if you agree?
@bmyates Wrong implementation is in the validation layer. Driver does this:
ze_result_t KernelImp::getSourceAttributes(uint32_t *pSize, char **pString) {
auto &desc = kernelImmData->getDescriptor();
if (pString == nullptr) {
*pSize = (uint32_t)desc.kernelMetadata.kernelLanguageAttributes.length() + 1;
} else {
strncpy_s(*pString, desc.kernelMetadata.kernelLanguageAttributes.length() + 1,
desc.kernelMetadata.kernelLanguageAttributes.c_str(),
desc.kernelMetadata.kernelLanguageAttributes.length() + 1);
}
return ZE_RESULT_SUCCESS;
}
so effectively we just return size if string is null. However, the validation layer has this:
if( context.enableParameterValidation )
{
if( nullptr == hKernel )
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if( nullptr == pSize )
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
if( nullptr == pString )
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
}
which means we always fail if string is null.
When invoking
zeKernelGetSourceAttributes
with a nullptrpString
pointer to obtain the attribute size, https://github.com/intel/compute-runtime/blob/128cd8a31c16977ecc41bf13bdd35c2ac4907a5b/level_zero/core/source/kernel/kernel_imp.cpp#L443-L445, the validator erroneously throws an ERROR_INVALID_NULL_POINTER, https://github.com/oneapi-src/level-zero/blob/284ccb089184180e34864a9f1e23971d3d736bd8/source/layers/validation/ze_valddi.cpp#L3087-L3088