2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/file_io.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/test_files.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/context/context.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "cl_api_tests.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef api_tests clReleaseKernelTests;
|
|
|
|
|
|
|
|
namespace ULT {
|
|
|
|
|
2019-07-13 05:31:34 +08:00
|
|
|
TEST_F(clReleaseKernelTests, GivenNullKernelWhenReleasingKernelThenClInvalidKernelErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
retVal = clReleaseKernel(nullptr);
|
|
|
|
EXPECT_EQ(CL_INVALID_KERNEL, retVal);
|
|
|
|
}
|
|
|
|
|
2019-07-13 05:31:34 +08:00
|
|
|
TEST_F(clReleaseKernelTests, GivenRetainedKernelWhenReleasingKernelThenKernelIsCorrectlyReleased) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_kernel kernel = nullptr;
|
|
|
|
cl_program program = nullptr;
|
|
|
|
cl_int binaryStatus = CL_SUCCESS;
|
|
|
|
size_t binarySize = 0;
|
2018-04-24 19:06:49 +08:00
|
|
|
std::string testFile;
|
2020-02-12 17:10:28 +08:00
|
|
|
retrieveBinaryKernelFilename(testFile, "CopyBuffer_simd16_", ".bin");
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
auto binary = loadDataFromFile(testFile.c_str(), binarySize);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_NE(0u, binarySize);
|
|
|
|
ASSERT_NE(nullptr, binary);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
unsigned const char *binaries[1] = {reinterpret_cast<const unsigned char *>(binary.get())};
|
2020-04-24 18:58:39 +08:00
|
|
|
program = clCreateProgramWithBinary(pContext, 1, &testedClDevice, &binarySize, binaries, &binaryStatus, &retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
binary.reset();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_NE(nullptr, program);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2020-04-24 18:58:39 +08:00
|
|
|
retVal = clBuildProgram(program, 1, &testedClDevice, nullptr, nullptr, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
kernel = clCreateKernel(program, "CopyBuffer", &retVal);
|
|
|
|
|
|
|
|
EXPECT_NE(nullptr, kernel);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
cl_uint theRef;
|
|
|
|
retVal = clGetKernelInfo(kernel, CL_KERNEL_REFERENCE_COUNT, sizeof(cl_uint), &theRef, NULL);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(1u, theRef);
|
|
|
|
|
|
|
|
retVal = clRetainKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clRetainKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clGetKernelInfo(kernel, CL_KERNEL_REFERENCE_COUNT, sizeof(cl_uint), &theRef, NULL);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(3u, theRef);
|
|
|
|
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clGetKernelInfo(kernel, CL_KERNEL_REFERENCE_COUNT, sizeof(cl_uint), &theRef, NULL);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(1u, theRef);
|
|
|
|
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(program);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
} // namespace ULT
|