From 17c6142191187b8229049b0f75e2771e72140037 Mon Sep 17 00:00:00 2001 From: hjnapiat Date: Wed, 3 Jan 2018 10:54:31 +0100 Subject: [PATCH] Add support for GT-Pin Callbacks [1/n] - Also fixes bug when returning version of supported GT-Pin interface Change-Id: Ib471a11a3b51d69240dcd2f800a8e28eefdeed57 --- Jenkinsfile | 2 +- runtime/CMakeLists.txt | 19 +++- runtime/api/api.cpp | 10 ++- runtime/gtpin/gtpin_callback_stubs.cpp | 32 +++++++ runtime/gtpin/gtpin_callbacks.cpp | 58 +++++++++++++ runtime/gtpin/gtpin_helpers.cpp | 6 +- runtime/gtpin/gtpin_hw_helper.cpp | 31 +++++++ runtime/gtpin/gtpin_hw_helper.h | 48 +++++++++++ runtime/gtpin/gtpin_init.cpp | 18 +--- runtime/gtpin/gtpin_notify.h | 28 ++++++ runtime/gtpin/gtpin_setup_gen8.cpp | 48 +++++++++++ runtime/gtpin/gtpin_setup_gen9.cpp | 48 +++++++++++ unit_tests/CMakeLists.txt | 9 ++ .../api/cl_create_context_from_type_tests.cpp | 8 ++ unit_tests/api/cl_create_context_tests.cpp | 8 ++ unit_tests/gtpin/gtpin_tests.cpp | 86 ++++++++++++++++++- 16 files changed, 435 insertions(+), 24 deletions(-) create mode 100644 runtime/gtpin/gtpin_callback_stubs.cpp create mode 100644 runtime/gtpin/gtpin_callbacks.cpp create mode 100644 runtime/gtpin/gtpin_hw_helper.cpp create mode 100644 runtime/gtpin/gtpin_hw_helper.h create mode 100644 runtime/gtpin/gtpin_notify.h create mode 100644 runtime/gtpin/gtpin_setup_gen8.cpp create mode 100644 runtime/gtpin/gtpin_setup_gen9.cpp diff --git a/Jenkinsfile b/Jenkinsfile index 9e3f040f43..841faeb9e1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,4 +2,4 @@ neoDependenciesRev='727168-748' strategy='EQUAL' allowedF=49 -allowedCD=374 +allowedCD=373 diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index e01ea725f9..33015dbf92 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -250,10 +250,19 @@ set (RUNTIME_SRCS_EXECUTION_MODEL if(GTPIN_HEADERS_DIR) set (RUNTIME_SRCS_GTPIN - gtpin/gtpin_init.cpp - gtpin/gtpin_init.h + gtpin/gtpin_callbacks.cpp gtpin/gtpin_helpers.cpp gtpin/gtpin_helpers.h + gtpin/gtpin_hw_helper.cpp + gtpin/gtpin_hw_helper.h + gtpin/gtpin_init.cpp + gtpin/gtpin_init.h + gtpin/gtpin_notify.h + ) +else(GTPIN_HEADERS_DIR) + set (RUNTIME_SRCS_GTPIN + gtpin/gtpin_callback_stubs.cpp + gtpin/gtpin_notify.h ) endif(GTPIN_HEADERS_DIR) @@ -803,6 +812,12 @@ if(${GENERATE_EXECUTABLE}) if(GTPIN_HEADERS_DIR) list (APPEND RUNTIME_SRCS_DLL gtpin/gtpin_init.cpp) + foreach(GEN_NUM RANGE ${MAX_GEN} 0 -1) + GEN_CONTAINS_PLATFORMS("SUPPORTED" ${GEN_NUM} GENX_HAS_PLATFORMS) + if(${GENX_HAS_PLATFORMS}) + list(APPEND RUNTIME_SRCS_GTPIN gtpin/gtpin_setup_gen${GEN_NUM}.cpp) + endif(${GENX_HAS_PLATFORMS}) + endforeach(GEN_NUM) endif(GTPIN_HEADERS_DIR) add_library(${NEO_DYNAMIC_LIB_NAME} SHARED diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index 0a3b9e7a9f..4aed77a7ea 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -33,6 +33,7 @@ #include "runtime/context/driver_diagnostics.h" #include "runtime/device/device.h" #include "runtime/device_queue/device_queue.h" +#include "runtime/gtpin/gtpin_notify.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/get_info.h" #include "runtime/helpers/hw_info.h" @@ -289,6 +290,9 @@ cl_context CL_API_CALL clCreateContext(const cl_context_properties *properties, DeviceVector allDevs(devices, numDevices); context = Context::create(properties, allDevs, funcNotify, userData, retVal); + if (context != nullptr) { + gtpinNotifyContextCreate(context); + } } while (false); if (errcodeRet) { @@ -314,7 +318,7 @@ cl_context CL_API_CALL clCreateContextFromType(const cl_context_properties *prop } cl_uint numDevices = 0; - /* Querry the number of device first. */ + /* Query the number of device first. */ retVal = clGetDeviceIDs(nullptr, deviceType, 0, nullptr, &numDevices); if (retVal != CL_SUCCESS) { break; @@ -329,6 +333,9 @@ cl_context CL_API_CALL clCreateContextFromType(const cl_context_properties *prop DeviceVector allDevs(supportedDevs.begin(), numDevices); pContext = Context::create(properties, allDevs, funcNotify, userData, retVal); + if (pContext != nullptr) { + gtpinNotifyContextCreate((cl_context)pContext); + } } while (false); if (errcodeRet) { @@ -353,6 +360,7 @@ cl_int CL_API_CALL clReleaseContext(cl_context context) { Context *pContext = castToObject(context); if (pContext) { pContext->release(); + gtpinNotifyContextDestroy(context); return CL_SUCCESS; } diff --git a/runtime/gtpin/gtpin_callback_stubs.cpp b/runtime/gtpin/gtpin_callback_stubs.cpp new file mode 100644 index 0000000000..bf3fa8c442 --- /dev/null +++ b/runtime/gtpin/gtpin_callback_stubs.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "CL/cl.h" + +namespace OCLRT { + +void gtpinNotifyContextCreate(cl_context context) { +} + +void gtpinNotifyContextDestroy(cl_context context) { +} +} diff --git a/runtime/gtpin/gtpin_callbacks.cpp b/runtime/gtpin/gtpin_callbacks.cpp new file mode 100644 index 0000000000..ca2b2e41d8 --- /dev/null +++ b/runtime/gtpin/gtpin_callbacks.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "config.h" +#include "gtpin_dx11_interface.h" +#include "CL/cl.h" +#include "runtime/device/device.h" +#include "runtime/device/device_info.h" +#include "runtime/gtpin/gtpin_hw_helper.h" +#include "runtime/platform/platform.h" + +using namespace gtpin; + +namespace OCLRT { +extern bool isGTPinInitialized; +extern gtpin::dx11::gtpin_events_t GTPinCallbacks; + +igc_init_t *pIgcInfo = nullptr; + +void gtpinNotifyContextCreate(cl_context context) { + if (isGTPinInitialized) { + platform_info_t gtpinPlatformInfo; + auto pPlatform = platform(); + auto pDevice = pPlatform->getDevice(0); + GFXCORE_FAMILY genFamily = pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily; + GTPinHwHelper >pinHelper = GTPinHwHelper::get(genFamily); + gtpinPlatformInfo.gen_version = (gtpin::GTPIN_GEN_VERSION)gtpinHelper.getGenVersion(); + gtpinPlatformInfo.device_id = static_cast(pDevice->getHardwareInfo().pPlatform->usDeviceID); + + (*GTPinCallbacks.onContextCreate)((context_handle_t)context, >pinPlatformInfo, &pIgcInfo); + } +} + +void gtpinNotifyContextDestroy(cl_context context) { + if (isGTPinInitialized) { + (*GTPinCallbacks.onContextDestroy)((context_handle_t)context); + } +} +} diff --git a/runtime/gtpin/gtpin_helpers.cpp b/runtime/gtpin/gtpin_helpers.cpp index 3b690bcaf9..3ebf39145e 100644 --- a/runtime/gtpin/gtpin_helpers.cpp +++ b/runtime/gtpin/gtpin_helpers.cpp @@ -49,7 +49,7 @@ GTPIN_DI_STATUS gtpinCreateBuffer(context_handle_t context, uint32_t reqSize, re return GTPIN_DI_SUCCESS; } -GTPIN_DI_STATUS gtpinFreeBuffer(gtpin::context_handle_t context, gtpin::resource_handle_t resource) { +GTPIN_DI_STATUS gtpinFreeBuffer(context_handle_t context, resource_handle_t resource) { cl_mem buffer = (cl_mem)resource; Context *pContext = castToObject((cl_context)context); if ((pContext == nullptr) || (buffer == nullptr)) { @@ -64,7 +64,7 @@ GTPIN_DI_STATUS gtpinFreeBuffer(gtpin::context_handle_t context, gtpin::resource return GTPIN_DI_SUCCESS; } -GTPIN_DI_STATUS gtpinMapBuffer(gtpin::context_handle_t context, gtpin::resource_handle_t resource, uint8_t **pAddress) { +GTPIN_DI_STATUS gtpinMapBuffer(context_handle_t context, resource_handle_t resource, uint8_t **pAddress) { cl_mem buffer = (cl_mem)resource; Context *pContext = castToObject((cl_context)context); if ((pContext == nullptr) || (buffer == nullptr) || (pAddress == nullptr)) { @@ -78,7 +78,7 @@ GTPIN_DI_STATUS gtpinMapBuffer(gtpin::context_handle_t context, gtpin::resource_ return GTPIN_DI_SUCCESS; } -GTPIN_DI_STATUS gtpinUnmapBuffer(gtpin::context_handle_t context, gtpin::resource_handle_t resource) { +GTPIN_DI_STATUS gtpinUnmapBuffer(context_handle_t context, resource_handle_t resource) { cl_mem buffer = (cl_mem)resource; Context *pContext = castToObject((cl_context)context); if ((pContext == nullptr) || (buffer == nullptr)) { diff --git a/runtime/gtpin/gtpin_hw_helper.cpp b/runtime/gtpin/gtpin_hw_helper.cpp new file mode 100644 index 0000000000..9ec95693e2 --- /dev/null +++ b/runtime/gtpin/gtpin_hw_helper.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/gtpin/gtpin_hw_helper.h" + +namespace OCLRT { +GTPinHwHelper *gtpinHwHelperFactory[IGFX_MAX_CORE] = {}; + +GTPinHwHelper >PinHwHelper::get(GFXCORE_FAMILY gfxCore) { + return *gtpinHwHelperFactory[gfxCore]; +} +} // namespace OCLRT diff --git a/runtime/gtpin/gtpin_hw_helper.h b/runtime/gtpin/gtpin_hw_helper.h new file mode 100644 index 0000000000..752003d1cc --- /dev/null +++ b/runtime/gtpin/gtpin_hw_helper.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#include "runtime/gen_common/hw_cmds.h" + +namespace OCLRT { +class GTPinHwHelper { + public: + static GTPinHwHelper &get(GFXCORE_FAMILY gfxCore); + virtual uint32_t getGenVersion() = 0; + + protected: + GTPinHwHelper(){}; +}; + +template +class GTPinHwHelperHw : public GTPinHwHelper { + public: + static GTPinHwHelper &get() { + static GTPinHwHelperHw gtpinHwHelper; + return gtpinHwHelper; + } + uint32_t getGenVersion() override; + + private: + GTPinHwHelperHw(){}; +}; +} // namespace OCLRT diff --git a/runtime/gtpin/gtpin_init.cpp b/runtime/gtpin/gtpin_init.cpp index 102ab87358..dc754a0919 100644 --- a/runtime/gtpin/gtpin_init.cpp +++ b/runtime/gtpin/gtpin_init.cpp @@ -33,28 +33,17 @@ using namespace OCLRT; namespace OCLRT { bool isGTPinInitialized = false; +gtpin::dx11::gtpin_events_t GTPinCallbacks = {0}; } GTPIN_DI_STATUS GTPin_Init(gtpin::dx11::gtpin_events_t *pGtpinEvents, driver_services_t *pDriverServices, uint32_t *pDriverVersion) { - char ver[128] = {'\0'}; - uint32_t driverVersion = 0; - if (isGTPinInitialized) { return GTPIN_DI_ERROR_INSTANCE_ALREADY_CREATED; } if (pDriverVersion != nullptr) { - // GT-Pin is asking to obtain driver version - auto pPlatform = platform(); - Device *pDevice = pPlatform->getDevice(0); - pDevice->getDeviceInfo(CL_DRIVER_VERSION, sizeof(ver), &ver[0], nullptr); - uint32_t nums[3] = {0}; - int numVerSegments = sscanf(&ver[0], "%u.%u.%u", &nums[0], &nums[1], &nums[2]); - for (int verSeg = 0; verSeg < numVerSegments; verSeg++) { - driverVersion <<= 8; - driverVersion |= nums[verSeg]; - } - *pDriverVersion = driverVersion; + // GT-Pin is asking to obtain GT-Pin Interface version that is supported + *pDriverVersion = gtpin::dx11::GTPIN_DX11_INTERFACE_VERSION; if ((pDriverServices == nullptr) || (pGtpinEvents == nullptr)) { return GTPIN_DI_SUCCESS; @@ -78,6 +67,7 @@ GTPIN_DI_STATUS GTPin_Init(gtpin::dx11::gtpin_events_t *pGtpinEvents, driver_ser pDriverServices->bufferMap = OCLRT::gtpinMapBuffer; pDriverServices->bufferUnMap = OCLRT::gtpinUnmapBuffer; + GTPinCallbacks = *pGtpinEvents; isGTPinInitialized = true; return GTPIN_DI_SUCCESS; diff --git a/runtime/gtpin/gtpin_notify.h b/runtime/gtpin/gtpin_notify.h new file mode 100644 index 0000000000..059ccbd7d8 --- /dev/null +++ b/runtime/gtpin/gtpin_notify.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +namespace OCLRT { +void gtpinNotifyContextCreate(cl_context context); +void gtpinNotifyContextDestroy(cl_context context); +} diff --git a/runtime/gtpin/gtpin_setup_gen8.cpp b/runtime/gtpin/gtpin_setup_gen8.cpp new file mode 100644 index 0000000000..be6781ed33 --- /dev/null +++ b/runtime/gtpin/gtpin_setup_gen8.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "gtpin_dx11_interface.h" +#include "runtime/gtpin/gtpin_hw_helper.h" + +namespace OCLRT { + +extern GTPinHwHelper *gtpinHwHelperFactory[IGFX_MAX_CORE]; + +typedef BDWFamily Family; +static const auto gfxFamily = IGFX_GEN8_CORE; + +template <> +uint32_t GTPinHwHelperHw::getGenVersion() { + return gtpin::GTPIN_GEN_8; +} + +template class GTPinHwHelperHw; + +struct GTPinEnableGen8 { + GTPinEnableGen8() { + gtpinHwHelperFactory[gfxFamily] = >PinHwHelperHw::get(); + } +}; + +static GTPinEnableGen8 gtpinEnable; + +} // namespace OCLRT diff --git a/runtime/gtpin/gtpin_setup_gen9.cpp b/runtime/gtpin/gtpin_setup_gen9.cpp new file mode 100644 index 0000000000..1481f04b26 --- /dev/null +++ b/runtime/gtpin/gtpin_setup_gen9.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "gtpin_dx11_interface.h" +#include "runtime/gtpin/gtpin_hw_helper.h" + +namespace OCLRT { + +extern GTPinHwHelper *gtpinHwHelperFactory[IGFX_MAX_CORE]; + +typedef SKLFamily Family; +static const auto gfxFamily = IGFX_GEN9_CORE; + +template <> +uint32_t GTPinHwHelperHw::getGenVersion() { + return gtpin::GTPIN_GEN_9; +} + +template class GTPinHwHelperHw; + +struct GTPinEnableGen9 { + GTPinEnableGen9() { + gtpinHwHelperFactory[gfxFamily] = >PinHwHelperHw::get(); + } +}; + +static GTPinEnableGen9 gtpinEnable; + +} // namespace OCLRT diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 8094625748..37a7eebddf 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -179,6 +179,15 @@ foreach(GEN_NUM RANGE 0 ${MAX_GEN} 1) endif(${GENX_HAS_PLATFORMS}) endforeach(GEN_NUM) +if(GTPIN_HEADERS_DIR) + foreach(GEN_NUM RANGE ${MAX_GEN} 0 -1) + GEN_CONTAINS_PLATFORMS("SUPPORTED" ${GEN_NUM} GENX_HAS_PLATFORMS) + if(${GENX_HAS_PLATFORMS}) + list(APPEND IGDRCL_SRCS_tests ${IGDRCL_SOURCE_DIR}/runtime/gtpin/gtpin_setup_gen${GEN_NUM}.cpp) + endif(${GENX_HAS_PLATFORMS}) + endforeach(GEN_NUM) +endif(GTPIN_HEADERS_DIR) + add_executable(igdrcl_tests ${IGDRCL_SRCS_tests} $ diff --git a/unit_tests/api/cl_create_context_from_type_tests.cpp b/unit_tests/api/cl_create_context_from_type_tests.cpp index e81be4a9b1..e9b1e18ce7 100644 --- a/unit_tests/api/cl_create_context_from_type_tests.cpp +++ b/unit_tests/api/cl_create_context_from_type_tests.cpp @@ -79,4 +79,12 @@ TEST_F(clCreateContextFromTypeTests, noRet) { retVal = clReleaseContext(context); ASSERT_EQ(CL_SUCCESS, retVal); } + +TEST_F(clCreateContextFromTypeTests, givenInvalidContextCreationPropertiesThenContextCreationFails) { + cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0}; + auto context = clCreateContextFromType(invalidProperties, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal); + EXPECT_EQ(CL_INVALID_PLATFORM, retVal); + EXPECT_EQ(nullptr, context); +} + } // namespace ULT diff --git a/unit_tests/api/cl_create_context_tests.cpp b/unit_tests/api/cl_create_context_tests.cpp index cdb13fc3fc..56f2eb5bdc 100644 --- a/unit_tests/api/cl_create_context_tests.cpp +++ b/unit_tests/api/cl_create_context_tests.cpp @@ -94,4 +94,12 @@ TEST_F(clCreateContextTests, nullUserData) { retVal = clReleaseContext(context); EXPECT_EQ(CL_SUCCESS, retVal); } + +TEST_F(clCreateContextTests, givenInvalidContextCreationPropertiesThenContextCreationFails) { + cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0}; + auto context = clCreateContext(invalidProperties, num_devices, devices, nullptr, nullptr, &retVal); + EXPECT_EQ(CL_INVALID_PLATFORM, retVal); + EXPECT_EQ(nullptr, context); +} + } // namespace ULT diff --git a/unit_tests/gtpin/gtpin_tests.cpp b/unit_tests/gtpin/gtpin_tests.cpp index aa1774f041..32f2d516b7 100644 --- a/unit_tests/gtpin/gtpin_tests.cpp +++ b/unit_tests/gtpin/gtpin_tests.cpp @@ -43,10 +43,15 @@ extern bool isGTPinInitialized; namespace ULT { +int ContextCreateCallbackCount = 0; +int ContextDestroyCallbackCount = 0; + void OnContextCreate(context_handle_t context, platform_info_t *platformInfo, igc_init_t **igcInit) { + ContextCreateCallbackCount++; } void OnContextDestroy(context_handle_t context) { + ContextDestroyCallbackCount++; } void OnKernelCreate(context_handle_t context, const instrument_params_in_t *paramsIn, instrument_params_out_t *paramsOut) { @@ -100,6 +105,7 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture { ContextFixture::TearDown(); pPlatform->shutdown(); MemoryManagementFixture::TearDown(); + OCLRT::isGTPinInitialized = false; } Platform *pPlatform = nullptr; @@ -159,15 +165,15 @@ TEST_F(GTPinTests, givenInvalidArgumentsWhenVersionArgumentIsProvidedThenGTPinIn retFromGtPin = GTPin_Init(nullptr, nullptr, &ver); EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin); - EXPECT_NE(0u, ver); + EXPECT_EQ(gtpin::dx11::GTPIN_DX11_INTERFACE_VERSION, ver); retFromGtPin = GTPin_Init(>pinCallbacks, nullptr, &ver); EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin); - EXPECT_NE(0u, ver); + EXPECT_EQ(gtpin::dx11::GTPIN_DX11_INTERFACE_VERSION, ver); retFromGtPin = GTPin_Init(nullptr, &driverServices, &ver); EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin); - EXPECT_NE(0u, ver); + EXPECT_EQ(gtpin::dx11::GTPIN_DX11_INTERFACE_VERSION, ver); } TEST_F(GTPinTests, givenValidAndCompleteArgumentsThenGTPinInitSucceeds) { @@ -468,4 +474,78 @@ TEST_F(GTPinTests, givenValidArgumentsForBufferUnMapWhenCallSequenceIsCorrectThe EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin); } +TEST_F(GTPinTests, givenUninitializedGTPinInterfaceThenGTPinContextCallbackIsNotCalled) { + int prevCount = ContextCreateCallbackCount; + cl_device_id device = (cl_device_id)pDevice; + auto context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_NE(nullptr, context); + EXPECT_EQ(ContextCreateCallbackCount, prevCount); + + prevCount = ContextDestroyCallbackCount; + retVal = clReleaseContext(context); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(ContextDestroyCallbackCount, prevCount); +} + +TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenContextCreationArgumentsAreInvalidThenGTPinContextCallbackIsNotCalled) { + gtpinCallbacks.onContextCreate = OnContextCreate; + gtpinCallbacks.onContextDestroy = OnContextDestroy; + gtpinCallbacks.onKernelCreate = OnKernelCreate; + gtpinCallbacks.onDraw = OnDraw; + gtpinCallbacks.onKernelSubmit = OnKernelSubmit; + gtpinCallbacks.onCommandBufferCreate = OnCommandBufferCreate; + gtpinCallbacks.onCommandBufferSubmit = OnCommandBufferSubmit; + retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr); + EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin); + + int prevCount = ContextCreateCallbackCount; + cl_device_id device = (cl_device_id)pDevice; + cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0}; + auto contextZ = clCreateContext(invalidProperties, 1, &device, nullptr, nullptr, &retVal); + EXPECT_EQ(CL_INVALID_PLATFORM, retVal); + EXPECT_EQ(nullptr, contextZ); + EXPECT_EQ(ContextCreateCallbackCount, prevCount); + + contextZ = clCreateContextFromType(invalidProperties, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal); + EXPECT_EQ(CL_INVALID_PLATFORM, retVal); + EXPECT_EQ(nullptr, contextZ); + EXPECT_EQ(ContextCreateCallbackCount, prevCount); +} + +TEST_F(GTPinTests, givenInitializedGTPinInterfaceThenGTPinContextCallbackIsCalled) { + gtpinCallbacks.onContextCreate = OnContextCreate; + gtpinCallbacks.onContextDestroy = OnContextDestroy; + gtpinCallbacks.onKernelCreate = OnKernelCreate; + gtpinCallbacks.onDraw = OnDraw; + gtpinCallbacks.onKernelSubmit = OnKernelSubmit; + gtpinCallbacks.onCommandBufferCreate = OnCommandBufferCreate; + gtpinCallbacks.onCommandBufferSubmit = OnCommandBufferSubmit; + retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr); + EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin); + + int prevCount = ContextCreateCallbackCount; + cl_device_id device = (cl_device_id)pDevice; + auto context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_NE(nullptr, context); + EXPECT_EQ(ContextCreateCallbackCount, prevCount + 1); + + prevCount = ContextDestroyCallbackCount; + retVal = clReleaseContext(context); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(ContextDestroyCallbackCount, prevCount + 1); + + prevCount = ContextCreateCallbackCount; + context = clCreateContextFromType(nullptr, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_NE(nullptr, context); + EXPECT_EQ(ContextCreateCallbackCount, prevCount + 1); + + prevCount = ContextDestroyCallbackCount; + retVal = clReleaseContext(context); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(ContextDestroyCallbackCount, prevCount + 1); +} + } // namespace ULT