mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Initial commit
Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
345
runtime/context/context.cpp
Normal file
345
runtime/context/context.cpp
Normal file
@ -0,0 +1,345 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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/context/context.h"
|
||||
#include "runtime/helpers/surface_formats.h"
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/device_queue/device_queue.h"
|
||||
#include "runtime/mem_obj/image.h"
|
||||
#include "runtime/helpers/get_info.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/platform/platform.h"
|
||||
#include "runtime/helpers/string.h"
|
||||
#include "runtime/command_queue/command_queue.h"
|
||||
#include "runtime/built_ins/built_ins.h"
|
||||
#include "runtime/compiler_interface/compiler_interface.h"
|
||||
#include "runtime/memory_manager/svm_memory_manager.h"
|
||||
#include "runtime/memory_manager/deferred_deleter.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
#include "runtime/sharings/sharing_factory.h"
|
||||
#include "runtime/sharings/sharing.h"
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include "d3d_sharing_functions.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
Context::Context(
|
||||
void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *),
|
||||
void *data) {
|
||||
properties = nullptr;
|
||||
numProperties = 0;
|
||||
contextCallback = funcNotify;
|
||||
userData = data;
|
||||
memoryManager = nullptr;
|
||||
specialQueue = nullptr;
|
||||
defaultDeviceQueue = nullptr;
|
||||
driverDiagnostics = nullptr;
|
||||
sharingFunctions.resize(SharingType::MAX_SHARING_VALUE);
|
||||
}
|
||||
|
||||
Context::~Context() {
|
||||
delete[] properties;
|
||||
if (specialQueue) {
|
||||
delete specialQueue;
|
||||
}
|
||||
if (svmAllocsManager) {
|
||||
delete svmAllocsManager;
|
||||
}
|
||||
if (driverDiagnostics) {
|
||||
delete driverDiagnostics;
|
||||
}
|
||||
if (memoryManager && memoryManager->isAsyncDeleterEnabled()) {
|
||||
memoryManager->getDeferredDeleter()->removeClient();
|
||||
}
|
||||
}
|
||||
|
||||
DeviceQueue *Context::getDefaultDeviceQueue() {
|
||||
return defaultDeviceQueue;
|
||||
}
|
||||
|
||||
void Context::setDefaultDeviceQueue(DeviceQueue *queue) {
|
||||
defaultDeviceQueue = queue;
|
||||
}
|
||||
|
||||
CommandQueue *Context::getSpecialQueue() {
|
||||
return specialQueue;
|
||||
}
|
||||
|
||||
void Context::setSpecialQueue(CommandQueue *commandQueue) {
|
||||
specialQueue = commandQueue;
|
||||
if (commandQueue) {
|
||||
decRefInternal();
|
||||
} else {
|
||||
incRefInternal();
|
||||
}
|
||||
};
|
||||
|
||||
bool Context::isSpecialQueue(CommandQueue *commandQueue) {
|
||||
return specialQueue == commandQueue;
|
||||
};
|
||||
|
||||
void Context::deleteSpecialQueue() {
|
||||
if (specialQueue) {
|
||||
delete specialQueue;
|
||||
specialQueue = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Context::createImpl(const cl_context_properties *properties,
|
||||
const DeviceVector &devices,
|
||||
void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *),
|
||||
void *data, cl_int &errcodeRet) {
|
||||
|
||||
auto propertiesCurrent = properties;
|
||||
bool interopUserSync = false;
|
||||
auto sharingBuilder = sharingFactory.build();
|
||||
|
||||
std::unique_ptr<DriverDiagnostics> driverDiagnostics;
|
||||
while (propertiesCurrent && *propertiesCurrent) {
|
||||
errcodeRet = CL_SUCCESS;
|
||||
|
||||
auto propertyType = propertiesCurrent[0];
|
||||
auto propertyValue = propertiesCurrent[1];
|
||||
propertiesCurrent += 2;
|
||||
|
||||
switch (propertyType) {
|
||||
case CL_CONTEXT_PLATFORM: {
|
||||
cl_platform_id pid = platform();
|
||||
if (reinterpret_cast<cl_platform_id>(propertyValue) != pid) {
|
||||
errcodeRet = CL_INVALID_PLATFORM;
|
||||
}
|
||||
} break;
|
||||
case CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL:
|
||||
driverDiagnostics.reset(new DriverDiagnostics((cl_diagnostics_verbose_level)propertyValue));
|
||||
break;
|
||||
case CL_CONTEXT_INTEROP_USER_SYNC:
|
||||
interopUserSync = propertyValue > 0;
|
||||
break;
|
||||
default:
|
||||
if (!sharingBuilder->processProperties(propertyType, propertyValue, errcodeRet)) {
|
||||
errcodeRet = createContextOsProperties(propertyType, propertyValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto numProperties = ptrDiff(propertiesCurrent, properties) / sizeof(cl_context_properties);
|
||||
cl_context_properties *propertiesNew = nullptr;
|
||||
|
||||
// copy the user properties if there are any
|
||||
if (numProperties) {
|
||||
propertiesNew = new cl_context_properties[numProperties + 1];
|
||||
memcpy_s(propertiesNew, (numProperties + 1) * sizeof(cl_context_properties), properties, numProperties * sizeof(cl_context_properties));
|
||||
propertiesNew[numProperties] = 0;
|
||||
numProperties++;
|
||||
}
|
||||
|
||||
this->numProperties = numProperties;
|
||||
this->properties = propertiesNew;
|
||||
this->devices = devices;
|
||||
this->setInteropUserSyncEnabled(interopUserSync);
|
||||
|
||||
if (!sharingBuilder->finalizeProperties(*this, errcodeRet)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->driverDiagnostics = driverDiagnostics.release();
|
||||
|
||||
// We currently assume each device uses the same MemoryManager
|
||||
if (devices.size() > 0) {
|
||||
this->memoryManager = this->getDevice(0)->getMemoryManager();
|
||||
this->svmAllocsManager = new SVMAllocsManager(this->memoryManager);
|
||||
this->eventsRegistry.setDevice(this->getDevice(0));
|
||||
if (memoryManager->isAsyncDeleterEnabled()) {
|
||||
memoryManager->getDeferredDeleter()->addClient();
|
||||
}
|
||||
}
|
||||
|
||||
auto commandQueue = CommandQueue::create(this, devices[0], nullptr, errcodeRet);
|
||||
DEBUG_BREAK_IF(commandQueue == nullptr);
|
||||
|
||||
setSpecialQueue(commandQueue);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
cl_int Context::getInfo(cl_context_info paramName, size_t paramValueSize,
|
||||
void *paramValue, size_t *paramValueSizeRet) {
|
||||
cl_int retVal;
|
||||
size_t valueSize = 0;
|
||||
const void *pValue = nullptr;
|
||||
cl_uint numDevices;
|
||||
cl_uint refCount = 0;
|
||||
std::vector<cl_device_id> devIDs;
|
||||
auto callGetinfo = true;
|
||||
|
||||
switch (paramName) {
|
||||
case CL_CONTEXT_DEVICES:
|
||||
valueSize = devices.size() * sizeof(cl_device_id);
|
||||
devices.toDeviceIDs(devIDs);
|
||||
pValue = devIDs.data();
|
||||
break;
|
||||
|
||||
case CL_CONTEXT_NUM_DEVICES:
|
||||
numDevices = (cl_uint)(devices.size());
|
||||
valueSize = sizeof(numDevices);
|
||||
pValue = &numDevices;
|
||||
break;
|
||||
|
||||
case CL_CONTEXT_PROPERTIES:
|
||||
valueSize = this->numProperties * sizeof(cl_context_properties);
|
||||
pValue = this->properties;
|
||||
if (valueSize == 0) {
|
||||
callGetinfo = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CL_CONTEXT_REFERENCE_COUNT:
|
||||
refCount = static_cast<cl_uint>(this->getReference());
|
||||
valueSize = sizeof(refCount);
|
||||
pValue = &refCount;
|
||||
break;
|
||||
|
||||
default:
|
||||
pValue = getOsContextInfo(paramName, &valueSize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (callGetinfo) {
|
||||
retVal = ::getInfo(paramValue, paramValueSize, pValue, valueSize);
|
||||
} else {
|
||||
retVal = CL_SUCCESS;
|
||||
}
|
||||
|
||||
if (paramValueSizeRet) {
|
||||
*paramValueSizeRet = valueSize;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
size_t Context::getNumDevices() const {
|
||||
return devices.size();
|
||||
}
|
||||
|
||||
Device *Context::getDevice(size_t deviceOrdinal) {
|
||||
return (Device *)devices[deviceOrdinal];
|
||||
}
|
||||
|
||||
cl_int Context::getSupportedImageFormats(
|
||||
Device *device,
|
||||
cl_mem_flags flags,
|
||||
cl_mem_object_type imageType,
|
||||
cl_uint numEntries,
|
||||
cl_image_format *imageFormats,
|
||||
cl_uint *numImageFormatsReturned) {
|
||||
|
||||
cl_uint numImageFormats = 0;
|
||||
cl_uint numDepthFormats = 0;
|
||||
const SurfaceFormatInfo *surfaceFormats = nullptr;
|
||||
const SurfaceFormatInfo *depthFormats = nullptr;
|
||||
|
||||
const bool nv12ExtensionEnabled = device->getDeviceInfo().nv12Extension;
|
||||
const bool packedYuvExtensionEnabled = device->getDeviceInfo().packedYuvExtension;
|
||||
bool appendPlanarYUVSurfaces = false;
|
||||
bool appendPackedYUVSurfaces = false;
|
||||
bool appendDepthSurfaces = true;
|
||||
|
||||
if (flags & CL_MEM_READ_ONLY) {
|
||||
numImageFormats = static_cast<cl_uint>(numReadOnlySurfaceFormats);
|
||||
surfaceFormats = readOnlySurfaceFormats;
|
||||
depthFormats = readOnlyDepthSurfaceFormats;
|
||||
numDepthFormats = static_cast<cl_uint>(numReadOnlyDepthSurfaceFormats);
|
||||
appendPlanarYUVSurfaces = true;
|
||||
appendPackedYUVSurfaces = true;
|
||||
} else if (flags & CL_MEM_WRITE_ONLY) {
|
||||
numImageFormats = static_cast<cl_uint>(numWriteOnlySurfaceFormats);
|
||||
surfaceFormats = writeOnlySurfaceFormats;
|
||||
depthFormats = readWriteDepthSurfaceFormats;
|
||||
numDepthFormats = static_cast<cl_uint>(numReadWriteDepthSurfaceFormats);
|
||||
} else if (nv12ExtensionEnabled && (flags & CL_MEM_NO_ACCESS_INTEL)) {
|
||||
numImageFormats = static_cast<cl_uint>(numReadOnlySurfaceFormats);
|
||||
surfaceFormats = readOnlySurfaceFormats;
|
||||
appendPlanarYUVSurfaces = true;
|
||||
} else {
|
||||
numImageFormats = static_cast<cl_uint>(numReadWriteSurfaceFormats);
|
||||
surfaceFormats = readWriteSurfaceFormats;
|
||||
depthFormats = readWriteDepthSurfaceFormats;
|
||||
numDepthFormats = static_cast<cl_uint>(numReadWriteDepthSurfaceFormats);
|
||||
}
|
||||
|
||||
if (!Image::isImage2d(imageType)) {
|
||||
appendPlanarYUVSurfaces = false;
|
||||
appendPackedYUVSurfaces = false;
|
||||
}
|
||||
if (!Image::isImage2dOr2dArray(imageType)) {
|
||||
appendDepthSurfaces = false;
|
||||
}
|
||||
|
||||
if (imageFormats) {
|
||||
numImageFormats = std::min(numEntries, numImageFormats);
|
||||
|
||||
cl_uint entry = 0;
|
||||
for (entry = 0; entry < numImageFormats; ++entry) {
|
||||
imageFormats[entry] = surfaceFormats[entry].OCLImageFormat;
|
||||
}
|
||||
|
||||
if (nv12ExtensionEnabled && appendPlanarYUVSurfaces) {
|
||||
for (uint32_t planarEntry = 0; planarEntry < numPlanarYuvSurfaceFormats && (entry < numEntries); ++planarEntry, ++entry) {
|
||||
imageFormats[entry] = planarYuvSurfaceFormats[planarEntry].OCLImageFormat;
|
||||
}
|
||||
}
|
||||
|
||||
if (appendDepthSurfaces) {
|
||||
for (uint32_t depthEntry = 0; depthEntry < numDepthFormats && (entry < numEntries); ++depthEntry, ++entry) {
|
||||
imageFormats[entry] = depthFormats[depthEntry].OCLImageFormat;
|
||||
}
|
||||
}
|
||||
|
||||
if (packedYuvExtensionEnabled && appendPackedYUVSurfaces) {
|
||||
for (uint32_t packedEntry = 0; packedEntry < numPackedYuvSurfaceFormats && (entry < numEntries); ++packedEntry, ++entry) {
|
||||
imageFormats[entry] = packedYuvSurfaceFormats[packedEntry].OCLImageFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numImageFormatsReturned) {
|
||||
if (nv12ExtensionEnabled && appendPlanarYUVSurfaces) {
|
||||
numImageFormats += static_cast<cl_uint>(numPlanarYuvSurfaceFormats);
|
||||
}
|
||||
if (packedYuvExtensionEnabled && appendPackedYUVSurfaces) {
|
||||
numImageFormats += static_cast<cl_uint>(numPackedYuvSurfaceFormats);
|
||||
}
|
||||
if (appendDepthSurfaces) {
|
||||
numImageFormats += numDepthFormats;
|
||||
}
|
||||
|
||||
*numImageFormatsReturned = numImageFormats;
|
||||
}
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
} // namespace OCLRT
|
151
runtime/context/context.h
Normal file
151
runtime/context/context.h
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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/device/device_vector.h"
|
||||
#include "runtime/event/event.h"
|
||||
#include "runtime/event/event_registry.h"
|
||||
#include "runtime/context/driver_diagnostics.h"
|
||||
#include <vector>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
class Device;
|
||||
class DeviceQueue;
|
||||
class MemoryManager;
|
||||
class SharingFunctions;
|
||||
class SVMAllocsManager;
|
||||
|
||||
template <>
|
||||
struct OpenCLObjectMapper<_cl_context> {
|
||||
typedef class Context DerivedType;
|
||||
};
|
||||
|
||||
class Context : public BaseObject<_cl_context> {
|
||||
public:
|
||||
static const cl_ulong objectMagic = 0xA4234321DC002130LL;
|
||||
|
||||
bool createImpl(const cl_context_properties *properties,
|
||||
const DeviceVector &devices,
|
||||
void(CL_CALLBACK *pfnNotify)(const char *, const void *, size_t, void *),
|
||||
void *userData, cl_int &errcodeRet);
|
||||
|
||||
template <typename T>
|
||||
static T *create(const cl_context_properties *properties,
|
||||
const DeviceVector &devices,
|
||||
void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *),
|
||||
void *data, cl_int &errcodeRet) {
|
||||
|
||||
auto pContext = new T(funcNotify, data);
|
||||
|
||||
if (!pContext->createImpl(properties, devices, funcNotify, data, errcodeRet)) {
|
||||
delete pContext;
|
||||
pContext = nullptr;
|
||||
}
|
||||
|
||||
return pContext;
|
||||
}
|
||||
|
||||
Context &operator=(const Context &) = delete;
|
||||
Context(const Context &) = delete;
|
||||
|
||||
~Context() override;
|
||||
|
||||
cl_int getInfo(cl_context_info paramName, size_t paramValueSize,
|
||||
void *paramValue, size_t *paramValueSizeRet);
|
||||
|
||||
cl_int getSupportedImageFormats(Device *device, cl_mem_flags flags,
|
||||
cl_mem_object_type imageType, cl_uint numEntries,
|
||||
cl_image_format *imageFormats, cl_uint *numImageFormats);
|
||||
|
||||
size_t getNumDevices() const;
|
||||
Device *getDevice(size_t deviceOrdinal);
|
||||
|
||||
MemoryManager *getMemoryManager() {
|
||||
return memoryManager;
|
||||
}
|
||||
|
||||
SVMAllocsManager *getSVMAllocsManager() const {
|
||||
return svmAllocsManager;
|
||||
}
|
||||
|
||||
EventsRegistry &getEventsRegistry() {
|
||||
return eventsRegistry;
|
||||
}
|
||||
|
||||
DeviceQueue *getDefaultDeviceQueue();
|
||||
void setDefaultDeviceQueue(DeviceQueue *queue);
|
||||
|
||||
CommandQueue *getSpecialQueue();
|
||||
void setSpecialQueue(CommandQueue *commandQueue);
|
||||
bool isSpecialQueue(CommandQueue *commandQueue);
|
||||
void deleteSpecialQueue();
|
||||
|
||||
template <typename Sharing>
|
||||
Sharing *getSharing();
|
||||
|
||||
template <typename Sharing>
|
||||
void registerSharing(Sharing *sharing);
|
||||
|
||||
template <typename... Args>
|
||||
void providePerformanceHint(cl_diagnostics_verbose_level flags, PerformanceHints performanceHint, Args &&... args) {
|
||||
DEBUG_BREAK_IF(contextCallback == nullptr);
|
||||
DEBUG_BREAK_IF(driverDiagnostics == nullptr);
|
||||
char hint[DriverDiagnostics::maxHintStringSize];
|
||||
snprintf(hint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[performanceHint], std::forward<Args>(args)..., 0);
|
||||
if (driverDiagnostics->validFlags(flags)) {
|
||||
contextCallback(hint, &flags, sizeof(flags), userData);
|
||||
}
|
||||
}
|
||||
|
||||
cl_bool isProvidingPerformanceHints() const {
|
||||
return driverDiagnostics != nullptr;
|
||||
}
|
||||
|
||||
bool getInteropUserSyncEnabled() { return interopUserSync; }
|
||||
void setInteropUserSyncEnabled(bool enabled) { interopUserSync = enabled; }
|
||||
|
||||
protected:
|
||||
Context(void(CL_CALLBACK *pfnNotify)(const char *, const void *, size_t, void *) = nullptr,
|
||||
void *userData = nullptr);
|
||||
|
||||
// OS specific implementation
|
||||
cl_int createContextOsProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue);
|
||||
void *getOsContextInfo(cl_context_info ¶mName, size_t *srcParamSize);
|
||||
|
||||
const cl_context_properties *properties;
|
||||
size_t numProperties;
|
||||
void(CL_CALLBACK *contextCallback)(const char *, const void *, size_t, void *);
|
||||
void *userData;
|
||||
|
||||
DeviceVector devices;
|
||||
MemoryManager *memoryManager;
|
||||
SVMAllocsManager *svmAllocsManager = nullptr;
|
||||
EventsRegistry eventsRegistry;
|
||||
CommandQueue *specialQueue;
|
||||
DeviceQueue *defaultDeviceQueue;
|
||||
std::vector<std::unique_ptr<SharingFunctions>> sharingFunctions;
|
||||
DriverDiagnostics *driverDiagnostics;
|
||||
bool interopUserSync = false;
|
||||
cl_bool preferD3dSharedResources = 0u;
|
||||
};
|
||||
} // namespace OCLRT
|
38
runtime/context/context.inl
Normal file
38
runtime/context/context.inl
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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/context/context.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
template <typename Sharing>
|
||||
void Context::registerSharing(Sharing *sharing) {
|
||||
this->sharingFunctions[Sharing::sharingId].reset(sharing);
|
||||
}
|
||||
|
||||
template <typename Sharing>
|
||||
Sharing *Context::getSharing() {
|
||||
UNRECOVERABLE_IF(Sharing::sharingId >= sharingFunctions.size());
|
||||
|
||||
return reinterpret_cast<Sharing *>(sharingFunctions[Sharing::sharingId].get());
|
||||
}
|
||||
}
|
66
runtime/context/driver_diagnostics.cpp
Normal file
66
runtime/context/driver_diagnostics.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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 "driver_diagnostics.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
DriverDiagnostics::DriverDiagnostics(cl_diagnostics_verbose_level level) {
|
||||
this->verboseLevel = level;
|
||||
}
|
||||
|
||||
cl_bool DriverDiagnostics::validFlags(cl_diagnostics_verbose_level flags) const {
|
||||
return (verboseLevel & flags) != 0;
|
||||
}
|
||||
|
||||
const char *DriverDiagnostics::hintFormat[] = {
|
||||
"Performance hint: clCreateBuffer with pointer %p and size %u doesn't meet alignment restrictions. Size should be aligned to %u bytes and pointer should be aligned to %u. Buffer is not sharing the same physical memory with CPU.", //CL_BUFFER_DOESNT_MEET_ALIGNMENT_RESTRICTIONS
|
||||
"Performance hint: clCreateBuffer with pointer %p and size %u meets alignment restrictions and buffer will share the same physical memory with CPU.", //CL_BUFFER_MEETS_ALIGNMENT_RESTRICTIONS
|
||||
"Performance hint: clCreateBuffer needs to allocate memory for buffer. For subsequent operations the buffer will share the same physical memory with CPU.", //CL_BUFFER_NEEDS_ALLOCATE_MEMORY
|
||||
"Performance hint: Driver calls internal clFlush on the command queue each time 1 command is enqueued.", //DRIVER_CALLS_INTERNAL_CL_FLUSH
|
||||
"Performance hint: Profiling adds overhead on all enqueue commands with events.", //PROFILING_ENABLED
|
||||
"Performance hint: Profiled kernels will be executed with disabled preemption.", //PROFILING_ENABLED_WITH_DISABLED_PREEMPTION
|
||||
"Performance hint: Subbuffer created from buffer %p shares the same memory with buffer.", //SUBBUFFER_SHARES_MEMORY
|
||||
"Performance hint: clSVMAlloc with pointer %p and size %u meets alignment restrictions.", //CL_SVM_ALLOC_MEETS_ALIGNMENT_RESTRICTIONS
|
||||
"Performance hint: clEnqueueReadBuffer call on a buffer %p with pointer %p will require driver to copy the data.Consider using clEnqueueMapBuffer with buffer that shares the same physical memory with CPU.", //CL_ENQUEUE_READ_BUFFER_REQUIRES_COPY_DATA
|
||||
"Performance hint: Pointer %p and size %u passed to clEnqueueReadBuffer doesn't meet alignment restrictions. Size should be aligned to %u bytes and pointer should be aligned to %u. Driver needs to disable L3 caching.", //CL_ENQUEUE_READ_BUFFER_DOESNT_MEET_ALIGNMENT_RESTRICTIONS
|
||||
"Performance hint: clEnqueueReadBufferRect call on a buffer %p with pointer %p will require driver to copy the data.Consider using clEnqueueMapBuffer with buffer that shares the same physical memory with CPU.", //CL_ENQUEUE_READ_BUFFER_RECT_REQUIRES_COPY_DATA
|
||||
"Performance hint: Pointer %p and size %u passed to clEnqueueReadBufferRect doesn't meet alignment restrictions. Size should be aligned to %u bytes and pointer should be aligned to %u. Driver needs to disable L3 caching.", //CL_ENQUEUE_READ_BUFFER_RECT_DOESNT_MEET_ALIGNMENT_RESTRICTIONS
|
||||
"Performance hint: clEnqueueWriteBuffer call on a buffer %p require driver to copy the data. Consider using clEnqueueMapBuffer with buffer that shares the same physical memory with CPU.", //CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA
|
||||
"Performance hint: clEnqueueWriteBufferRect call on a buffer %p require driver to copy the data. Consider using clEnqueueMapBuffer with buffer that shares the same physical memory with CPU.", //CL_ENQUEUE_WRITE_BUFFER_RECT_REQUIRES_COPY_DATA
|
||||
"Performance hint: Pointer %p and size %u passed to clEnqueueReadImage doesn't meet alignment restrictions. Size should be aligned to %u bytes and pointer should be aligned to %u. Driver needs to disable L3 caching.", //CL_ENQUEUE_READ_IMAGE_DOESNT_MEET_ALIGNMENT_RESTRICTIONS
|
||||
"Performance hint: clEnqueueWriteImage call on an image %p require driver to copy the data.", //CL_ENQUEUE_WRITE_IMAGE_REQUIRES_COPY_DATA
|
||||
"Performance hint: clEnqueueMapBuffer call on a buffer %p will require driver to make a copy as buffer is not sharing the same physical memory with CPU.", //CL_ENQUEUE_MAP_BUFFER_REQUIRES_COPY_DATA
|
||||
"Performance hint: clEnqueueMapBuffer call on a buffer %p will not require any data copy as buffer shares the same physical memory with CPU.", //CL_ENQUEUE_MAP_BUFFER_DOESNT_REQUIRE_COPY_DATA
|
||||
"Performance hint: clEnqueueMapImage call on an image %p will require driver to make a copy, as image is not sharing the same physical memory with CPU.", //CL_ENQUEUE_MAP_IMAGE_REQUIRES_COPY_DATA
|
||||
"Performance hint: clEnqueueMapImage call on an image %p will not require any data copy as image shares the same physical memory with CPU.", //CL_ENQUEUE_MAP_IMAGE_DOESNT_REQUIRE_COPY_DATA
|
||||
"Performance hint: clEnqueueUnmapMemObject call with pointer %p will not require any data copy.", //CL_ENQUEUE_UNMAP_MEM_OBJ_DOESNT_REQUIRE_COPY_DATA
|
||||
"Performance hint: clEnqueueUnmapMemObject call with pointer %p will require driver to copy the data to memory object %p.", //CL_ENQUEUE_UNMAP_MEM_OBJ_REQUIRES_COPY_DATA
|
||||
"Performance hint: clEnqueueSVMMap call with pointer %p will not require any data copy.", //CL_ENQUEUE_SVM_MAP_DOESNT_REQUIRE_COPY_DATA
|
||||
"Performance hint: Printf detected in kernel %s, it may cause overhead.", //PRINTF_DETECTED_IN_KERNEL
|
||||
"Performance hint: Null local workgroup size detected ( kernel name: %s ); following sizes will be used for execution : { %u, %u, %u }.", //NULL_LOCAL_WORKGROUP_SIZE
|
||||
"Performance hint: Local workgroup sizes { %u, %u, %u } selected for this workload ( kernel name: %s ) may not be optimal, consider using following local workgroup size: { %u, %u, %u }.", //BAD_LOCAL_WORKGROUP_SIZE
|
||||
"Performance hint: Kernel %s register pressure is too high, spill fills will be generated, additional surface needs to be allocated of size %u, consider simplifying your kernel.", //REGISTER_PRESSURE_TOO_HIGH
|
||||
"Performance hint: Kernel %s private memory usage is too high and exhausts register space, additional surface needs to be allocated of size %u, consider reducing amount of private memory used, avoid using private memory arrays.", //PRIVATE_MEMORY_USAGE_TOO_HIGH
|
||||
"Performance hint: Kernel %s submission requires coherency with CPU; this will impact performance." //KERNEL_REQUIRES_COHERENCY
|
||||
};
|
||||
}
|
71
runtime/context/driver_diagnostics.h
Normal file
71
runtime/context/driver_diagnostics.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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 "CL/cl_ext_intel.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
enum PerformanceHints {
|
||||
CL_BUFFER_DOESNT_MEET_ALIGNMENT_RESTRICTIONS,
|
||||
CL_BUFFER_MEETS_ALIGNMENT_RESTRICTIONS,
|
||||
CL_BUFFER_NEEDS_ALLOCATE_MEMORY,
|
||||
DRIVER_CALLS_INTERNAL_CL_FLUSH,
|
||||
PROFILING_ENABLED,
|
||||
PROFILING_ENABLED_WITH_DISABLED_PREEMPTION,
|
||||
SUBBUFFER_SHARES_MEMORY,
|
||||
CL_SVM_ALLOC_MEETS_ALIGNMENT_RESTRICTIONS,
|
||||
CL_ENQUEUE_READ_BUFFER_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_READ_BUFFER_DOESNT_MEET_ALIGNMENT_RESTRICTIONS,
|
||||
CL_ENQUEUE_READ_BUFFER_RECT_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_READ_BUFFER_RECT_DOESNT_MEET_ALIGNMENT_RESTRICTIONS,
|
||||
CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_WRITE_BUFFER_RECT_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_READ_IMAGE_DOESNT_MEET_ALIGNMENT_RESTRICTIONS,
|
||||
CL_ENQUEUE_WRITE_IMAGE_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_MAP_BUFFER_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_MAP_BUFFER_DOESNT_REQUIRE_COPY_DATA,
|
||||
CL_ENQUEUE_MAP_IMAGE_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_MAP_IMAGE_DOESNT_REQUIRE_COPY_DATA,
|
||||
CL_ENQUEUE_UNMAP_MEM_OBJ_DOESNT_REQUIRE_COPY_DATA,
|
||||
CL_ENQUEUE_UNMAP_MEM_OBJ_REQUIRES_COPY_DATA,
|
||||
CL_ENQUEUE_SVM_MAP_DOESNT_REQUIRE_COPY_DATA,
|
||||
PRINTF_DETECTED_IN_KERNEL,
|
||||
NULL_LOCAL_WORKGROUP_SIZE,
|
||||
BAD_LOCAL_WORKGROUP_SIZE,
|
||||
REGISTER_PRESSURE_TOO_HIGH,
|
||||
PRIVATE_MEMORY_USAGE_TOO_HIGH,
|
||||
KERNEL_REQUIRES_COHERENCY
|
||||
};
|
||||
|
||||
class DriverDiagnostics {
|
||||
public:
|
||||
DriverDiagnostics(cl_diagnostics_verbose_level level);
|
||||
cl_bool validFlags(cl_diagnostics_verbose_level flags) const;
|
||||
~DriverDiagnostics() = default;
|
||||
static const char *hintFormat[];
|
||||
static const cl_int maxHintStringSize = 1024;
|
||||
|
||||
protected:
|
||||
cl_diagnostics_verbose_level verboseLevel;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user