P4 to Git Change 1528961 by cpaquot@cpaquot-ocl-lc-lnx on 2018/03/19 13:43:08
SWDEV-145570 - Contexts Create one amd::Context per device g_context is now thread's current context HIP doesn't want more than one context per device so we always use the primary one Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#7 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#4 edit
这个提交包含在:
@@ -27,7 +27,8 @@ THE SOFTWARE.
|
||||
#include "utils/versions.hpp"
|
||||
|
||||
|
||||
amd::Context* g_context = nullptr;
|
||||
thread_local amd::Context* g_context = nullptr;
|
||||
std::vector<amd::Context*> g_devices;
|
||||
|
||||
hipError_t hipInit(unsigned int flags)
|
||||
{
|
||||
@@ -37,14 +38,18 @@ hipError_t hipInit(unsigned int flags)
|
||||
amd::Runtime::init();
|
||||
}
|
||||
|
||||
// FIXME: move the global VDI context to hipInit.
|
||||
g_context = new amd::Context(
|
||||
amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false), amd::Context::Info());
|
||||
if (!g_context) return hipErrorOutOfMemory;
|
||||
const std::vector<amd::Device*>& devices = amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false);
|
||||
|
||||
if (g_context && CL_SUCCESS != g_context->create(nullptr)) {
|
||||
g_context->release();
|
||||
return hipErrorUnknown;
|
||||
for (unsigned int i=0; i<devices.size(); i++) {
|
||||
const std::vector<amd::Device*> device(1, devices[i]);
|
||||
amd::Context* context = new amd::Context(device, amd::Context::Info());
|
||||
if (!context) return hipErrorOutOfMemory;
|
||||
|
||||
if (context && CL_SUCCESS != context->create(nullptr)) {
|
||||
context->release();
|
||||
} else {
|
||||
g_devices.push_back(context);
|
||||
}
|
||||
}
|
||||
|
||||
return hipSuccess;
|
||||
@@ -54,6 +59,30 @@ hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
|
||||
{
|
||||
HIP_INIT_API(ctx, flags, device);
|
||||
|
||||
if (static_cast<size_t>(device) >= g_devices.size()) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
*ctx = reinterpret_cast<hipCtx_t>(g_devices[device]);
|
||||
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
hipError_t hipCtxSetCurrent(hipCtx_t ctx)
|
||||
{
|
||||
HIP_INIT_API(ctx);
|
||||
|
||||
g_context = reinterpret_cast<amd::Context*>(ctx);
|
||||
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
hipError_t hipCtxGetCurrent(hipCtx_t* ctx)
|
||||
{
|
||||
HIP_INIT_API(ctx);
|
||||
|
||||
*ctx = reinterpret_cast<hipCtx_t>(g_context);
|
||||
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) {
|
||||
|
||||
HIP_INIT_API(bytes, device);
|
||||
|
||||
if (device < 0 || device > (cl_int)g_context->devices().size()) {
|
||||
if (device < 0 || static_cast<size_t>(device) >= g_devices.size()) {
|
||||
return hipErrorInvalidDevice;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
auto* deviceHandle = g_context->devices()[device];
|
||||
auto* deviceHandle = g_devices[device]->devices()[0];
|
||||
const auto& info = deviceHandle->info();
|
||||
|
||||
*bytes = info.globalMemSize_;
|
||||
@@ -70,7 +70,7 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
|
||||
|
||||
HIP_INIT_API(major, minor, device);
|
||||
|
||||
if (device < 0 || device > (cl_int)g_context->devices().size()) {
|
||||
if (device < 0 || static_cast<size_t>(device) >= g_devices.size()) {
|
||||
return hipErrorInvalidDevice;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
auto* deviceHandle = g_context->devices()[device];
|
||||
auto* deviceHandle = g_devices[device]->devices()[0];
|
||||
const auto& info = deviceHandle->info();
|
||||
*major = info.gfxipVersion_ / 100;
|
||||
*minor = info.gfxipVersion_ % 100;
|
||||
@@ -94,7 +94,7 @@ hipError_t hipDeviceGetCount(int* count) {
|
||||
}
|
||||
|
||||
// Get all available devices
|
||||
*count = g_context->devices().size();
|
||||
*count = g_devices.size();
|
||||
|
||||
return hipSuccess;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
|
||||
|
||||
HIP_INIT_API((void*)name, len, device);
|
||||
|
||||
if (device < 0 || device > (cl_int)g_context->devices().size()) {
|
||||
if (device < 0 || static_cast<size_t>(device) >= g_devices.size()) {
|
||||
return hipErrorInvalidDevice;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
auto* deviceHandle = g_context->devices()[device];
|
||||
auto* deviceHandle = g_devices[device]->devices()[0];
|
||||
const auto& info = deviceHandle->info();
|
||||
|
||||
len = ((cl_uint)len < ::strlen(info.boardName_)) ? len : 128;
|
||||
@@ -127,10 +127,10 @@ hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device )
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
if (unsigned(device) >= g_context->devices().size()) {
|
||||
if (unsigned(device) >= g_devices.size()) {
|
||||
return hipErrorInvalidDevice;
|
||||
}
|
||||
auto* deviceHandle = g_context->devices()[device];
|
||||
auto* deviceHandle = g_devices[device]->devices()[0];
|
||||
|
||||
hipDeviceProp_t deviceProps = {0};
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ THE SOFTWARE.
|
||||
#define HIP_INIT_API(...) \
|
||||
HIP_INIT()
|
||||
|
||||
extern amd::Context* g_context;
|
||||
extern thread_local amd::Context* g_context;
|
||||
extern std::vector<amd::Context*> g_devices;
|
||||
|
||||
hipError_t hipDeviceGetCount(int* count);
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户