Reorganization directory structure [1/n]

Change-Id: Id1a94577437a4826a32411869f516fec20314ec0
This commit is contained in:
kamdiedrich
2020-02-22 21:54:11 +01:00
parent 247cc953d1
commit fa8e720f9e
660 changed files with 3 additions and 3 deletions

View File

@@ -0,0 +1,16 @@
#
# Copyright (C) 2018-2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(RUNTIME_SRCS_PLATFORM
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/extensions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform.h
${CMAKE_CURRENT_SOURCE_DIR}/platform_info.h
)
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_PLATFORM})
set_property(GLOBAL PROPERTY RUNTIME_SRCS_PLATFORM ${RUNTIME_SRCS_PLATFORM})

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "platform/extensions.h"
#include "core/helpers/hw_info.h"
#include <string>
namespace NEO {
const char *deviceExtensionsList = "cl_khr_byte_addressable_store "
"cl_khr_fp16 "
"cl_khr_global_int32_base_atomics "
"cl_khr_global_int32_extended_atomics "
"cl_khr_icd "
"cl_khr_local_int32_base_atomics "
"cl_khr_local_int32_extended_atomics "
"cl_intel_subgroups "
"cl_intel_required_subgroup_size "
"cl_intel_subgroups_short "
"cl_khr_spir "
"cl_intel_accelerator "
"cl_intel_driver_diagnostics "
"cl_khr_priority_hints "
"cl_khr_throttle_hints "
"cl_khr_create_command_queue "
"cl_intel_subgroups_char "
"cl_intel_subgroups_long ";
std::string getExtensionsList(const HardwareInfo &hwInfo) {
std::string allExtensionsList;
allExtensionsList.reserve(1000);
allExtensionsList.append(deviceExtensionsList);
if (hwInfo.capabilityTable.clVersionSupport >= 21) {
allExtensionsList += "cl_khr_subgroups ";
allExtensionsList += "cl_khr_il_program ";
if (hwInfo.capabilityTable.supportsVme) {
allExtensionsList += "cl_intel_spirv_device_side_avc_motion_estimation ";
}
if (hwInfo.capabilityTable.supportsImages) {
allExtensionsList += "cl_intel_spirv_media_block_io ";
}
allExtensionsList += "cl_intel_spirv_subgroups ";
allExtensionsList += "cl_khr_spirv_no_integer_wrap_decoration ";
}
if (hwInfo.capabilityTable.ftrSupportsFP64) {
allExtensionsList += "cl_khr_fp64 ";
}
if (hwInfo.capabilityTable.ftrSupportsInteger64BitAtomics) {
allExtensionsList += "cl_khr_int64_base_atomics ";
allExtensionsList += "cl_khr_int64_extended_atomics ";
}
if (hwInfo.capabilityTable.supportsImages) {
allExtensionsList += "cl_khr_3d_image_writes ";
}
if (hwInfo.capabilityTable.supportsVme) {
allExtensionsList += "cl_intel_motion_estimation cl_intel_device_side_avc_motion_estimation ";
}
return allExtensionsList;
}
std::string removeLastSpace(std::string &processedString) {
if (processedString.size() > 0) {
if (*processedString.rbegin() == ' ') {
processedString.pop_back();
}
}
return processedString;
}
std::string convertEnabledExtensionsToCompilerInternalOptions(const char *enabledExtensions) {
std::string extensionsList = enabledExtensions;
extensionsList.reserve(1000);
removeLastSpace(extensionsList);
std::string::size_type pos = 0;
while ((pos = extensionsList.find(" ", pos)) != std::string::npos) {
extensionsList.replace(pos, 1, ",+");
}
extensionsList = " -cl-ext=-all,+" + extensionsList + ",+cl_khr_3d_image_writes ";
return extensionsList;
}
} // namespace NEO

View File

@@ -0,0 +1,24 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "core/helpers/hw_info.h"
#include <string>
namespace NEO {
namespace Extensions {
constexpr const char *const sharingFormatQuery = "cl_intel_sharing_format_query ";
}
extern const char *deviceExtensionsList;
std::string getExtensionsList(const HardwareInfo &hwInfo);
std::string removeLastSpace(std::string &s);
std::string convertEnabledExtensionsToCompilerInternalOptions(const char *deviceExtensions);
} // namespace NEO

View File

@@ -0,0 +1,282 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "platform.h"
#include "core/command_stream/command_stream_receiver.h"
#include "core/compiler_interface/compiler_interface.h"
#include "core/debug_settings/debug_settings_manager.h"
#include "core/device/root_device.h"
#include "core/execution_environment/execution_environment.h"
#include "core/execution_environment/root_device_environment.h"
#include "core/gmm_helper/gmm_helper.h"
#include "core/helpers/debug_helpers.h"
#include "core/helpers/get_info.h"
#include "core/helpers/hw_helper.h"
#include "core/helpers/string.h"
#include "core/os_interface/device_factory.h"
#include "core/os_interface/os_interface.h"
#include "CL/cl_ext.h"
#include "api/api.h"
#include "device/cl_device.h"
#include "event/async_events_handler.h"
#include "gmm_client_context.h"
#include "gtpin/gtpin_notify.h"
#include "helpers/built_ins_helper.h"
#include "helpers/get_info_status_mapper.h"
#include "platform/extensions.h"
#include "sharings/sharing_factory.h"
#include "source_level_debugger/source_level_debugger.h"
#include <algorithm>
#include <map>
namespace NEO {
std::vector<std::unique_ptr<Platform>> platformsImpl;
Platform *platform() {
if (platformsImpl.empty()) {
return nullptr;
}
return platformsImpl[0].get();
}
Platform *constructPlatform() {
static std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex);
if (platformsImpl.empty()) {
platformsImpl.push_back(std::make_unique<Platform>(*(new ExecutionEnvironment())));
}
return platformsImpl[0].get();
}
Platform::Platform(ExecutionEnvironment &executionEnvironmentIn) : executionEnvironment(executionEnvironmentIn) {
clDevices.reserve(4);
setAsyncEventsHandler(std::unique_ptr<AsyncEventsHandler>(new AsyncEventsHandler()));
executionEnvironment.incRefInternal();
}
Platform::~Platform() {
asyncEventsHandler->closeThread();
for (auto clDevice : this->clDevices) {
if (clDevice) {
clDevice->decRefInternal();
}
}
gtpinNotifyPlatformShutdown();
executionEnvironment.decRefInternal();
}
cl_int Platform::getInfo(cl_platform_info paramName,
size_t paramValueSize,
void *paramValue,
size_t *paramValueSizeRet) {
auto retVal = CL_INVALID_VALUE;
const std::string *param = nullptr;
size_t paramSize = 0;
uint64_t pVal = 0;
switch (paramName) {
case CL_PLATFORM_HOST_TIMER_RESOLUTION:
pVal = static_cast<uint64_t>(this->clDevices[0]->getPlatformHostTimerResolution());
paramSize = sizeof(uint64_t);
retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, &pVal, paramSize));
break;
case CL_PLATFORM_PROFILE:
param = &platformInfo->profile;
break;
case CL_PLATFORM_VERSION:
param = &platformInfo->version;
break;
case CL_PLATFORM_NAME:
param = &platformInfo->name;
break;
case CL_PLATFORM_VENDOR:
param = &platformInfo->vendor;
break;
case CL_PLATFORM_EXTENSIONS:
param = &platformInfo->extensions;
break;
case CL_PLATFORM_ICD_SUFFIX_KHR:
param = &platformInfo->icdSuffixKhr;
break;
default:
break;
}
// Case for string parameters
if (param) {
paramSize = param->length() + 1;
retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, param->c_str(), paramSize));
}
if (paramValueSizeRet) {
*paramValueSizeRet = paramSize;
}
return retVal;
}
bool Platform::initialize(std::vector<std::unique_ptr<Device>> devices) {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (devices.empty()) {
return false;
}
if (state == StateInited) {
return true;
}
if (DebugManager.flags.LoopAtPlatformInitialize.get()) {
while (DebugManager.flags.LoopAtPlatformInitialize.get())
this->initializationLoopHelper();
}
state = StateIniting;
DEBUG_BREAK_IF(this->platformInfo);
this->platformInfo.reset(new PlatformInfo);
this->clDevices.resize(devices.size());
for (auto &inputDevice : devices) {
ClDevice *pClDevice = nullptr;
auto pDevice = inputDevice.release();
UNRECOVERABLE_IF(!pDevice);
pClDevice = new ClDevice{*pDevice, this};
this->clDevices[pDevice->getRootDeviceIndex()] = pClDevice;
this->platformInfo->extensions = pClDevice->getDeviceInfo().deviceExtensions;
switch (pClDevice->getEnabledClVersion()) {
case 21:
this->platformInfo->version = "OpenCL 2.1 ";
break;
case 20:
this->platformInfo->version = "OpenCL 2.0 ";
break;
default:
this->platformInfo->version = "OpenCL 1.2 ";
break;
}
}
auto hwInfo = clDevices[0]->getHardwareInfo();
const bool debuggerActive = executionEnvironment.debugger && executionEnvironment.debugger->isDebuggerActive();
if (clDevices[0]->getPreemptionMode() == PreemptionMode::MidThread || debuggerActive) {
auto sipType = SipKernel::getSipKernelType(hwInfo.platform.eRenderCoreFamily, clDevices[0]->isDebuggerActive());
initSipKernel(sipType, clDevices[0]->getDevice());
}
this->fillGlobalDispatchTable();
DEBUG_BREAK_IF(DebugManager.flags.CreateMultipleRootDevices.get() > 1 && !this->clDevices[0]->getDefaultEngine().commandStreamReceiver->peekTimestampPacketWriteEnabled());
state = StateInited;
return true;
}
void Platform::fillGlobalDispatchTable() {
sharingFactory.fillGlobalDispatchTable();
}
bool Platform::isInitialized() {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
bool ret = (this->state == StateInited);
return ret;
}
Device *Platform::getDevice(size_t deviceOrdinal) {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (this->state != StateInited || deviceOrdinal >= clDevices.size()) {
return nullptr;
}
auto pDevice = &clDevices[deviceOrdinal]->getDevice();
DEBUG_BREAK_IF(pDevice == nullptr);
return pDevice;
}
ClDevice *Platform::getClDevice(size_t deviceOrdinal) {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (this->state != StateInited || deviceOrdinal >= clDevices.size()) {
return nullptr;
}
auto pClDevice = clDevices[deviceOrdinal];
DEBUG_BREAK_IF(pClDevice == nullptr);
return pClDevice;
}
size_t Platform::getNumDevices() const {
TakeOwnershipWrapper<const Platform> platformOwnership(*this);
if (this->state != StateInited) {
return 0;
}
return clDevices.size();
}
ClDevice **Platform::getClDevices() {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (this->state != StateInited) {
return nullptr;
}
return clDevices.data();
}
const PlatformInfo &Platform::getPlatformInfo() const {
DEBUG_BREAK_IF(!platformInfo);
return *platformInfo;
}
AsyncEventsHandler *Platform::getAsyncEventsHandler() {
return asyncEventsHandler.get();
}
std::unique_ptr<AsyncEventsHandler> Platform::setAsyncEventsHandler(std::unique_ptr<AsyncEventsHandler> handler) {
asyncEventsHandler.swap(handler);
return handler;
}
GmmHelper *Platform::peekGmmHelper() const {
return executionEnvironment.getGmmHelper();
}
GmmClientContext *Platform::peekGmmClientContext() const {
return peekGmmHelper()->getClientContext();
}
std::unique_ptr<Platform> (*Platform::createFunc)(ExecutionEnvironment &) = [](ExecutionEnvironment &executionEnvironment) -> std::unique_ptr<Platform> {
return std::make_unique<Platform>(executionEnvironment);
};
std::vector<DeviceVector> Platform::groupDevices(DeviceVector devices) {
std::map<PRODUCT_FAMILY, size_t> platformsMap;
std::vector<DeviceVector> outDevices;
for (auto &device : devices) {
auto productFamily = device->getHardwareInfo().platform.eProductFamily;
auto result = platformsMap.find(productFamily);
if (result == platformsMap.end()) {
platformsMap.insert({productFamily, platformsMap.size()});
outDevices.push_back(DeviceVector{});
}
auto platformId = platformsMap[productFamily];
outDevices[platformId].push_back(std::move(device));
}
std::reverse(outDevices.begin(), outDevices.end());
return outDevices;
}
} // namespace NEO

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "api/cl_types.h"
#include "device/cl_device_vector.h"
#include "helpers/base_object.h"
#include "platform_info.h"
#include <condition_variable>
#include <unordered_map>
#include <vector>
namespace NEO {
class CompilerInterface;
class Device;
class AsyncEventsHandler;
class ExecutionEnvironment;
class GmmHelper;
class GmmClientContext;
struct HardwareInfo;
template <>
struct OpenCLObjectMapper<_cl_platform_id> {
typedef class Platform DerivedType;
};
using DeviceVector = std::vector<std::unique_ptr<Device>>;
class Platform : public BaseObject<_cl_platform_id> {
public:
static const cl_ulong objectMagic = 0x8873ACDEF2342133LL;
Platform(ExecutionEnvironment &executionEnvironment);
~Platform() override;
Platform(const Platform &) = delete;
Platform &operator=(Platform const &) = delete;
cl_int getInfo(cl_platform_info paramName,
size_t paramValueSize,
void *paramValue,
size_t *paramValueSizeRet);
MOCKABLE_VIRTUAL bool initialize(std::vector<std::unique_ptr<Device>> devices);
bool isInitialized();
size_t getNumDevices() const;
Device *getDevice(size_t deviceOrdinal);
ClDevice **getClDevices();
ClDevice *getClDevice(size_t deviceOrdinal);
const PlatformInfo &getPlatformInfo() const;
AsyncEventsHandler *getAsyncEventsHandler();
std::unique_ptr<AsyncEventsHandler> setAsyncEventsHandler(std::unique_ptr<AsyncEventsHandler> handler);
ExecutionEnvironment *peekExecutionEnvironment() const { return &executionEnvironment; }
GmmHelper *peekGmmHelper() const;
GmmClientContext *peekGmmClientContext() const;
static std::unique_ptr<Platform> (*createFunc)(ExecutionEnvironment &executionEnvironment);
static std::vector<DeviceVector> groupDevices(DeviceVector devices);
protected:
enum {
StateNone,
StateIniting,
StateInited,
};
cl_uint state = StateNone;
void fillGlobalDispatchTable();
MOCKABLE_VIRTUAL void initializationLoopHelper(){};
std::unique_ptr<PlatformInfo> platformInfo;
ClDeviceVector clDevices;
std::unique_ptr<AsyncEventsHandler> asyncEventsHandler;
ExecutionEnvironment &executionEnvironment;
};
extern std::vector<std::unique_ptr<Platform>> platformsImpl;
Platform *platform();
Platform *constructPlatform();
} // namespace NEO

View File

@@ -0,0 +1,18 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <string>
struct PlatformInfo {
std::string profile = "FULL_PROFILE";
std::string version = "";
std::string name = "Intel(R) OpenCL HD Graphics";
std::string vendor = "Intel(R) Corporation";
std::string extensions;
std::string icdSuffixKhr = "INTEL";
};