fix: return success from release calls after platform teardown

Related-To: NEO-11282
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2024-09-26 11:55:27 +00:00
committed by Compute-Runtime-Automation
parent 168ed4af54
commit 1dafb66463
17 changed files with 248 additions and 17 deletions

View File

@@ -31,6 +31,7 @@
#include "opencl/source/context/driver_diagnostics.h"
#include "opencl/source/event/user_event.h"
#include "opencl/source/execution_environment/cl_execution_environment.h"
#include "opencl/source/global_teardown/global_platform_teardown.h"
#include "opencl/source/gtpin/gtpin_notify.h"
#include "opencl/source/helpers/cl_memory_properties_helpers.h"
#include "opencl/source/helpers/cl_validators.h"
@@ -383,6 +384,9 @@ cl_int CL_API_CALL clRetainDevice(cl_device_id device) {
cl_int CL_API_CALL clReleaseDevice(cl_device_id device) {
TRACING_ENTER(ClReleaseDevice, &device);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_INVALID_DEVICE;
API_ENTER(&retVal);
DBG_LOG_INPUTS("device", device);
@@ -519,6 +523,9 @@ cl_int CL_API_CALL clRetainContext(cl_context context) {
cl_int CL_API_CALL clReleaseContext(cl_context context) {
TRACING_ENTER(ClReleaseContext, &context);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("context", context);
@@ -636,6 +643,9 @@ cl_int CL_API_CALL clRetainCommandQueue(cl_command_queue commandQueue) {
cl_int CL_API_CALL clReleaseCommandQueue(cl_command_queue commandQueue) {
TRACING_ENTER(ClReleaseCommandQueue, &commandQueue);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_INVALID_COMMAND_QUEUE;
API_ENTER(&retVal);
DBG_LOG_INPUTS("commandQueue", commandQueue);
@@ -1115,6 +1125,9 @@ cl_int CL_API_CALL clRetainMemObject(cl_mem memobj) {
cl_int CL_API_CALL clReleaseMemObject(cl_mem memobj) {
TRACING_ENTER(ClReleaseMemObject, &memobj);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_INVALID_MEM_OBJECT;
API_ENTER(&retVal);
@@ -1339,6 +1352,9 @@ cl_int CL_API_CALL clRetainSampler(cl_sampler sampler) {
cl_int CL_API_CALL clReleaseSampler(cl_sampler sampler) {
TRACING_ENTER(ClReleaseSampler, &sampler);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("sampler", sampler);
@@ -1537,6 +1553,9 @@ cl_int CL_API_CALL clRetainProgram(cl_program program) {
cl_int CL_API_CALL clReleaseProgram(cl_program program) {
TRACING_ENTER(ClReleaseProgram, &program);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("program", program);
@@ -1878,6 +1897,9 @@ cl_int CL_API_CALL clRetainKernel(cl_kernel kernel) {
cl_int CL_API_CALL clReleaseKernel(cl_kernel kernel) {
TRACING_ENTER(ClReleaseKernel, &kernel);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("kernel", kernel);
@@ -2172,6 +2194,9 @@ cl_int CL_API_CALL clRetainEvent(cl_event event) {
cl_int CL_API_CALL clReleaseEvent(cl_event event) {
TRACING_ENTER(ClReleaseEvent, &event);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
auto retVal = CL_SUCCESS;
API_ENTER(&retVal);
auto pEvent = castToObject<Event>(event);
@@ -4509,6 +4534,9 @@ cl_int CL_API_CALL clReleaseAcceleratorINTEL(
cl_accelerator_intel accelerator) {
TRACING_ENTER(ClReleaseAcceleratorINTEL, &accelerator);
if (wasPlatformTeardownCalled) {
return CL_SUCCESS;
}
cl_int retVal = CL_SUCCESS;
API_ENTER(&retVal);
DBG_LOG_INPUTS("accelerator", accelerator);

View File

@@ -0,0 +1,14 @@
#
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(RUNTIME_SRCS_GLOBAL_TEARDOWN
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/global_platform_teardown.cpp
${CMAKE_CURRENT_SOURCE_DIR}/global_platform_teardown.h
)
add_subdirectories()
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_GLOBAL_TEARDOWN})
set_property(GLOBAL PROPERTY RUNTIME_SRCS_GLOBAL_TEARDOWN ${RUNTIME_SRCS_GLOBAL_TEARDOWN})

View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/source/platform/platform.h"
namespace NEO {
volatile bool wasPlatformTeardownCalled = false;
void globalPlatformSetup() {
platformsImpl = new std::vector<std::unique_ptr<Platform>>;
}
void globalPlatformTeardown() {
delete platformsImpl;
platformsImpl = nullptr;
wasPlatformTeardownCalled = true;
}
} // namespace NEO

View File

@@ -0,0 +1,15 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
namespace NEO {
extern volatile bool wasPlatformTeardownCalled;
void globalPlatformTeardown();
void globalPlatformSetup();
} // namespace NEO

View File

@@ -1,18 +1,17 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/source/platform/platform.h"
#include "opencl/source/global_teardown/global_platform_teardown.h"
namespace NEO {
void __attribute__((constructor)) platformsConstructor() {
platformsImpl = new std::vector<std::unique_ptr<Platform>>;
globalPlatformSetup();
}
void __attribute__((destructor)) platformsDestructor() {
delete platformsImpl;
platformsImpl = nullptr;
globalPlatformTeardown();
}
} // namespace NEO

View File

@@ -1,20 +1,22 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/source/platform/platform.h"
#include "shared/source/os_interface/windows/windows_wrapper.h"
#include "opencl/source/global_teardown/global_platform_teardown.h"
using namespace NEO;
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { // NOLINT(readability-identifier-naming)
if (fdwReason == DLL_PROCESS_DETACH) {
delete platformsImpl;
globalPlatformTeardown();
}
if (fdwReason == DLL_PROCESS_ATTACH) {
platformsImpl = new std::vector<std::unique_ptr<Platform>>;
globalPlatformSetup();
}
return TRUE;
}

View File

@@ -1,11 +1,12 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/source/context/context.h"
#include "opencl/source/global_teardown/global_platform_teardown.h"
#include "cl_api_tests.h"
@@ -53,4 +54,17 @@ TEST_F(ClCreateSamplerTests, GivenInvalidContextWhenCreatingSamplerThenInvalidCo
EXPECT_EQ(nullptr, sampler);
delete sampler;
}
TEST_F(ClCreateSamplerTests, GivenInvalidSamplerWhenCallingReleaseThenErrorCodeReturn) {
retVal = clReleaseSampler(nullptr);
EXPECT_NE(CL_SUCCESS, retVal);
}
TEST_F(ClCreateSamplerTests, GivenInvalidSamplerWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
retVal = clReleaseSampler(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
} // namespace ULT

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -8,6 +8,7 @@
#include "opencl/source/accelerators/intel_accelerator.h"
#include "opencl/source/accelerators/intel_motion_estimation.h"
#include "opencl/source/context/context.h"
#include "opencl/source/global_teardown/global_platform_teardown.h"
#include "opencl/test/unit_test/api/cl_api_tests.h"
using namespace NEO;
@@ -86,6 +87,13 @@ TEST_F(IntelAcceleratorTest, GivenNullAcceleratorWhenRetainingAcceleratorThenClI
EXPECT_EQ(CL_INVALID_ACCELERATOR_INTEL, result);
}
TEST_F(IntelAcceleratorTest, GivenInvalidAcceleratorWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseAcceleratorINTEL(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
struct IntelAcceleratorGetInfoTest : IntelAcceleratorTestWithValidDescriptor {
IntelAcceleratorGetInfoTest() {}

View File

@@ -1,10 +1,12 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/source/global_teardown/global_platform_teardown.h"
#include "cl_api_tests.h"
using namespace NEO;
@@ -33,4 +35,11 @@ TEST_F(ClReleaseContextTests, GivenNullContextWhenReleasingContextThenClInvalidC
auto retVal = clReleaseContext(nullptr);
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
}
TEST_F(ClReleaseContextTests, GivenInvalidContextWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseContext(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
} // namespace ULT

View File

@@ -124,6 +124,13 @@ TEST_F(clEventTests, GivenValidEventWhenSettingStatusMultipleTimesThenClInvalidO
clReleaseEvent(event);
}
TEST_F(clEventTests, GivenInvalidEventWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseEvent(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
typedef EventFixture<::testing::TestWithParam<std::tuple<int32_t, int32_t>>> clEventStatusTests;
TEST_P(clEventStatusTests, GivenExecutionStatusWhenSettingUserEventStatusThenSuccessOrCorrectErrorIsReturned) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -82,4 +82,12 @@ TEST_F(ClReleaseKernelTests, GivenRetainedKernelWhenReleasingKernelThenKernelIsC
retVal = clReleaseProgram(program);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(ClReleaseKernelTests, GivenInvalidKernelWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseKernel(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
} // namespace ULT

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -36,4 +36,17 @@ TEST_F(ClReleaseMemObjectTests, GivenValidBufferWhenReleasingMemObjectThenSucces
retVal = clReleaseMemObject(buffer);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(ClReleaseMemObjectTests, GivenInvalidMemObjWhenReleasingThenErrorCodeReturn) {
auto retVal = clReleaseMemObject(nullptr);
EXPECT_NE(CL_SUCCESS, retVal);
}
TEST_F(ClReleaseMemObjectTests, GivenInvalidMemObjWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseMemObject(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
} // namespace ULT

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -46,3 +46,10 @@ TEST_F(ClReleaseProgramTests, GivenRetainedProgramWhenReleasingProgramThenProgra
retVal = clReleaseProgram(prog);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(ClReleaseProgramTests, GivenInvalidProgramWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseProgram(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -64,4 +64,16 @@ TEST_F(ClRetainReleaseCommandQueueTests, GivenValidCommandQueueWhenRetainingAndR
this->retVal = clReleaseCommandQueue(queue);
EXPECT_EQ(CL_SUCCESS, this->retVal);
}
TEST_F(ClRetainReleaseCommandQueueTests, GivenInvalidCommandQueueWhenReleasingThenErrorCodeReturn) {
auto retVal = clReleaseCommandQueue(nullptr);
EXPECT_NE(CL_SUCCESS, retVal);
}
TEST_F(ClRetainReleaseCommandQueueTests, GivenInvalidCommandQueueWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseCommandQueue(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
} // namespace ULT

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,6 +7,7 @@
#include "shared/test/common/test_macros/test.h"
#include "opencl/source/global_teardown/global_platform_teardown.h"
#include "opencl/test/unit_test/fixtures/platform_fixture.h"
using namespace NEO;
@@ -64,4 +65,16 @@ TEST_F(ClRetainReleaseDeviceTests, GivenRootDeviceWhenReleasingThenReferenceCoun
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, theRef);
}
TEST_F(ClRetainReleaseDeviceTests, GivenInvaliddeviceWhenCallingReleaseThenErrorCodeReturn) {
auto retVal = clReleaseDevice(nullptr);
EXPECT_NE(CL_SUCCESS, retVal);
}
TEST_F(ClRetainReleaseDeviceTests, GivenInvalidDeviceWhenTerdownWasCalledThenSuccessReturned) {
wasPlatformTeardownCalled = true;
auto retVal = clReleaseDevice(nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
wasPlatformTeardownCalled = false;
}
} // namespace ULT

View File

@@ -0,0 +1,13 @@
#
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(IGDRCL_SRCS_tests_global_platform_teardown
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/global_platform_teardown_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_global_platform_teardown})

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/test_macros/test.h"
#include "opencl/source/global_teardown/global_platform_teardown.h"
#include "opencl/source/platform/platform.h"
using namespace NEO;
class GlobalPlatformTeardownTest : public ::testing::Test {
void SetUp() override {
tmpPlatforms = platformsImpl;
platformsImpl = nullptr;
}
void TearDown() override {
globalPlatformTeardown();
wasPlatformTeardownCalled = false;
platformsImpl = tmpPlatforms;
}
std::vector<std::unique_ptr<Platform>> *tmpPlatforms;
};
TEST_F(GlobalPlatformTeardownTest, whenCallingPlatformSetupThenPlatformsAllocated) {
globalPlatformSetup();
EXPECT_NE(platformsImpl, nullptr);
}
TEST_F(GlobalPlatformTeardownTest, whenCallingPlatformSetupThenWasTeardownCalledIsSetToFalse) {
globalPlatformSetup();
EXPECT_FALSE(wasPlatformTeardownCalled);
}
TEST_F(GlobalPlatformTeardownTest, whenCallingPlatformTeardownThenPlatformsDestroyed) {
globalPlatformSetup();
globalPlatformTeardown();
EXPECT_EQ(platformsImpl, nullptr);
}
TEST_F(GlobalPlatformTeardownTest, whenCallingPlatformTeardownThenWasTeardownCalledIsSetToTrue) {
globalPlatformSetup();
globalPlatformTeardown();
EXPECT_TRUE(wasPlatformTeardownCalled);
}