mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
Return error when device does not support Intermediate Language Programs
clGetDeviceInfo, clGetProgramInfo, clCreateProgramWithIL and clSetProgramSpecializationConstant return errors when Intermediate Language Programs are not supported Related-To: NEO-4368 Change-Id: I0bdc218c3cc57ea7ac698cd1db6c85687a8f9f4c Signed-off-by: Andrzej Swierczynski <andrzej.swierczynski@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
b0ed3b2ab1
commit
0dfcfff89c
@ -168,6 +168,11 @@ T *Program::createFromIL(Context *ctx,
|
||||
cl_int &errcodeRet) {
|
||||
errcodeRet = CL_SUCCESS;
|
||||
|
||||
if (ctx->getDevice(0)->getEnabledClVersion() < 21) {
|
||||
errcodeRet = CL_INVALID_VALUE;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ((il == nullptr) || (length == 0)) {
|
||||
errcodeRet = CL_INVALID_BINARY;
|
||||
return nullptr;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "shared/test/unit_test/helpers/test_files.h"
|
||||
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
|
||||
|
||||
#include "cl_api_tests.h"
|
||||
|
||||
@ -66,6 +67,7 @@ TEST_F(clCreateProgramWithBinaryTests, GivenCorrectParametersWhenCreatingProgram
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILTests, GivenInvalidContextWhenCreatingProgramWithIlThenInvalidContextErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
|
||||
cl_int err = CL_SUCCESS;
|
||||
@ -75,13 +77,29 @@ TEST_F(clCreateProgramWithILTests, GivenInvalidContextWhenCreatingProgramWithIlT
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILTests, GivenNullIlWhenCreatingProgramWithIlThenInvalidValueErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
cl_int err = CL_SUCCESS;
|
||||
cl_program prog = clCreateProgramWithIL(pContext, nullptr, 0, &err);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, err);
|
||||
EXPECT_EQ(nullptr, prog);
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILTests, GivenContextWithDevicesThatDontSupportILWhenCreatingProgramWithILThenErrorIsReturned) {
|
||||
cl_int err = CL_SUCCESS;
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
cl_program prog = clCreateProgramWithIL(pContext, spirv, sizeof(spirv), &err);
|
||||
if (pContext->getDevice(0)->getEnabledClVersion() >= 21) {
|
||||
EXPECT_EQ(CL_SUCCESS, err);
|
||||
EXPECT_NE(nullptr, prog);
|
||||
clReleaseProgram(prog);
|
||||
} else {
|
||||
EXPECT_EQ(CL_INVALID_VALUE, err);
|
||||
EXPECT_EQ(nullptr, prog);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILTests, GivenIncorrectIlSizeWhenCreatingProgramWithIlThenInvalidBinaryErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
|
||||
cl_int err = CL_SUCCESS;
|
||||
@ -91,6 +109,7 @@ TEST_F(clCreateProgramWithILTests, GivenIncorrectIlSizeWhenCreatingProgramWithIl
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILTests, GivenIncorrectIlWhenCreatingProgramWithIlThenInvalidBinaryErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t notSpirv[16] = {0xDEADBEEF};
|
||||
|
||||
cl_int err = CL_SUCCESS;
|
||||
@ -100,6 +119,7 @@ TEST_F(clCreateProgramWithILTests, GivenIncorrectIlWhenCreatingProgramWithIlThen
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILTests, GivenIncorrectIlAndNoErrorPointerWhenCreatingProgramWithIlThenInvalidBinaryErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t notSpirv[16] = {0xDEADBEEF};
|
||||
|
||||
cl_program prog = clCreateProgramWithIL(pContext, notSpirv, sizeof(notSpirv), nullptr);
|
||||
@ -107,6 +127,7 @@ TEST_F(clCreateProgramWithILTests, GivenIncorrectIlAndNoErrorPointerWhenCreating
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILKHRTests, GivenCorrectParametersWhenCreatingProgramWithIlkhrThenProgramIsCreatedAndSuccessIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
|
||||
cl_int err = CL_INVALID_VALUE;
|
||||
@ -119,6 +140,7 @@ TEST_F(clCreateProgramWithILKHRTests, GivenCorrectParametersWhenCreatingProgramW
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILKHRTests, GivenProgramCreatedWithILWhenBuildAfterBuildIsCalledThenReturnSuccess) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
cl_int err = CL_INVALID_VALUE;
|
||||
cl_program program = clCreateProgramWithIL(pContext, spirv, sizeof(spirv), &err);
|
||||
@ -133,6 +155,7 @@ TEST_F(clCreateProgramWithILKHRTests, GivenProgramCreatedWithILWhenBuildAfterBui
|
||||
}
|
||||
|
||||
TEST_F(clCreateProgramWithILKHRTests, GivenNullIlWhenCreatingProgramWithIlkhrThenNullProgramIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
cl_program program = clCreateProgramWithILKHR(pContext, nullptr, 0, nullptr);
|
||||
EXPECT_EQ(nullptr, program);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/test/unit_test/helpers/kernel_binary_helper.h"
|
||||
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
|
||||
|
||||
#include "cl_api_tests.h"
|
||||
|
||||
@ -97,6 +98,7 @@ TEST_F(clGetProgramInfoTests, SuccessfulProgramWithSource) {
|
||||
}
|
||||
|
||||
TEST_F(clGetProgramInfoTests, SuccessfulProgramWithIL) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const size_t binarySize = 16;
|
||||
const uint32_t spirv[binarySize] = {0x03022307};
|
||||
|
||||
@ -117,6 +119,7 @@ TEST_F(clGetProgramInfoTests, SuccessfulProgramWithIL) {
|
||||
}
|
||||
|
||||
TEST_F(clGetProgramInfoTests, GivenSPIRVProgramWhenGettingProgramSourceThenReturnNullString) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const size_t binarySize = 16;
|
||||
const uint32_t spirv[binarySize] = {0x03022307};
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "opencl/test/unit_test/mocks/mock_program.h"
|
||||
#include "opencl/test/unit_test/program/program_from_binary.h"
|
||||
#include "opencl/test/unit_test/program/program_with_source.h"
|
||||
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
|
||||
#include "test.h"
|
||||
|
||||
#include "compiler_options.h"
|
||||
@ -2159,6 +2160,7 @@ struct CreateProgramFromBinaryMock : public MockProgram {
|
||||
};
|
||||
|
||||
TEST_F(ProgramTests, GivenFailedBinaryWhenCreatingFromIlThenInvalidBinaryErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t notSpirv[16] = {0xDEADBEEF};
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto prog = Program::createFromIL<CreateProgramFromBinaryMock<CL_INVALID_BINARY>>(pContext, reinterpret_cast<const void *>(notSpirv), sizeof(notSpirv), retVal);
|
||||
@ -2167,6 +2169,7 @@ TEST_F(ProgramTests, GivenFailedBinaryWhenCreatingFromIlThenInvalidBinaryErrorIs
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, GivenSuccessfullyBuiltBinaryWhenCreatingFromIlThenValidProgramIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto prog = Program::createFromIL<CreateProgramFromBinaryMock<CL_SUCCESS>>(pContext, reinterpret_cast<const void *>(spirv), sizeof(spirv), retVal);
|
||||
@ -2176,6 +2179,7 @@ TEST_F(ProgramTests, GivenSuccessfullyBuiltBinaryWhenCreatingFromIlThenValidProg
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, givenProgramCreatedFromILWhenCompileIsCalledThenReuseTheILInsteadOfCallingCompilerInterface) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
cl_int errCode = 0;
|
||||
auto prog = Program::createFromIL<MockProgram>(pContext, reinterpret_cast<const void *>(spirv), sizeof(spirv), errCode);
|
||||
@ -2209,6 +2213,7 @@ TEST_F(ProgramTests, givenProgramCreatedFromIntermediateBinaryRepresentationWhen
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, GivenIlIsNullptrWhenCreatingFromIlThenInvalidBinaryErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto prog = Program::createFromIL<CreateProgramFromBinaryMock<CL_INVALID_BINARY>>(pContext, nullptr, 16, retVal);
|
||||
EXPECT_EQ(nullptr, prog);
|
||||
@ -2216,6 +2221,7 @@ TEST_F(ProgramTests, GivenIlIsNullptrWhenCreatingFromIlThenInvalidBinaryErrorIsR
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, GivenIlSizeZeroWhenCreatingFromIlThenInvalidBinaryErrorIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto prog = Program::createFromIL<CreateProgramFromBinaryMock<CL_INVALID_BINARY>>(pContext, reinterpret_cast<const void *>(spirv), 0, retVal);
|
||||
@ -2224,6 +2230,7 @@ TEST_F(ProgramTests, GivenIlSizeZeroWhenCreatingFromIlThenInvalidBinaryErrorIsRe
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, WhenCreatingFromIlThenIsSpirvIsSetCorrectly) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto prog = Program::createFromIL<Program>(pContext, reinterpret_cast<const void *>(spirv), sizeof(spirv), retVal);
|
||||
@ -2281,6 +2288,7 @@ TEST(isValidSpirvBinary, whenBinaryDoesNotContainLllvMagicThenBinaryIsNotValidLL
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, WhenLinkingTwoValidSpirvProgramsThenValidProgramIsReturned) {
|
||||
REQUIRE_OCL_21_OR_SKIP(pContext);
|
||||
const uint32_t spirv[16] = {0x03022307};
|
||||
cl_int errCode = CL_SUCCESS;
|
||||
|
||||
|
@ -21,3 +21,7 @@ bool TestChecks::supportsSvm(const ClDevice *pClDevice) {
|
||||
bool TestChecks::supportsImages(const Context *pContext) {
|
||||
return pContext->getDevice(0)->getSharedDeviceInfo().imageSupport;
|
||||
}
|
||||
|
||||
bool TestChecks::supportsOcl21(const Context *pContext) {
|
||||
return pContext->getDevice(0)->getEnabledClVersion() >= 21;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ class Context;
|
||||
namespace TestChecks {
|
||||
bool supportsSvm(const ClDevice *pClDevice);
|
||||
bool supportsImages(const Context *pContext);
|
||||
bool supportsOcl21(const Context *pContext);
|
||||
} // namespace TestChecks
|
||||
|
||||
} // namespace NEO
|
||||
@ -24,3 +25,8 @@ bool supportsImages(const Context *pContext);
|
||||
if (NEO::TestChecks::supportsImages(param) == false) { \
|
||||
GTEST_SKIP(); \
|
||||
}
|
||||
|
||||
#define REQUIRE_OCL_21_OR_SKIP(param) \
|
||||
if (NEO::TestChecks::supportsOcl21(param) == false) { \
|
||||
GTEST_SKIP(); \
|
||||
}
|
||||
|
Reference in New Issue
Block a user