mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Reorganization directory structure [1/n]
Change-Id: Id1a94577437a4826a32411869f516fec20314ec0
This commit is contained in:
36
opencl/source/gtpin/CMakeLists.txt
Normal file
36
opencl/source/gtpin/CMakeLists.txt
Normal file
@ -0,0 +1,36 @@
|
||||
#
|
||||
# Copyright (C) 2018-2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(NOT DISABLED_GTPIN_SUPPORT)
|
||||
set(RUNTIME_SRCS_GTPIN
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_callbacks.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_helpers.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_helpers.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_hw_helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_hw_helper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_hw_helper.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_init.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_init.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_notify.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_defs.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(MSVC_DEF_ADDITIONAL_EXPORTS "${MSVC_DEF_ADDITIONAL_EXPORTS}\nGTPin_Init")
|
||||
endif()
|
||||
|
||||
else()
|
||||
set(RUNTIME_SRCS_GTPIN
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_callback_stubs.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gtpin_notify.h
|
||||
)
|
||||
endif()
|
||||
|
||||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_GTPIN})
|
||||
set_property(GLOBAL PROPERTY RUNTIME_SRCS_GTPIN ${RUNTIME_SRCS_GTPIN})
|
||||
set(MSVC_DEF_ADDITIONAL_EXPORTS "${MSVC_DEF_ADDITIONAL_EXPORTS}" PARENT_SCOPE)
|
55
opencl/source/gtpin/gtpin_callback_stubs.cpp
Normal file
55
opencl/source/gtpin/gtpin_callback_stubs.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "CL/cl.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace NEO {
|
||||
bool isGTPinInitialized = false;
|
||||
|
||||
void gtpinNotifyContextCreate(cl_context context) {
|
||||
}
|
||||
|
||||
void gtpinNotifyContextDestroy(cl_context context) {
|
||||
}
|
||||
|
||||
void gtpinNotifyKernelCreate(cl_kernel kernel) {
|
||||
}
|
||||
|
||||
void gtpinNotifyKernelSubmit(cl_kernel kernel, void *pCmdQueue) {
|
||||
}
|
||||
|
||||
void gtpinNotifyPreFlushTask(void *pCmdQueue) {
|
||||
}
|
||||
|
||||
void gtpinNotifyFlushTask(uint32_t flushedTaskCount) {
|
||||
}
|
||||
|
||||
void gtpinNotifyTaskCompletion(uint32_t completedTaskCount) {
|
||||
}
|
||||
|
||||
void gtpinNotifyMakeResident(void *pKernel, void *pCommandStreamReceiver) {
|
||||
}
|
||||
|
||||
void gtpinNotifyUpdateResidencyList(void *pKernel, void *pResidencyVector) {
|
||||
}
|
||||
|
||||
void gtpinNotifyPlatformShutdown() {
|
||||
}
|
||||
|
||||
void *gtpinGetIgcInit() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void setIgcInfo(const void *igcInfo) {
|
||||
}
|
||||
|
||||
const void *gtpinGetIgcInfo() {
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace NEO
|
234
opencl/source/gtpin/gtpin_callbacks.cpp
Normal file
234
opencl/source/gtpin/gtpin_callbacks.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/command_stream/command_stream_receiver.h"
|
||||
#include "core/memory_manager/surface.h"
|
||||
#include "core/utilities/spinlock.h"
|
||||
|
||||
#include "CL/cl.h"
|
||||
#include "command_queue/command_queue.h"
|
||||
#include "context/context.h"
|
||||
#include "device/cl_device.h"
|
||||
#include "device/device_info.h"
|
||||
#include "gtpin/gtpin_defs.h"
|
||||
#include "gtpin/gtpin_hw_helper.h"
|
||||
#include "gtpin/gtpin_notify.h"
|
||||
#include "kernel/kernel.h"
|
||||
#include "mem_obj/buffer.h"
|
||||
#include "ocl_igc_shared/gtpin/gtpin_ocl_interface.h"
|
||||
#include "program/program.h"
|
||||
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
using namespace gtpin;
|
||||
|
||||
namespace NEO {
|
||||
|
||||
extern gtpin::ocl::gtpin_events_t GTPinCallbacks;
|
||||
|
||||
igc_init_t *pIgcInit = nullptr;
|
||||
std::atomic<int> sequenceCount(1);
|
||||
CommandQueue *pCmdQueueForFlushTask = nullptr;
|
||||
std::deque<gtpinkexec_t> kernelExecQueue;
|
||||
SpinLock kernelExecQueueLock;
|
||||
|
||||
void gtpinNotifyContextCreate(cl_context context) {
|
||||
if (isGTPinInitialized) {
|
||||
platform_info_t gtpinPlatformInfo;
|
||||
auto pContext = castToObjectOrAbort<Context>(context);
|
||||
auto pDevice = pContext->getDevice(0);
|
||||
UNRECOVERABLE_IF(pDevice == nullptr);
|
||||
GFXCORE_FAMILY genFamily = pDevice->getHardwareInfo().platform.eRenderCoreFamily;
|
||||
GTPinHwHelper >pinHelper = GTPinHwHelper::get(genFamily);
|
||||
gtpinPlatformInfo.gen_version = (gtpin::GTPIN_GEN_VERSION)gtpinHelper.getGenVersion();
|
||||
gtpinPlatformInfo.device_id = static_cast<uint32_t>(pDevice->getHardwareInfo().platform.usDeviceID);
|
||||
(*GTPinCallbacks.onContextCreate)((context_handle_t)context, >pinPlatformInfo, &pIgcInit);
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyContextDestroy(cl_context context) {
|
||||
if (isGTPinInitialized) {
|
||||
(*GTPinCallbacks.onContextDestroy)((context_handle_t)context);
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyKernelCreate(cl_kernel kernel) {
|
||||
if (nullptr == kernel) {
|
||||
return;
|
||||
}
|
||||
if (isGTPinInitialized) {
|
||||
auto pKernel = castToObjectOrAbort<Kernel>(kernel);
|
||||
size_t gtpinBTI = pKernel->getNumberOfBindingTableStates();
|
||||
// Enlarge local copy of SSH by 1 SS
|
||||
auto &device = pKernel->getDevice();
|
||||
GFXCORE_FAMILY genFamily = device.getHardwareInfo().platform.eRenderCoreFamily;
|
||||
GTPinHwHelper >pinHelper = GTPinHwHelper::get(genFamily);
|
||||
if (!gtpinHelper.addSurfaceState(pKernel)) {
|
||||
// Kernel with no SSH or Kernel EM, not supported
|
||||
return;
|
||||
}
|
||||
if (pKernel->isKernelHeapSubstituted()) {
|
||||
// ISA for this kernel was already substituted
|
||||
return;
|
||||
}
|
||||
// Notify GT-Pin that new kernel was created
|
||||
Context *pContext = &(pKernel->getContext());
|
||||
cl_context context = (cl_context)pContext;
|
||||
auto &kernelInfo = pKernel->getKernelInfo();
|
||||
instrument_params_in_t paramsIn = {};
|
||||
|
||||
paramsIn.kernel_type = GTPIN_KERNEL_TYPE_CS;
|
||||
paramsIn.simd = (GTPIN_SIMD_WIDTH)kernelInfo.getMaxSimdSize();
|
||||
paramsIn.orig_kernel_binary = (uint8_t *)pKernel->getKernelHeap();
|
||||
paramsIn.orig_kernel_size = static_cast<uint32_t>(pKernel->getKernelHeapSize());
|
||||
paramsIn.buffer_type = GTPIN_BUFFER_BINDFULL;
|
||||
paramsIn.buffer_desc.BTI = static_cast<uint32_t>(gtpinBTI);
|
||||
paramsIn.igc_hash_id = kernelInfo.heapInfo.pKernelHeader->ShaderHashCode;
|
||||
paramsIn.kernel_name = (char *)kernelInfo.name.c_str();
|
||||
paramsIn.igc_info = kernelInfo.igcInfoForGtpin;
|
||||
paramsIn.debug_data = pKernel->getProgram()->getDebugData();
|
||||
paramsIn.debug_data_size = static_cast<uint32_t>(pKernel->getProgram()->getDebugDataSize());
|
||||
instrument_params_out_t paramsOut = {0};
|
||||
(*GTPinCallbacks.onKernelCreate)((context_handle_t)(cl_context)context, ¶msIn, ¶msOut);
|
||||
// Substitute ISA of created kernel with instrumented code
|
||||
pKernel->substituteKernelHeap(paramsOut.inst_kernel_binary, paramsOut.inst_kernel_size);
|
||||
pKernel->setKernelId(paramsOut.kernel_id);
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyKernelSubmit(cl_kernel kernel, void *pCmdQueue) {
|
||||
if (isGTPinInitialized) {
|
||||
auto pKernel = castToObjectOrAbort<Kernel>(kernel);
|
||||
if (pKernel->getSurfaceStateHeapSize() == 0) {
|
||||
// Kernel with no SSH, not supported
|
||||
return;
|
||||
}
|
||||
Context *pContext = &(pKernel->getContext());
|
||||
cl_context context = (cl_context)pContext;
|
||||
uint64_t kernelId = pKernel->getKernelId();
|
||||
command_buffer_handle_t commandBuffer = (command_buffer_handle_t)((uintptr_t)(sequenceCount++));
|
||||
uint32_t kernelOffset = 0;
|
||||
resource_handle_t resource = 0;
|
||||
// Notify GT-Pin that abstract "command buffer" was created
|
||||
(*GTPinCallbacks.onCommandBufferCreate)((context_handle_t)context, commandBuffer);
|
||||
// Notify GT-Pin that kernel was submited for execution
|
||||
(*GTPinCallbacks.onKernelSubmit)(commandBuffer, kernelId, &kernelOffset, &resource);
|
||||
// Create new record in Kernel Execution Queue describing submited kernel
|
||||
pKernel->setStartOffset(kernelOffset);
|
||||
gtpinkexec_t kExec;
|
||||
kExec.pKernel = pKernel;
|
||||
kExec.gtpinResource = (cl_mem)resource;
|
||||
kExec.commandBuffer = commandBuffer;
|
||||
kExec.pCommandQueue = (CommandQueue *)pCmdQueue;
|
||||
std::unique_lock<SpinLock> lock{kernelExecQueueLock};
|
||||
kernelExecQueue.push_back(kExec);
|
||||
lock.unlock();
|
||||
// Patch SSH[gtpinBTI] with GT-Pin resource
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
auto &device = pKernel->getDevice();
|
||||
GFXCORE_FAMILY genFamily = device.getHardwareInfo().platform.eRenderCoreFamily;
|
||||
GTPinHwHelper >pinHelper = GTPinHwHelper::get(genFamily);
|
||||
size_t gtpinBTI = pKernel->getNumberOfBindingTableStates() - 1;
|
||||
void *pSurfaceState = gtpinHelper.getSurfaceState(pKernel, gtpinBTI);
|
||||
cl_mem buffer = (cl_mem)resource;
|
||||
auto pBuffer = castToObjectOrAbort<Buffer>(buffer);
|
||||
pBuffer->setArgStateful(pSurfaceState, false, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyPreFlushTask(void *pCmdQueue) {
|
||||
if (isGTPinInitialized) {
|
||||
pCmdQueueForFlushTask = (CommandQueue *)pCmdQueue;
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyFlushTask(uint32_t flushedTaskCount) {
|
||||
if (isGTPinInitialized) {
|
||||
std::unique_lock<SpinLock> lock{kernelExecQueueLock};
|
||||
size_t numElems = kernelExecQueue.size();
|
||||
for (size_t n = 0; n < numElems; n++) {
|
||||
if ((kernelExecQueue[n].pCommandQueue == pCmdQueueForFlushTask) && !kernelExecQueue[n].isTaskCountValid) {
|
||||
// Update record in Kernel Execution Queue with kernel's TC
|
||||
kernelExecQueue[n].isTaskCountValid = true;
|
||||
kernelExecQueue[n].taskCount = flushedTaskCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pCmdQueueForFlushTask = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyTaskCompletion(uint32_t completedTaskCount) {
|
||||
if (isGTPinInitialized) {
|
||||
std::unique_lock<SpinLock> lock{kernelExecQueueLock};
|
||||
size_t numElems = kernelExecQueue.size();
|
||||
for (size_t n = 0; n < numElems;) {
|
||||
if (kernelExecQueue[n].isTaskCountValid && (kernelExecQueue[n].taskCount <= completedTaskCount)) {
|
||||
// Notify GT-Pin that execution of "command buffer" was completed
|
||||
(*GTPinCallbacks.onCommandBufferComplete)(kernelExecQueue[n].commandBuffer);
|
||||
// Remove kernel's record from Kernel Execution Queue
|
||||
kernelExecQueue.erase(kernelExecQueue.begin() + n);
|
||||
numElems--;
|
||||
} else {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyMakeResident(void *pKernel, void *pCSR) {
|
||||
if (isGTPinInitialized) {
|
||||
std::unique_lock<SpinLock> lock{kernelExecQueueLock};
|
||||
size_t numElems = kernelExecQueue.size();
|
||||
for (size_t n = 0; n < numElems; n++) {
|
||||
if ((kernelExecQueue[n].pKernel == pKernel) && !kernelExecQueue[n].isResourceResident && kernelExecQueue[n].gtpinResource) {
|
||||
// It's time for kernel to make resident its GT-Pin resource
|
||||
CommandStreamReceiver *pCommandStreamReceiver = reinterpret_cast<CommandStreamReceiver *>(pCSR);
|
||||
cl_mem gtpinBuffer = kernelExecQueue[n].gtpinResource;
|
||||
auto pBuffer = castToObjectOrAbort<Buffer>(gtpinBuffer);
|
||||
GraphicsAllocation *pGfxAlloc = pBuffer->getGraphicsAllocation();
|
||||
pCommandStreamReceiver->makeResident(*pGfxAlloc);
|
||||
kernelExecQueue[n].isResourceResident = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyUpdateResidencyList(void *pKernel, void *pResVec) {
|
||||
if (isGTPinInitialized) {
|
||||
std::unique_lock<SpinLock> lock{kernelExecQueueLock};
|
||||
size_t numElems = kernelExecQueue.size();
|
||||
for (size_t n = 0; n < numElems; n++) {
|
||||
if ((kernelExecQueue[n].pKernel == pKernel) && !kernelExecQueue[n].isResourceResident && kernelExecQueue[n].gtpinResource) {
|
||||
// It's time for kernel to update its residency list with its GT-Pin resource
|
||||
std::vector<Surface *> *pResidencyVector = (std::vector<Surface *> *)pResVec;
|
||||
cl_mem gtpinBuffer = kernelExecQueue[n].gtpinResource;
|
||||
auto pBuffer = castToObjectOrAbort<Buffer>(gtpinBuffer);
|
||||
GraphicsAllocation *pGfxAlloc = pBuffer->getGraphicsAllocation();
|
||||
GeneralSurface *pSurface = new GeneralSurface(pGfxAlloc);
|
||||
pResidencyVector->push_back(pSurface);
|
||||
kernelExecQueue[n].isResourceResident = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gtpinNotifyPlatformShutdown() {
|
||||
if (isGTPinInitialized) {
|
||||
// Clear Kernel Execution Queue
|
||||
kernelExecQueue.clear();
|
||||
}
|
||||
}
|
||||
void *gtpinGetIgcInit() {
|
||||
return pIgcInit;
|
||||
}
|
||||
} // namespace NEO
|
36
opencl/source/gtpin/gtpin_defs.h
Normal file
36
opencl/source/gtpin/gtpin_defs.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "CL/cl.h"
|
||||
#include "command_queue/command_queue.h"
|
||||
#include "kernel/kernel.h"
|
||||
#include "ocl_igc_shared/gtpin/gtpin_ocl_interface.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
struct GTPinKernelExec {
|
||||
Kernel *pKernel;
|
||||
cl_mem gtpinResource;
|
||||
CommandQueue *pCommandQueue;
|
||||
gtpin::command_buffer_handle_t commandBuffer;
|
||||
uint32_t taskCount;
|
||||
bool isTaskCountValid;
|
||||
bool isResourceResident;
|
||||
|
||||
GTPinKernelExec() {
|
||||
pKernel = nullptr;
|
||||
gtpinResource = nullptr;
|
||||
pCommandQueue = nullptr;
|
||||
commandBuffer = nullptr;
|
||||
taskCount = 0;
|
||||
isTaskCountValid = false;
|
||||
isResourceResident = false;
|
||||
}
|
||||
};
|
||||
typedef struct GTPinKernelExec gtpinkexec_t;
|
||||
|
||||
} // namespace NEO
|
79
opencl/source/gtpin/gtpin_helpers.cpp
Normal file
79
opencl/source/gtpin/gtpin_helpers.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gtpin_helpers.h"
|
||||
|
||||
#include "core/memory_manager/memory_manager.h"
|
||||
|
||||
#include "CL/cl.h"
|
||||
#include "context/context.h"
|
||||
#include "helpers/validators.h"
|
||||
#include "mem_obj/buffer.h"
|
||||
#include "ocl_igc_shared/gtpin/gtpin_ocl_interface.h"
|
||||
|
||||
using namespace gtpin;
|
||||
|
||||
namespace NEO {
|
||||
|
||||
GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinCreateBuffer(context_handle_t context, uint32_t reqSize, resource_handle_t *pResource) {
|
||||
cl_int diag = CL_SUCCESS;
|
||||
Context *pContext = castToObject<Context>((cl_context)context);
|
||||
if ((pContext == nullptr) || (pResource == nullptr)) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
size_t size = alignUp(reqSize, MemoryConstants::cacheLineSize);
|
||||
void *hostPtr = pContext->getMemoryManager()->allocateSystemMemory(size, MemoryConstants::pageSize);
|
||||
if (hostPtr == nullptr) {
|
||||
return GTPIN_DI_ERROR_ALLOCATION_FAILED;
|
||||
}
|
||||
cl_mem buffer = Buffer::create(pContext, CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE | CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL, size, hostPtr, diag);
|
||||
*pResource = (resource_handle_t)buffer;
|
||||
return GTPIN_DI_SUCCESS;
|
||||
}
|
||||
|
||||
GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV 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)) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
auto pMemObj = castToObject<MemObj>(buffer);
|
||||
if (pMemObj == nullptr) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
alignedFree(pMemObj->getHostPtr());
|
||||
pMemObj->release();
|
||||
return GTPIN_DI_SUCCESS;
|
||||
}
|
||||
|
||||
GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV 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)) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
auto pMemObj = castToObject<MemObj>(buffer);
|
||||
if (pMemObj == nullptr) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
*pAddress = (uint8_t *)pMemObj->getHostPtr();
|
||||
return GTPIN_DI_SUCCESS;
|
||||
}
|
||||
|
||||
GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV 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)) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
auto pMemObj = castToObject<MemObj>(buffer);
|
||||
if (pMemObj == nullptr) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
return GTPIN_DI_SUCCESS;
|
||||
}
|
||||
} // namespace NEO
|
17
opencl/source/gtpin/gtpin_helpers.h
Normal file
17
opencl/source/gtpin/gtpin_helpers.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ocl_igc_shared/gtpin/gtpin_driver_common.h"
|
||||
|
||||
namespace NEO {
|
||||
gtpin::GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinCreateBuffer(gtpin::context_handle_t context, uint32_t size, gtpin::resource_handle_t *pResource);
|
||||
gtpin::GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinFreeBuffer(gtpin::context_handle_t context, gtpin::resource_handle_t resource);
|
||||
gtpin::GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinMapBuffer(gtpin::context_handle_t context, gtpin::resource_handle_t resource, uint8_t **pAddress);
|
||||
gtpin::GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinUnmapBuffer(gtpin::context_handle_t context, gtpin::resource_handle_t resource);
|
||||
} // namespace NEO
|
16
opencl/source/gtpin/gtpin_hw_helper.cpp
Normal file
16
opencl/source/gtpin/gtpin_hw_helper.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gtpin/gtpin_hw_helper.h"
|
||||
|
||||
namespace NEO {
|
||||
GTPinHwHelper *gtpinHwHelperFactory[IGFX_MAX_CORE] = {};
|
||||
|
||||
GTPinHwHelper >PinHwHelper::get(GFXCORE_FAMILY gfxCore) {
|
||||
return *gtpinHwHelperFactory[gfxCore];
|
||||
}
|
||||
} // namespace NEO
|
39
opencl/source/gtpin/gtpin_hw_helper.h
Normal file
39
opencl/source/gtpin/gtpin_hw_helper.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "core/helpers/hw_cmds.h"
|
||||
|
||||
namespace NEO {
|
||||
class Kernel;
|
||||
|
||||
class GTPinHwHelper {
|
||||
public:
|
||||
static GTPinHwHelper &get(GFXCORE_FAMILY gfxCore);
|
||||
virtual uint32_t getGenVersion() = 0;
|
||||
virtual bool addSurfaceState(Kernel *pKernel) = 0;
|
||||
virtual void *getSurfaceState(Kernel *pKernel, size_t bti) = 0;
|
||||
|
||||
protected:
|
||||
GTPinHwHelper(){};
|
||||
};
|
||||
|
||||
template <typename GfxFamily>
|
||||
class GTPinHwHelperHw : public GTPinHwHelper {
|
||||
public:
|
||||
static GTPinHwHelper &get() {
|
||||
static GTPinHwHelperHw<GfxFamily> gtpinHwHelper;
|
||||
return gtpinHwHelper;
|
||||
}
|
||||
uint32_t getGenVersion() override;
|
||||
bool addSurfaceState(Kernel *pKernel) override;
|
||||
void *getSurfaceState(Kernel *pKernel, size_t bti) override;
|
||||
|
||||
private:
|
||||
GTPinHwHelperHw(){};
|
||||
};
|
||||
} // namespace NEO
|
58
opencl/source/gtpin/gtpin_hw_helper.inl
Normal file
58
opencl/source/gtpin/gtpin_hw_helper.inl
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/helpers/hw_cmds.h"
|
||||
#include "core/helpers/string.h"
|
||||
|
||||
#include "gtpin/gtpin_hw_helper.h"
|
||||
#include "kernel/kernel.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
template <typename GfxFamily>
|
||||
bool GTPinHwHelperHw<GfxFamily>::addSurfaceState(Kernel *pKernel) {
|
||||
using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE;
|
||||
using BINDING_TABLE_STATE = typename GfxFamily::BINDING_TABLE_STATE;
|
||||
|
||||
size_t sshSize = pKernel->getSurfaceStateHeapSize();
|
||||
if ((sshSize == 0) || pKernel->isParentKernel) {
|
||||
// Kernels which do not use SSH or use Execution Model are not supported (yet)
|
||||
return false;
|
||||
}
|
||||
size_t ssSize = sizeof(RENDER_SURFACE_STATE);
|
||||
size_t btsSize = sizeof(BINDING_TABLE_STATE);
|
||||
size_t sizeToEnlarge = ssSize + btsSize;
|
||||
size_t currBTOffset = pKernel->getBindingTableOffset();
|
||||
size_t currSurfaceStateSize = currBTOffset;
|
||||
char *pSsh = static_cast<char *>(pKernel->getSurfaceStateHeap());
|
||||
char *pNewSsh = new char[sshSize + sizeToEnlarge];
|
||||
memcpy_s(pNewSsh, sshSize + sizeToEnlarge, pSsh, currSurfaceStateSize);
|
||||
RENDER_SURFACE_STATE *pSS = reinterpret_cast<RENDER_SURFACE_STATE *>(pNewSsh + currSurfaceStateSize);
|
||||
*pSS = GfxFamily::cmdInitRenderSurfaceState;
|
||||
size_t newSurfaceStateSize = currSurfaceStateSize + ssSize;
|
||||
size_t currBTCount = pKernel->getNumberOfBindingTableStates();
|
||||
memcpy_s(pNewSsh + newSurfaceStateSize, sshSize + sizeToEnlarge - newSurfaceStateSize, pSsh + currBTOffset, currBTCount * btsSize);
|
||||
BINDING_TABLE_STATE *pNewBTS = reinterpret_cast<BINDING_TABLE_STATE *>(pNewSsh + newSurfaceStateSize + currBTCount * btsSize);
|
||||
*pNewBTS = GfxFamily::cmdInitBindingTableState;
|
||||
pNewBTS->setSurfaceStatePointer((uint64_t)currBTOffset);
|
||||
pKernel->resizeSurfaceStateHeap(pNewSsh, sshSize + sizeToEnlarge, currBTCount + 1, newSurfaceStateSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
void *GTPinHwHelperHw<GfxFamily>::getSurfaceState(Kernel *pKernel, size_t bti) {
|
||||
using BINDING_TABLE_STATE = typename GfxFamily::BINDING_TABLE_STATE;
|
||||
|
||||
if ((nullptr == pKernel->getSurfaceStateHeap()) || (bti >= pKernel->getNumberOfBindingTableStates())) {
|
||||
return nullptr;
|
||||
}
|
||||
auto *pBts = reinterpret_cast<BINDING_TABLE_STATE *>(ptrOffset(pKernel->getSurfaceStateHeap(), (pKernel->getBindingTableOffset() + bti * sizeof(BINDING_TABLE_STATE))));
|
||||
auto pSurfaceState = ptrOffset(pKernel->getSurfaceStateHeap(), pBts->getSurfaceStatePointer());
|
||||
return pSurfaceState;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
60
opencl/source/gtpin/gtpin_init.cpp
Normal file
60
opencl/source/gtpin/gtpin_init.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gtpin_init.h"
|
||||
|
||||
#include "core/device/device.h"
|
||||
|
||||
#include "CL/cl.h"
|
||||
#include "device/device_info.h"
|
||||
#include "gtpin_helpers.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
using namespace gtpin;
|
||||
using namespace NEO;
|
||||
|
||||
namespace NEO {
|
||||
bool isGTPinInitialized = false;
|
||||
gtpin::ocl::gtpin_events_t GTPinCallbacks = {0};
|
||||
} // namespace NEO
|
||||
|
||||
GTPIN_DI_STATUS GTPin_Init(gtpin::ocl::gtpin_events_t *pGtpinEvents, driver_services_t *pDriverServices,
|
||||
interface_version_t *pDriverVersion) {
|
||||
if (isGTPinInitialized) {
|
||||
return GTPIN_DI_ERROR_INSTANCE_ALREADY_CREATED;
|
||||
}
|
||||
if (pDriverVersion != nullptr) {
|
||||
// GT-Pin is asking to obtain GT-Pin Interface version that is supported
|
||||
pDriverVersion->common = gtpin::GTPIN_COMMON_INTERFACE_VERSION;
|
||||
pDriverVersion->specific = gtpin::ocl::GTPIN_OCL_INTERFACE_VERSION;
|
||||
|
||||
if ((pDriverServices == nullptr) || (pGtpinEvents == nullptr)) {
|
||||
return GTPIN_DI_SUCCESS;
|
||||
}
|
||||
}
|
||||
if ((pDriverServices == nullptr) || (pGtpinEvents == nullptr)) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
if ((pGtpinEvents->onContextCreate == nullptr) ||
|
||||
(pGtpinEvents->onContextDestroy == nullptr) ||
|
||||
(pGtpinEvents->onKernelCreate == nullptr) ||
|
||||
(pGtpinEvents->onKernelSubmit == nullptr) ||
|
||||
(pGtpinEvents->onCommandBufferCreate == nullptr) ||
|
||||
(pGtpinEvents->onCommandBufferComplete == nullptr)) {
|
||||
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
pDriverServices->bufferAllocate = NEO::gtpinCreateBuffer;
|
||||
pDriverServices->bufferDeallocate = NEO::gtpinFreeBuffer;
|
||||
pDriverServices->bufferMap = NEO::gtpinMapBuffer;
|
||||
pDriverServices->bufferUnMap = NEO::gtpinUnmapBuffer;
|
||||
|
||||
GTPinCallbacks = *pGtpinEvents;
|
||||
isGTPinInitialized = true;
|
||||
|
||||
return GTPIN_DI_SUCCESS;
|
||||
}
|
20
opencl/source/gtpin/gtpin_init.h
Normal file
20
opencl/source/gtpin/gtpin_init.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ocl_igc_shared/gtpin/gtpin_ocl_interface.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
gtpin::GTPIN_DI_STATUS GTPin_Init(gtpin::ocl::gtpin_events_t *pGtpinEvents, gtpin::driver_services_t *pDriverServices, gtpin::interface_version_t *pDriverVersion);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
29
opencl/source/gtpin/gtpin_notify.h
Normal file
29
opencl/source/gtpin/gtpin_notify.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CL/cl.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace NEO {
|
||||
extern bool isGTPinInitialized;
|
||||
|
||||
void gtpinNotifyContextCreate(cl_context context);
|
||||
void gtpinNotifyContextDestroy(cl_context context);
|
||||
void gtpinNotifyKernelCreate(cl_kernel kernel);
|
||||
void gtpinNotifyKernelSubmit(cl_kernel kernel, void *pCmdQueue);
|
||||
void gtpinNotifyPreFlushTask(void *pCmdQueue);
|
||||
void gtpinNotifyFlushTask(uint32_t flushedTaskCount);
|
||||
void gtpinNotifyTaskCompletion(uint32_t completedTaskCount);
|
||||
void gtpinNotifyMakeResident(void *pKernel, void *pCommandStreamReceiver);
|
||||
void gtpinNotifyUpdateResidencyList(void *pKernel, void *pResidencyVector);
|
||||
void gtpinNotifyPlatformShutdown();
|
||||
inline bool gtpinIsGTPinInitialized() { return isGTPinInitialized; }
|
||||
void *gtpinGetIgcInit();
|
||||
} // namespace NEO
|
Reference in New Issue
Block a user