Add support for GT-Pin Callbacks [1/n]

- Also fixes bug when returning version of supported GT-Pin interface

Change-Id: Ib471a11a3b51d69240dcd2f800a8e28eefdeed57
This commit is contained in:
hjnapiat
2018-01-03 10:54:31 +01:00
committed by sys_ocldev
parent 11e7a5f1d9
commit 17c6142191
16 changed files with 435 additions and 24 deletions

View File

@ -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) {
}
}

View File

@ -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 &gtpinHelper = GTPinHwHelper::get(genFamily);
gtpinPlatformInfo.gen_version = (gtpin::GTPIN_GEN_VERSION)gtpinHelper.getGenVersion();
gtpinPlatformInfo.device_id = static_cast<uint32_t>(pDevice->getHardwareInfo().pPlatform->usDeviceID);
(*GTPinCallbacks.onContextCreate)((context_handle_t)context, &gtpinPlatformInfo, &pIgcInfo);
}
}
void gtpinNotifyContextDestroy(cl_context context) {
if (isGTPinInitialized) {
(*GTPinCallbacks.onContextDestroy)((context_handle_t)context);
}
}
}

View File

@ -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<Context>((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<Context>((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<Context>((cl_context)context);
if ((pContext == nullptr) || (buffer == nullptr)) {

View File

@ -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 &GTPinHwHelper::get(GFXCORE_FAMILY gfxCore) {
return *gtpinHwHelperFactory[gfxCore];
}
} // namespace OCLRT

View File

@ -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 <typename GfxFamily>
class GTPinHwHelperHw : public GTPinHwHelper {
public:
static GTPinHwHelper &get() {
static GTPinHwHelperHw<GfxFamily> gtpinHwHelper;
return gtpinHwHelper;
}
uint32_t getGenVersion() override;
private:
GTPinHwHelperHw(){};
};
} // namespace OCLRT

View File

@ -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;

View File

@ -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);
}

View File

@ -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<Family>::getGenVersion() {
return gtpin::GTPIN_GEN_8;
}
template class GTPinHwHelperHw<Family>;
struct GTPinEnableGen8 {
GTPinEnableGen8() {
gtpinHwHelperFactory[gfxFamily] = &GTPinHwHelperHw<Family>::get();
}
};
static GTPinEnableGen8 gtpinEnable;
} // namespace OCLRT

View File

@ -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<Family>::getGenVersion() {
return gtpin::GTPIN_GEN_9;
}
template class GTPinHwHelperHw<Family>;
struct GTPinEnableGen9 {
GTPinEnableGen9() {
gtpinHwHelperFactory[gfxFamily] = &GTPinHwHelperHw<Family>::get();
}
};
static GTPinEnableGen9 gtpinEnable;
} // namespace OCLRT