2021-07-02 16:46:49 -07:00
|
|
|
/* Copyright (c) 2015 - 2021 Advanced Micro Devices, Inc.
|
2020-02-04 08:45:01 -08:00
|
|
|
|
|
|
|
|
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. */
|
2018-03-01 22:57:20 -05:00
|
|
|
|
|
|
|
|
#include <hip/hip_runtime.h>
|
|
|
|
|
#include "hip_internal.hpp"
|
2020-05-18 22:40:33 -04:00
|
|
|
#include "hip_platform.hpp"
|
2018-03-01 22:57:20 -05:00
|
|
|
#include "platform/runtime.hpp"
|
2019-03-07 17:24:23 -05:00
|
|
|
#include "utils/flags.hpp"
|
2018-03-02 17:55:48 -05:00
|
|
|
#include "utils/versions.hpp"
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
std::vector<hip::Device*> g_devices;
|
2018-05-01 18:10:09 -04:00
|
|
|
|
|
|
|
|
namespace hip {
|
2022-09-26 15:59:27 +05:30
|
|
|
thread_local TlsAggregator tls;
|
2023-02-16 01:27:08 +00:00
|
|
|
amd::Context* host_context = nullptr;
|
2018-03-23 14:18:27 -04:00
|
|
|
|
2021-11-18 16:19:55 -05:00
|
|
|
//init() is only to be called from the HIP_INIT macro only once
|
|
|
|
|
bool init() {
|
|
|
|
|
amd::IS_HIP = true;
|
|
|
|
|
GPU_NUM_MEM_DEPENDENCY = 0;
|
2021-07-26 14:35:02 -04:00
|
|
|
#if DISABLE_DIRECT_DISPATCH
|
2021-11-18 16:19:55 -05:00
|
|
|
constexpr bool kDirectDispatch = false;
|
2021-07-26 14:35:02 -04:00
|
|
|
#else
|
2021-11-18 16:19:55 -05:00
|
|
|
constexpr bool kDirectDispatch = IS_LINUX;
|
2021-07-26 14:35:02 -04:00
|
|
|
#endif
|
2021-11-18 16:19:55 -05:00
|
|
|
AMD_DIRECT_DISPATCH = flagIsDefault(AMD_DIRECT_DISPATCH) ? kDirectDispatch : AMD_DIRECT_DISPATCH;
|
|
|
|
|
if (!amd::Runtime::init()) {
|
|
|
|
|
return false;
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2023-02-08 10:20:59 -08:00
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_INIT, "Direct Dispatch: %d", AMD_DIRECT_DISPATCH);
|
2021-11-18 16:19:55 -05:00
|
|
|
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
const std::vector<amd::Device*>& devices = amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
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());
|
2021-11-18 16:19:55 -05:00
|
|
|
if (!context) return false;
|
2018-03-19 13:52:17 -04:00
|
|
|
|
2020-03-02 18:35:56 -05:00
|
|
|
// Enable active wait on the device by default
|
|
|
|
|
devices[i]->SetActiveWait(true);
|
|
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
if (context && CL_SUCCESS != context->create(nullptr)) {
|
|
|
|
|
context->release();
|
|
|
|
|
} else {
|
2022-03-28 12:30:04 -04:00
|
|
|
auto device = new Device(context, i);
|
|
|
|
|
if ((device == nullptr) || !device->Create()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
g_devices.push_back(device);
|
2018-03-19 13:52:17 -04:00
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2019-04-05 11:58:25 -04:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
amd::Context* hContext = new amd::Context(devices, amd::Context::Info());
|
2021-11-18 16:19:55 -05:00
|
|
|
if (!hContext) return false;
|
2019-04-05 11:58:25 -04:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
if (CL_SUCCESS != hContext->create(nullptr)) {
|
|
|
|
|
hContext->release();
|
2019-04-05 11:58:25 -04:00
|
|
|
}
|
2023-02-16 01:27:08 +00:00
|
|
|
host_context = hContext;
|
2019-12-11 03:11:19 -05:00
|
|
|
|
|
|
|
|
PlatformState::instance().init();
|
2021-11-18 16:19:55 -05:00
|
|
|
return true;
|
2018-03-28 19:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
Device* getCurrentDevice() {
|
2022-09-26 15:59:27 +05:30
|
|
|
return tls.device_;
|
2018-05-01 18:10:09 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
void setCurrentDevice(unsigned int index) {
|
2018-05-01 18:10:09 -04:00
|
|
|
assert(index<g_devices.size());
|
2022-09-26 15:59:27 +05:30
|
|
|
tls.device_ = g_devices[index];
|
|
|
|
|
uint32_t preferredNumaNode = (tls.device_)->devices()[0]->getPreferredNumaNode();
|
2021-11-09 02:54:48 -08:00
|
|
|
amd::Os::setPreferredNumaNode(preferredNumaNode);
|
2018-05-01 18:10:09 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 11:28:33 -04:00
|
|
|
amd::HostQueue* getQueue(hipStream_t stream) {
|
|
|
|
|
if (stream == nullptr) {
|
|
|
|
|
return getNullStream();
|
|
|
|
|
} else {
|
2020-04-23 16:54:48 -04:00
|
|
|
amd::HostQueue* queue = reinterpret_cast<hip::Stream*>(stream)->asHostQueue();
|
2020-05-06 10:36:53 -07:00
|
|
|
if (!(reinterpret_cast<hip::Stream*>(stream)->Flags() & hipStreamNonBlocking)) {
|
2021-11-29 17:53:36 +00:00
|
|
|
constexpr bool WaitNullStreamOnly = true;
|
2020-05-06 10:36:53 -07:00
|
|
|
iHipWaitActiveStreams(queue, WaitNullStreamOnly);
|
|
|
|
|
}
|
2020-04-23 16:54:48 -04:00
|
|
|
return queue;
|
2019-09-13 11:28:33 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 17:30:38 -04:00
|
|
|
// ================================================================================================
|
2020-02-18 12:36:12 -08:00
|
|
|
amd::HostQueue* getNullStream(amd::Context& ctx) {
|
2020-07-08 17:30:38 -04:00
|
|
|
for (auto& it : g_devices) {
|
|
|
|
|
if (it->asContext() == &ctx) {
|
|
|
|
|
return it->NullStream();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If it's a pure SVM allocation with system memory access, then it shouldn't matter which device
|
|
|
|
|
// runtime selects by default
|
2023-02-16 01:27:08 +00:00
|
|
|
if (hip::host_context == &ctx) {
|
2020-07-08 17:30:38 -04:00
|
|
|
// Return current...
|
|
|
|
|
return getNullStream();
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
2020-02-18 12:36:12 -08:00
|
|
|
}
|
2018-05-01 18:10:09 -04:00
|
|
|
|
2021-08-25 08:16:52 -07:00
|
|
|
// ================================================================================================
|
|
|
|
|
int getDeviceID(amd::Context& ctx) {
|
|
|
|
|
for (auto& it : g_devices) {
|
|
|
|
|
if (it->asContext() == &ctx) {
|
|
|
|
|
return it->deviceId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 17:30:38 -04:00
|
|
|
// ================================================================================================
|
2019-04-17 18:38:30 -04:00
|
|
|
amd::HostQueue* getNullStream() {
|
2020-02-18 12:36:12 -08:00
|
|
|
Device* device = getCurrentDevice();
|
2020-04-23 16:54:48 -04:00
|
|
|
return device ? device->NullStream() : nullptr;
|
2019-04-17 18:38:30 -04:00
|
|
|
}
|
|
|
|
|
|
2018-05-01 18:10:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using namespace hip;
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipInit(unsigned int flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipInit, flags);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2022-10-26 19:29:37 +05:30
|
|
|
if (flags != 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxCreate, ctx, flags, device);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
if (static_cast<size_t>(device) >= g_devices.size()) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-03-19 13:52:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*ctx = reinterpret_cast<hipCtx_t>(g_devices[device]);
|
|
|
|
|
|
2018-03-23 14:18:27 -04:00
|
|
|
// Increment ref count for device primary context
|
|
|
|
|
g_devices[device]->retain();
|
2022-09-26 15:59:27 +05:30
|
|
|
tls.ctxt_stack_.push(g_devices[device]);
|
2018-03-23 14:18:27 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-19 13:52:17 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipCtxSetCurrent(hipCtx_t ctx) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxSetCurrent, ctx);
|
2018-03-19 13:52:17 -04:00
|
|
|
|
2018-03-23 14:18:27 -04:00
|
|
|
if (ctx == nullptr) {
|
2022-09-26 15:59:27 +05:30
|
|
|
if(!tls.ctxt_stack_.empty()) {
|
|
|
|
|
tls.ctxt_stack_.pop();
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-26 15:59:27 +05:30
|
|
|
hip::tls.device_ = reinterpret_cast<hip::Device*>(ctx);
|
|
|
|
|
if(!tls.ctxt_stack_.empty()) {
|
|
|
|
|
tls.ctxt_stack_.pop();
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
2022-09-26 15:59:27 +05:30
|
|
|
tls.ctxt_stack_.push(hip::getCurrentDevice());
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
2018-03-19 13:52:17 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-19 13:52:17 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipCtxGetCurrent(hipCtx_t* ctx) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxGetCurrent, ctx);
|
2018-03-19 13:52:17 -04:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
*ctx = reinterpret_cast<hipCtx_t>(hip::getCurrentDevice());
|
2018-03-19 13:52:17 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 16:08:44 -04:00
|
|
|
hipError_t hipCtxGetSharedMemConfig(hipSharedMemConfig* pConfig) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxGetSharedMemConfig, pConfig);
|
2018-09-11 16:08:44 -04:00
|
|
|
|
|
|
|
|
*pConfig = hipSharedMemBankSizeFourByte;
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipRuntimeGetVersion(int *runtimeVersion) {
|
2022-01-31 11:33:18 +00:00
|
|
|
HIP_INIT_API_NO_RETURN(hipRuntimeGetVersion, runtimeVersion);
|
2018-03-02 17:55:48 -05:00
|
|
|
|
|
|
|
|
if (!runtimeVersion) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-03-02 17:55:48 -05:00
|
|
|
}
|
|
|
|
|
|
2021-04-14 06:51:13 +00:00
|
|
|
// HIP_VERSION = HIP_VERSION_MAJOR*100 + HIP_MINOR_VERSION
|
|
|
|
|
*runtimeVersion = HIP_VERSION;
|
2018-03-02 17:55:48 -05:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-02 17:55:48 -05:00
|
|
|
}
|
2018-03-23 14:18:27 -04:00
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipCtxDestroy(hipCtx_t ctx) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxDestroy, ctx);
|
2018-03-23 14:18:27 -04:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
hip::Device* dev = reinterpret_cast<hip::Device*>(ctx);
|
|
|
|
|
if (dev == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Need to remove the ctx of calling thread if its the top one
|
2022-09-26 15:59:27 +05:30
|
|
|
if (!tls.ctxt_stack_.empty() && tls.ctxt_stack_.top() == dev) {
|
|
|
|
|
tls.ctxt_stack_.pop();
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove context from global context list
|
|
|
|
|
for (unsigned int i = 0; i < g_devices.size(); i++) {
|
2020-02-18 12:36:12 -08:00
|
|
|
if (g_devices[i] == dev) {
|
2018-03-23 14:18:27 -04:00
|
|
|
// Decrement ref count for device primary context
|
2020-02-18 12:36:12 -08:00
|
|
|
dev->release();
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipCtxPopCurrent(hipCtx_t* ctx) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxPopCurrent, ctx);
|
2018-03-23 14:18:27 -04:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
hip::Device** dev = reinterpret_cast<hip::Device**>(ctx);
|
2022-09-26 15:59:27 +05:30
|
|
|
if (!tls.ctxt_stack_.empty()) {
|
2021-02-17 14:08:14 -05:00
|
|
|
if (dev != nullptr) {
|
2022-09-26 15:59:27 +05:30
|
|
|
*dev = tls.ctxt_stack_.top();
|
2021-02-17 14:08:14 -05:00
|
|
|
}
|
2022-09-26 15:59:27 +05:30
|
|
|
tls.ctxt_stack_.pop();
|
2018-03-23 14:18:27 -04:00
|
|
|
} else {
|
2020-04-13 22:51:46 -04:00
|
|
|
DevLogError("Context Stack empty \n");
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidContext);
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipCtxPushCurrent(hipCtx_t ctx) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxPushCurrent, ctx);
|
2018-03-23 14:18:27 -04:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
hip::Device* dev = reinterpret_cast<hip::Device*>(ctx);
|
|
|
|
|
if (dev == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidContext);
|
2018-03-23 14:18:27 -04:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 15:59:27 +05:30
|
|
|
hip::tls.device_ = dev;
|
|
|
|
|
tls.ctxt_stack_.push(hip::getCurrentDevice());
|
2018-03-23 14:18:27 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-28 19:23:57 -04:00
|
|
|
}
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-04-10 17:41:24 -04:00
|
|
|
hipError_t hipDriverGetVersion(int* driverVersion) {
|
2022-01-31 11:33:18 +00:00
|
|
|
HIP_INIT_API_NO_RETURN(hipDriverGetVersion, driverVersion);
|
2018-04-10 17:41:24 -04:00
|
|
|
|
2021-05-31 04:02:56 -07:00
|
|
|
if (!driverVersion) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-04-10 17:41:24 -04:00
|
|
|
}
|
|
|
|
|
|
2021-05-31 04:02:56 -07:00
|
|
|
// HIP_VERSION = HIP_VERSION_MAJOR*100 + HIP_MINOR_VERSION
|
|
|
|
|
*driverVersion = HIP_VERSION;
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-10 17:41:24 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipCtxGetDevice(hipDevice_t* device) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxGetDevice, device);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-04-24 16:49:38 -04:00
|
|
|
if (device != nullptr) {
|
2020-02-18 12:36:12 -08:00
|
|
|
*device = hip::getCurrentDevice()->deviceId();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-24 16:49:38 -04:00
|
|
|
} else {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-04-24 16:49:38 -04:00
|
|
|
}
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidContext);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipCtxGetApiVersion(hipCtx_t ctx, int* apiVersion) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxGetApiVersion, apiVersion);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
|
|
|
|
assert(0 && "Unimplemented");
|
|
|
|
|
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipCtxGetCacheConfig(hipFuncCache_t* cacheConfig) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxGetCacheConfig, cacheConfig);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
|
|
|
|
assert(0 && "Unimplemented");
|
|
|
|
|
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipCtxSetCacheConfig(hipFuncCache_t cacheConfig) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxSetCacheConfig, cacheConfig);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
|
|
|
|
assert(0 && "Unimplemented");
|
|
|
|
|
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipCtxSetSharedMemConfig(hipSharedMemConfig config) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxSetSharedMemConfig, config);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
|
|
|
|
assert(0 && "Unimplemented");
|
|
|
|
|
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipCtxSynchronize(void) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxSynchronize, 1);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
|
|
|
|
assert(0 && "Unimplemented");
|
|
|
|
|
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipCtxGetFlags(unsigned int* flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipCtxGetFlags, flags);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
|
|
|
|
assert(0 && "Unimplemented");
|
|
|
|
|
|
2019-10-30 13:37:03 -04:00
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDevicePrimaryCtxGetState(hipDevice_t dev, unsigned int* flags, int* active) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDevicePrimaryCtxGetState, dev, flags, active);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
if (static_cast<unsigned int>(dev) >= g_devices.size()) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
|
|
|
|
}
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
if (flags != nullptr) {
|
|
|
|
|
*flags = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (active != nullptr) {
|
2021-12-01 10:05:16 -08:00
|
|
|
*active = g_devices[dev]->GetActiveStatus() ? 1 : 0;
|
2019-08-03 12:23:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDevicePrimaryCtxRelease(hipDevice_t dev) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDevicePrimaryCtxRelease, dev);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
if (static_cast<unsigned int>(dev) >= g_devices.size()) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
|
|
|
|
}
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDevicePrimaryCtxRetain(hipCtx_t* pctx, hipDevice_t dev) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDevicePrimaryCtxRetain, pctx, dev);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
if (static_cast<unsigned int>(dev) >= g_devices.size()) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
|
|
|
|
}
|
|
|
|
|
if (pctx == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
*pctx = reinterpret_cast<hipCtx_t>(g_devices[dev]);
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDevicePrimaryCtxReset(hipDevice_t dev) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDevicePrimaryCtxReset, dev);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDevicePrimaryCtxSetFlags(hipDevice_t dev, unsigned int flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDevicePrimaryCtxSetFlags, dev, flags);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2019-08-03 12:23:25 -04:00
|
|
|
if (static_cast<unsigned int>(dev) >= g_devices.size()) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
|
|
|
|
} else {
|
|
|
|
|
HIP_RETURN(hipErrorContextAlreadyInUse);
|
|
|
|
|
}
|
2018-04-24 16:49:38 -04:00
|
|
|
}
|