2022-04-20 18:55:38 -04:00
|
|
|
/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc.
|
2018-02-13 19:45:32 -05:00
|
|
|
|
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:
|
2018-02-13 19:45:32 -05:00
|
|
|
|
2020-02-04 08:45:01 -08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
2018-02-13 19:45:32 -05:00
|
|
|
|
2020-02-04 08:45:01 -08:00
|
|
|
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-02-13 19:45:32 -05:00
|
|
|
|
|
|
|
|
#include <hip/hip_runtime.h>
|
|
|
|
|
#include "hip_internal.hpp"
|
2020-05-18 22:40:33 -04:00
|
|
|
#include "hip_platform.hpp"
|
2020-02-23 15:34:31 -05:00
|
|
|
#include "hip_conversions.hpp"
|
2018-04-19 18:35:00 -04:00
|
|
|
#include "platform/context.hpp"
|
|
|
|
|
#include "platform/command.hpp"
|
|
|
|
|
#include "platform/memory.hpp"
|
2023-04-19 16:48:00 -04:00
|
|
|
#include "platform/external_memory.hpp"
|
2018-02-13 19:45:32 -05:00
|
|
|
|
2022-05-13 12:39:47 +00:00
|
|
|
amd::Monitor hip::hipArraySetLock{"Guards global hipArray set"};
|
|
|
|
|
std::unordered_set<hipArray*> hip::hipArraySet;
|
|
|
|
|
|
2020-05-01 09:22:31 -04:00
|
|
|
// ================================================================================================
|
2022-04-01 11:12:04 -04:00
|
|
|
amd::Memory* getMemoryObject(const void* ptr, size_t& offset, size_t size) {
|
2023-01-13 18:00:52 -05:00
|
|
|
auto memObj = amd::MemObjMap::FindMemObj(ptr, &offset);
|
|
|
|
|
if (memObj == nullptr) {
|
2023-05-09 10:03:33 +00:00
|
|
|
// If memObj not found, use arena_mem_obj. arena_mem_obj is null, if HMM is disabled.
|
2022-04-01 11:12:04 -04:00
|
|
|
memObj = (hip::getCurrentDevice()->asContext()->svmDevices()[0])->GetArenaMemObj(
|
|
|
|
|
ptr, offset, size);
|
2018-05-08 15:43:13 -04:00
|
|
|
}
|
|
|
|
|
return memObj;
|
2020-05-26 14:26:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
amd::Memory* getMemoryObjectWithOffset(const void* ptr, const size_t size) {
|
2022-11-23 19:48:23 +00:00
|
|
|
size_t offset = 0;
|
2020-05-26 14:26:19 -04:00
|
|
|
amd::Memory* memObj = getMemoryObject(ptr, offset);
|
|
|
|
|
|
|
|
|
|
if (memObj != nullptr) {
|
2022-07-05 22:44:54 +00:00
|
|
|
if (size > (memObj->getSize() - offset)) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2020-05-26 14:26:19 -04:00
|
|
|
memObj = new (memObj->getContext()) amd::Buffer(*memObj, memObj->getMemFlags(), offset, size);
|
|
|
|
|
if (memObj == nullptr) {;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!memObj->create(nullptr)) {
|
|
|
|
|
memObj->release();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return memObj;
|
2018-05-08 15:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-01 09:22:31 -04:00
|
|
|
// ================================================================================================
|
2022-04-20 18:55:38 -04:00
|
|
|
hipError_t ihipFree(void *ptr) {
|
2020-04-03 12:34:59 -04:00
|
|
|
if (ptr == nullptr) {
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2020-05-01 09:22:31 -04:00
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memory_object = getMemoryObject(ptr, offset);
|
|
|
|
|
if (memory_object != nullptr) {
|
2022-04-20 18:55:38 -04:00
|
|
|
// Wait on the device, associated with the current memory object during allocation
|
|
|
|
|
auto device_id = memory_object->getUserData().deviceId;
|
2023-03-22 19:14:15 -04:00
|
|
|
hip::Stream::SyncAllStreams(device_id);
|
|
|
|
|
|
2022-12-14 18:54:16 -05:00
|
|
|
// Find out if memory belongs to any memory pool
|
|
|
|
|
if (!g_devices[device_id]->FreeMemory(memory_object, nullptr)) {
|
2023-01-12 07:08:30 +00:00
|
|
|
// External mem is not svm.
|
|
|
|
|
if (memory_object->isInterop()) {
|
|
|
|
|
amd::MemObjMap::RemoveMemObj(ptr);
|
|
|
|
|
memory_object->release();
|
|
|
|
|
} else {
|
|
|
|
|
amd::SvmBuffer::free(memory_object->getContext(), ptr);
|
|
|
|
|
}
|
2022-12-14 18:54:16 -05:00
|
|
|
}
|
2020-04-03 12:34:59 -04:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 18:55:38 -04:00
|
|
|
// ================================================================================================
|
|
|
|
|
hipError_t hipImportExternalMemory(
|
|
|
|
|
hipExternalMemory_t* extMem_out,
|
|
|
|
|
const hipExternalMemoryHandleDesc* memHandleDesc) {
|
2021-03-19 18:36:13 -04:00
|
|
|
HIP_INIT_API(hipImportExternalMemory, extMem_out, memHandleDesc);
|
2023-01-05 07:56:33 -05:00
|
|
|
if (extMem_out == nullptr || memHandleDesc == nullptr ||
|
|
|
|
|
(memHandleDesc->flags != 0 && memHandleDesc->flags != hipExternalMemoryDedicated) ||
|
|
|
|
|
memHandleDesc->size == 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-03-19 18:36:13 -04:00
|
|
|
|
2023-03-17 08:16:45 +00:00
|
|
|
if ((memHandleDesc->type < hipExternalMemoryHandleTypeOpaqueFd) ||
|
|
|
|
|
(memHandleDesc->type > hipExternalMemoryHandleTypeD3D11ResourceKmt)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 18:36:13 -04:00
|
|
|
amd::Context& amdContext = *hip::getCurrentDevice()->asContext();
|
|
|
|
|
#ifdef _WIN32
|
2023-04-19 16:48:00 -04:00
|
|
|
auto ext_buffer = new (amdContext) amd::ExternalBuffer(amdContext, memHandleDesc->size,
|
|
|
|
|
memHandleDesc->handle.win32.handle,
|
|
|
|
|
static_cast<amd::ExternalMemory::HandleType>(memHandleDesc->type));
|
2021-03-19 18:36:13 -04:00
|
|
|
#else
|
2023-04-19 16:48:00 -04:00
|
|
|
auto ext_buffer = new (amdContext) amd::ExternalBuffer(amdContext, memHandleDesc->size,
|
|
|
|
|
memHandleDesc->handle.fd,
|
|
|
|
|
static_cast<amd::ExternalMemory::HandleType>(memHandleDesc->type));
|
2021-03-19 18:36:13 -04:00
|
|
|
#endif
|
|
|
|
|
|
2023-04-19 16:48:00 -04:00
|
|
|
if (!ext_buffer) {
|
2021-03-19 18:36:13 -04:00
|
|
|
HIP_RETURN(hipErrorOutOfMemory);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 16:48:00 -04:00
|
|
|
if (!ext_buffer->create()) {
|
|
|
|
|
ext_buffer->release();
|
2021-03-19 18:36:13 -04:00
|
|
|
HIP_RETURN(hipErrorOutOfMemory);
|
|
|
|
|
}
|
2023-04-19 16:48:00 -04:00
|
|
|
*extMem_out = ext_buffer;
|
2021-03-19 18:36:13 -04:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 18:55:38 -04:00
|
|
|
// ================================================================================================
|
|
|
|
|
hipError_t hipExternalMemoryGetMappedBuffer(
|
|
|
|
|
void **devPtr,
|
|
|
|
|
hipExternalMemory_t extMem,
|
|
|
|
|
const hipExternalMemoryBufferDesc *bufferDesc) {
|
2021-03-19 18:36:13 -04:00
|
|
|
HIP_INIT_API(hipExternalMemoryGetMappedBuffer, devPtr, extMem, bufferDesc);
|
|
|
|
|
|
2022-12-22 09:51:12 +00:00
|
|
|
if (devPtr == nullptr || extMem == nullptr || bufferDesc == nullptr || bufferDesc->flags != 0) {
|
2021-03-19 18:36:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-04-19 16:48:00 -04:00
|
|
|
auto buf = reinterpret_cast<amd::ExternalBuffer*>(extMem);
|
2021-03-19 18:36:13 -04:00
|
|
|
const device::Memory* devMem = buf->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]);
|
2022-12-22 09:51:12 +00:00
|
|
|
|
|
|
|
|
if (devMem == nullptr || ((bufferDesc->offset + bufferDesc->size) > devMem->size())) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-03-19 18:36:13 -04:00
|
|
|
}
|
2022-12-22 09:51:12 +00:00
|
|
|
*devPtr = reinterpret_cast<void*>(devMem->virtualAddress() + bufferDesc->offset);
|
2023-01-12 07:08:30 +00:00
|
|
|
amd::MemObjMap::AddMemObj(*devPtr, buf);
|
|
|
|
|
buf->retain();
|
2021-03-19 18:36:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 16:48:00 -04:00
|
|
|
// ================================================================================================
|
2021-03-19 18:36:13 -04:00
|
|
|
hipError_t hipDestroyExternalMemory(hipExternalMemory_t extMem) {
|
|
|
|
|
HIP_INIT_API(hipDestroyExternalMemory, extMem);
|
|
|
|
|
|
|
|
|
|
if (extMem == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-04-19 16:48:00 -04:00
|
|
|
reinterpret_cast<amd::ExternalBuffer*>(extMem)->release();
|
2021-03-19 18:36:13 -04:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 16:48:00 -04:00
|
|
|
// ================================================================================================
|
2021-04-22 20:21:01 -04:00
|
|
|
hipError_t hipImportExternalSemaphore(hipExternalSemaphore_t* extSem_out,
|
|
|
|
|
const hipExternalSemaphoreHandleDesc* semHandleDesc)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(hipImportExternalSemaphore, extSem_out, semHandleDesc);
|
|
|
|
|
if (extSem_out == nullptr || semHandleDesc == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-03-17 08:16:45 +00:00
|
|
|
|
|
|
|
|
if ((semHandleDesc->type < hipExternalSemaphoreHandleTypeOpaqueFd) ||
|
|
|
|
|
(semHandleDesc->type > hipExternalSemaphoreHandleTypeD3D12Fence)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-04-22 20:21:01 -04:00
|
|
|
amd::Device* device = hip::getCurrentDevice()->devices()[0];
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2023-04-11 13:37:45 -04:00
|
|
|
if (device->importExtSemaphore(extSem_out, semHandleDesc->handle.win32.handle,
|
|
|
|
|
static_cast <amd::ExternalSemaphoreHandleType>
|
|
|
|
|
(semHandleDesc->type))) {
|
2021-04-22 20:21:01 -04:00
|
|
|
#else
|
2023-04-11 13:37:45 -04:00
|
|
|
if (device->importExtSemaphore(extSem_out, semHandleDesc->handle.fd,
|
|
|
|
|
static_cast <amd::ExternalSemaphoreHandleType>
|
|
|
|
|
(semHandleDesc->type))) {
|
2021-04-22 20:21:01 -04:00
|
|
|
#endif
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
2022-10-17 10:59:22 -04:00
|
|
|
HIP_RETURN(hipErrorNotSupported);
|
2021-04-22 20:21:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hipError_t hipSignalExternalSemaphoresAsync(
|
|
|
|
|
const hipExternalSemaphore_t* extSemArray, const hipExternalSemaphoreSignalParams* paramsArray,
|
|
|
|
|
unsigned int numExtSems, hipStream_t stream )
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(hipSignalExternalSemaphoresAsync, extSemArray, paramsArray, numExtSems, stream);
|
2023-06-20 10:50:03 -04:00
|
|
|
if (extSemArray == nullptr || paramsArray == nullptr || !hip::isValid(stream)) {
|
2021-04-22 20:21:01 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-04-22 20:21:01 -04:00
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < numExtSems; i++) {
|
|
|
|
|
if (extSemArray[i] != nullptr) {
|
|
|
|
|
amd::ExternalSemaphoreCmd* command =
|
2023-02-08 20:18:11 +00:00
|
|
|
new amd::ExternalSemaphoreCmd(*hip_stream, extSemArray[i], paramsArray[i].params.fence.value,
|
2021-04-22 20:21:01 -04:00
|
|
|
amd::ExternalSemaphoreCmd::COMMAND_SIGNAL_EXTSEMAPHORE);
|
|
|
|
|
if (command == nullptr) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
command->enqueue();
|
|
|
|
|
command->release();
|
|
|
|
|
} else {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipWaitExternalSemaphoresAsync(const hipExternalSemaphore_t* extSemArray,
|
|
|
|
|
const hipExternalSemaphoreWaitParams* paramsArray,
|
|
|
|
|
unsigned int numExtSems, hipStream_t stream)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(hipWaitExternalSemaphoresAsync, extSemArray, paramsArray, numExtSems,
|
|
|
|
|
stream);
|
2023-06-20 10:50:03 -04:00
|
|
|
if (extSemArray == nullptr || paramsArray == nullptr || !hip::isValid(stream)) {
|
2021-04-22 20:21:01 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-04-22 20:21:01 -04:00
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < numExtSems; i++) {
|
|
|
|
|
if (extSemArray[i] != nullptr) {
|
|
|
|
|
amd::ExternalSemaphoreCmd* command =
|
2023-02-08 20:18:11 +00:00
|
|
|
new amd::ExternalSemaphoreCmd(*hip_stream, extSemArray[i], paramsArray[i].params.fence.value,
|
2021-04-22 20:21:01 -04:00
|
|
|
amd::ExternalSemaphoreCmd::COMMAND_WAIT_EXTSEMAPHORE);
|
|
|
|
|
if (command == nullptr) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
command->enqueue();
|
|
|
|
|
command->release();
|
|
|
|
|
} else {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDestroyExternalSemaphore(hipExternalSemaphore_t extSem)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(hipDestroyExternalSemaphore, extSem);
|
|
|
|
|
if (extSem == nullptr ) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
amd::Device* device = hip::getCurrentDevice()->devices()[0];
|
|
|
|
|
device->DestroyExtSemaphore(extSem);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-05-01 09:22:31 -04:00
|
|
|
// ================================================================================================
|
2018-04-06 18:08:18 -04:00
|
|
|
hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
|
|
|
|
|
{
|
2020-12-17 10:38:13 -05:00
|
|
|
if (ptr == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
if (sizeBytes == 0) {
|
|
|
|
|
*ptr = nullptr;
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-02-13 19:45:32 -05:00
|
|
|
|
2020-06-05 15:29:08 -04:00
|
|
|
bool useHostDevice = (flags & CL_MEM_SVM_FINE_GRAIN_BUFFER) != 0;
|
|
|
|
|
amd::Context* curDevContext = hip::getCurrentDevice()->asContext();
|
2023-02-16 01:27:08 +00:00
|
|
|
amd::Context* amdContext = useHostDevice ? hip::host_context : curDevContext;
|
2019-04-05 11:58:25 -04:00
|
|
|
|
2019-12-17 20:18:36 -05:00
|
|
|
if (amdContext == nullptr) {
|
2019-12-30 16:46:39 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2019-12-17 20:18:36 -05:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 15:44:15 +00:00
|
|
|
const auto& dev_info = amdContext->devices()[0]->info();
|
2023-07-12 13:20:02 -04:00
|
|
|
hip::getCurrentDevice()->SetActiveStatus();
|
2021-11-23 15:44:15 +00:00
|
|
|
|
|
|
|
|
if ((!useHostDevice && (dev_info.maxMemAllocSize_ < sizeBytes)) ||
|
|
|
|
|
(useHostDevice && (dev_info.maxPhysicalMemAllocSize_ < sizeBytes))) {
|
2019-12-30 16:46:39 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2018-02-13 19:45:32 -05:00
|
|
|
|
2021-11-23 15:44:15 +00:00
|
|
|
*ptr = amd::SvmBuffer::malloc(*amdContext, flags, sizeBytes, dev_info.memBaseAddrAlign_,
|
2020-06-05 15:29:08 -04:00
|
|
|
useHostDevice ? curDevContext->svmDevices()[0] : nullptr);
|
2021-09-08 11:01:02 -07:00
|
|
|
|
2018-05-02 21:08:53 -04:00
|
|
|
if (*ptr == nullptr) {
|
2021-10-19 18:25:22 +00:00
|
|
|
if (!useHostDevice) {
|
|
|
|
|
size_t free = 0, total =0;
|
|
|
|
|
hipError_t err = hipMemGetInfo(&free, &total);
|
|
|
|
|
if (err == hipSuccess) {
|
|
|
|
|
LogPrintfError("Allocation failed : Device memory : required :%zu | free :%zu | total :%zu \n", sizeBytes, free, total);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LogPrintfError("Allocation failed : Pinned Memory, size :%zu \n", sizeBytes);
|
|
|
|
|
}
|
2020-03-30 12:37:08 -07:00
|
|
|
return hipErrorOutOfMemory;
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2021-09-27 16:38:30 -04:00
|
|
|
size_t offset = 0; //this is ignored
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(*ptr, offset);
|
2021-09-17 19:18:10 -04:00
|
|
|
//saves the current device id so that it can be accessed later
|
|
|
|
|
memObj->getUserData().deviceId = hip::getCurrentDevice()->deviceId();
|
2018-04-06 18:08:18 -04:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2023-01-02 13:08:13 +00:00
|
|
|
bool IsHtoHMemcpyValid(void* dst, const void* src, hipMemcpyKind kind) {
|
|
|
|
|
size_t sOffset = 0;
|
|
|
|
|
amd::Memory* srcMemory = getMemoryObject(src, sOffset);
|
|
|
|
|
size_t dOffset = 0;
|
|
|
|
|
amd::Memory* dstMemory = getMemoryObject(dst, dOffset);
|
|
|
|
|
if (src && dst && srcMemory == nullptr && dstMemory == nullptr) {
|
|
|
|
|
if (kind != hipMemcpyHostToHost && kind != hipMemcpyDefault) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t ihipMemcpy_validate(void* dst, const void* src, size_t sizeBytes,
|
2021-03-11 12:10:49 -08:00
|
|
|
hipMemcpyKind kind) {
|
2020-05-20 03:50:36 -04:00
|
|
|
if (dst == nullptr || src == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-06-20 10:49:35 -07:00
|
|
|
|
2018-05-08 15:43:13 -04:00
|
|
|
size_t sOffset = 0;
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Memory* srcMemory = getMemoryObject(src, sOffset);
|
2018-05-08 15:43:13 -04:00
|
|
|
size_t dOffset = 0;
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Memory* dstMemory = getMemoryObject(dst, dOffset);
|
2021-04-06 06:37:14 -07:00
|
|
|
// Return error if sizeBytes passed to memcpy is more than the actual size allocated
|
|
|
|
|
if ((dstMemory && sizeBytes > (dstMemory->getSize() - dOffset)) ||
|
|
|
|
|
(srcMemory && sizeBytes > (srcMemory->getSize() - sOffset))) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2023-01-02 13:08:13 +00:00
|
|
|
//If src and dst ptr are null then kind must be either h2h or def.
|
|
|
|
|
if (!IsHtoHMemcpyValid(dst, src, kind)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2021-04-06 06:37:14 -07:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipMemcpyCommand(amd::Command*& command, void* dst, const void* src, size_t sizeBytes,
|
2023-02-08 20:18:11 +00:00
|
|
|
hipMemcpyKind kind, hip::Stream& stream, bool isAsync) {
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Command::EventWaitList waitList;
|
|
|
|
|
size_t sOffset = 0;
|
|
|
|
|
amd::Memory* srcMemory = getMemoryObject(src, sOffset);
|
|
|
|
|
size_t dOffset = 0;
|
|
|
|
|
amd::Memory* dstMemory = getMemoryObject(dst, dOffset);
|
2023-02-08 20:18:11 +00:00
|
|
|
amd::Device* queueDevice = &stream.device();
|
2022-12-01 16:32:01 +00:00
|
|
|
amd::CopyMetadata copyMetadata(isAsync, amd::CopyMetadata::CopyEnginePreference::SDMA);
|
2021-03-11 12:10:49 -08:00
|
|
|
if ((srcMemory == nullptr) && (dstMemory != nullptr)) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* pStream = &stream;
|
2019-08-08 19:03:46 -04:00
|
|
|
if (queueDevice != dstMemory->getContext().devices()[0]) {
|
2023-02-08 20:18:11 +00:00
|
|
|
pStream = hip::getNullStream(dstMemory->getContext());
|
|
|
|
|
amd::Command* cmd = stream.getLastQueuedCommand(true);
|
2020-05-08 11:23:58 -07:00
|
|
|
if (cmd != nullptr) {
|
|
|
|
|
waitList.push_back(cmd);
|
|
|
|
|
}
|
2019-08-08 19:03:46 -04:00
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
command = new amd::WriteMemoryCommand(*pStream, CL_COMMAND_WRITE_BUFFER, waitList,
|
2022-12-01 16:32:01 +00:00
|
|
|
*dstMemory->asBuffer(), dOffset, sizeBytes, src, 0, 0, copyMetadata);
|
2018-07-31 15:07:56 -04:00
|
|
|
} else if ((srcMemory != nullptr) && (dstMemory == nullptr)) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* pStream = &stream;
|
2019-08-08 19:03:46 -04:00
|
|
|
if (queueDevice != srcMemory->getContext().devices()[0]) {
|
2023-02-08 20:18:11 +00:00
|
|
|
pStream = hip::getNullStream(srcMemory->getContext());
|
|
|
|
|
amd::Command* cmd = stream.getLastQueuedCommand(true);
|
2020-05-08 11:23:58 -07:00
|
|
|
if (cmd != nullptr) {
|
|
|
|
|
waitList.push_back(cmd);
|
|
|
|
|
}
|
2019-08-08 19:03:46 -04:00
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
command = new amd::ReadMemoryCommand(*pStream, CL_COMMAND_READ_BUFFER, waitList,
|
2022-12-01 16:32:01 +00:00
|
|
|
*srcMemory->asBuffer(), sOffset, sizeBytes, dst, 0, 0, copyMetadata);
|
2018-07-31 15:07:56 -04:00
|
|
|
} else if ((srcMemory != nullptr) && (dstMemory != nullptr)) {
|
2020-07-20 12:03:04 -04:00
|
|
|
// Check if the queue device doesn't match the device on any memory object.
|
|
|
|
|
// And any of them are not host allocation.
|
|
|
|
|
// Hence it's a P2P transfer, because the app has requested access to another GPU
|
|
|
|
|
if ((srcMemory->getContext().devices()[0] != dstMemory->getContext().devices()[0]) &&
|
|
|
|
|
((srcMemory->getContext().devices().size() == 1) &&
|
|
|
|
|
(dstMemory->getContext().devices().size() == 1))) {
|
2023-02-08 20:18:11 +00:00
|
|
|
command = new amd::CopyMemoryP2PCommand(stream, CL_COMMAND_COPY_BUFFER, waitList,
|
2020-06-13 00:52:36 -04:00
|
|
|
*srcMemory->asBuffer(), *dstMemory->asBuffer(), sOffset, dOffset, sizeBytes);
|
|
|
|
|
if (command == nullptr) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
2019-04-17 18:38:30 -04:00
|
|
|
}
|
2020-06-13 00:52:36 -04:00
|
|
|
// Make sure runtime has valid memory for the command execution. P2P access
|
|
|
|
|
// requires page table mapping on the current device to another GPU memory
|
|
|
|
|
if (!static_cast<amd::CopyMemoryP2PCommand*>(command)->validateMemory()) {
|
|
|
|
|
delete command;
|
|
|
|
|
return hipErrorInvalidValue;
|
2019-04-17 18:38:30 -04:00
|
|
|
}
|
2020-06-13 00:52:36 -04:00
|
|
|
} else {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* pStream = &stream;
|
2020-12-28 11:27:09 -05:00
|
|
|
if ((srcMemory->getContext().devices()[0] == dstMemory->getContext().devices()[0]) &&
|
2020-10-05 13:20:58 -04:00
|
|
|
(queueDevice != srcMemory->getContext().devices()[0])) {
|
2022-12-01 16:32:01 +00:00
|
|
|
copyMetadata.copyEnginePreference_ = amd::CopyMetadata::CopyEnginePreference::NONE;
|
2023-02-08 20:18:11 +00:00
|
|
|
pStream = hip::getNullStream(srcMemory->getContext());
|
|
|
|
|
amd::Command* cmd = stream.getLastQueuedCommand(true);
|
2020-07-21 12:10:43 -04:00
|
|
|
if (cmd != nullptr) {
|
|
|
|
|
waitList.push_back(cmd);
|
|
|
|
|
}
|
2020-12-28 11:27:09 -05:00
|
|
|
} else if (srcMemory->getContext().devices()[0] != dstMemory->getContext().devices()[0]) {
|
|
|
|
|
// Scenarios such as DtoH where dst is pinned memory
|
|
|
|
|
if ((queueDevice != srcMemory->getContext().devices()[0]) &&
|
|
|
|
|
(dstMemory->getContext().devices().size() != 1)) {
|
2023-02-08 20:18:11 +00:00
|
|
|
pStream = hip::getNullStream(srcMemory->getContext());
|
|
|
|
|
amd::Command* cmd = stream.getLastQueuedCommand(true);
|
2020-12-28 11:27:09 -05:00
|
|
|
if (cmd != nullptr) {
|
|
|
|
|
waitList.push_back(cmd);
|
|
|
|
|
}
|
|
|
|
|
// Scenarios such as HtoD where src is pinned memory
|
|
|
|
|
} else if ((queueDevice != dstMemory->getContext().devices()[0]) &&
|
|
|
|
|
(srcMemory->getContext().devices().size() != 1)) {
|
2023-02-08 20:18:11 +00:00
|
|
|
pStream = hip::getNullStream(dstMemory->getContext());
|
|
|
|
|
amd::Command* cmd = stream.getLastQueuedCommand(true);
|
2020-12-28 11:27:09 -05:00
|
|
|
if (cmd != nullptr) {
|
|
|
|
|
waitList.push_back(cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-21 12:10:43 -04:00
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
command = new amd::CopyMemoryCommand(*pStream, CL_COMMAND_COPY_BUFFER, waitList,
|
2022-12-01 16:32:01 +00:00
|
|
|
*srcMemory->asBuffer(), *dstMemory->asBuffer(), sOffset, dOffset, sizeBytes,
|
|
|
|
|
copyMetadata);
|
2019-04-17 18:38:30 -04:00
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2018-05-02 21:08:53 -04:00
|
|
|
if (command == nullptr) {
|
2018-03-01 22:57:20 -05:00
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
2021-04-30 17:52:33 +00:00
|
|
|
if (waitList.size() > 0) {
|
|
|
|
|
waitList[0]->release();
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2023-01-02 13:08:13 +00:00
|
|
|
bool IsHtoHMemcpy(void* dst, const void* src, hipMemcpyKind kind) {
|
|
|
|
|
size_t sOffset = 0;
|
|
|
|
|
amd::Memory* srcMemory = getMemoryObject(src, sOffset);
|
|
|
|
|
size_t dOffset = 0;
|
|
|
|
|
amd::Memory* dstMemory = getMemoryObject(dst, dOffset);
|
|
|
|
|
if (srcMemory == nullptr && dstMemory == nullptr) {
|
|
|
|
|
if (kind == hipMemcpyHostToHost || kind == hipMemcpyDefault) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
void ihipHtoHMemcpy(void* dst, const void* src, size_t sizeBytes, hip::Stream& stream) {
|
|
|
|
|
stream.finish();
|
2023-01-02 13:08:13 +00:00
|
|
|
memcpy(dst, src, sizeBytes);
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
// ================================================================================================
|
|
|
|
|
hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
|
2023-02-27 17:23:01 +00:00
|
|
|
hip::Stream& stream, bool isHostAsync, bool isGPUAsync) {
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status;
|
|
|
|
|
if (sizeBytes == 0) {
|
|
|
|
|
// Skip if nothing needs writing.
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
status = ihipMemcpy_validate(dst, src, sizeBytes, kind);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2022-06-20 10:49:35 -07:00
|
|
|
if (src == dst && kind == hipMemcpyDefault) {
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
size_t sOffset = 0;
|
|
|
|
|
amd::Memory* srcMemory = getMemoryObject(src, sOffset);
|
|
|
|
|
size_t dOffset = 0;
|
|
|
|
|
amd::Memory* dstMemory = getMemoryObject(dst, dOffset);
|
2023-01-02 13:08:13 +00:00
|
|
|
if (srcMemory == nullptr && dstMemory == nullptr) {
|
2023-02-08 20:18:11 +00:00
|
|
|
ihipHtoHMemcpy(dst, src, sizeBytes, stream);
|
2023-01-02 13:08:13 +00:00
|
|
|
return hipSuccess;
|
2023-02-21 16:32:29 -08:00
|
|
|
} else if (((srcMemory == nullptr) && (dstMemory != nullptr)) ||
|
|
|
|
|
((srcMemory != nullptr) && (dstMemory == nullptr))) {
|
2023-02-27 17:23:01 +00:00
|
|
|
isHostAsync = false;
|
2023-04-10 07:41:47 +00:00
|
|
|
} else if (srcMemory->getContext().devices()[0] == dstMemory->getContext().devices()[0]) {
|
2023-02-21 16:32:29 -08:00
|
|
|
hipMemoryType srcMemoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
|
|
|
|
srcMemory->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice;
|
|
|
|
|
hipMemoryType dstMemoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
|
|
|
|
dstMemory->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice;
|
|
|
|
|
// Device to Device copies do not need to host side synchronization.
|
|
|
|
|
if ((srcMemoryType == hipMemoryTypeDevice) && (dstMemoryType == hipMemoryTypeDevice)) {
|
|
|
|
|
isHostAsync = true;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
}
|
2023-02-27 17:23:01 +00:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Command* command = nullptr;
|
2023-02-27 17:23:01 +00:00
|
|
|
status = ihipMemcpyCommand(command, dst, src, sizeBytes, kind, stream, isHostAsync);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
command->enqueue();
|
2023-02-27 17:23:01 +00:00
|
|
|
if (!isHostAsync) {
|
2018-05-05 00:34:05 -04:00
|
|
|
command->awaitCompletion();
|
2023-02-27 17:23:01 +00:00
|
|
|
} else if (!isGPUAsync) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* pStream = hip::getNullStream(dstMemory->getContext());
|
2023-02-06 17:27:31 +00:00
|
|
|
amd::Command::EventWaitList waitList;
|
|
|
|
|
waitList.push_back(command);
|
2023-02-08 20:18:11 +00:00
|
|
|
amd::Command* depdentMarker = new amd::Marker(*pStream, false, waitList);
|
2023-02-06 17:27:31 +00:00
|
|
|
if (depdentMarker != nullptr) {
|
|
|
|
|
depdentMarker->enqueue();
|
|
|
|
|
depdentMarker->release();
|
|
|
|
|
}
|
2021-03-31 00:26:23 -07:00
|
|
|
} else {
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::HostQueue* newQueue = command->queue();
|
2023-02-08 20:18:11 +00:00
|
|
|
if (newQueue != &stream) {
|
2021-03-31 00:26:23 -07:00
|
|
|
amd::Command::EventWaitList waitList;
|
|
|
|
|
amd::Command* cmd = newQueue->getLastQueuedCommand(true);
|
|
|
|
|
if (cmd != nullptr) {
|
|
|
|
|
waitList.push_back(cmd);
|
2023-02-08 20:18:11 +00:00
|
|
|
amd::Command* depdentMarker = new amd::Marker(stream, true, waitList);
|
2021-03-31 00:26:23 -07:00
|
|
|
if (depdentMarker != nullptr) {
|
|
|
|
|
depdentMarker->enqueue();
|
|
|
|
|
depdentMarker->release();
|
|
|
|
|
}
|
|
|
|
|
cmd->release();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-05 00:34:05 -04:00
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
command->release();
|
|
|
|
|
return hipSuccess;
|
2018-02-14 15:08:01 -05:00
|
|
|
}
|
2018-02-13 19:45:32 -05:00
|
|
|
|
2020-06-13 00:52:36 -04:00
|
|
|
// ================================================================================================
|
2019-06-13 12:47:17 -04:00
|
|
|
hipError_t hipExtMallocWithFlags(void** ptr, size_t sizeBytes, unsigned int flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipExtMallocWithFlags, ptr, sizeBytes, flags);
|
2019-06-13 12:47:17 -04:00
|
|
|
|
2020-12-14 15:28:01 -08:00
|
|
|
unsigned int ihipFlags = 0;
|
|
|
|
|
if (flags == hipDeviceMallocDefault) {
|
|
|
|
|
ihipFlags = 0;
|
|
|
|
|
} else if (flags == hipDeviceMallocFinegrained) {
|
2023-01-09 15:05:03 -08:00
|
|
|
ihipFlags = CL_MEM_SVM_ATOMICS;
|
|
|
|
|
} else if (flags == hipDeviceMallocUncached) {
|
|
|
|
|
ihipFlags = CL_MEM_SVM_ATOMICS | ROCCLR_MEM_HSA_UNCACHED;
|
2020-12-14 15:28:01 -08:00
|
|
|
} else if (flags == hipMallocSignalMemory) {
|
|
|
|
|
ihipFlags = CL_MEM_SVM_ATOMICS | CL_MEM_SVM_FINE_GRAIN_BUFFER | ROCCLR_MEM_HSA_SIGNAL_MEMORY;
|
|
|
|
|
if (sizeBytes != 8) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-06-13 12:47:17 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 23:33:36 +05:30
|
|
|
hipError_t status = ihipMalloc(ptr, sizeBytes, ihipFlags);
|
|
|
|
|
|
|
|
|
|
if ((status == hipSuccess) && ((*ptr) != nullptr)) {
|
|
|
|
|
size_t offset = 0; // This is ignored
|
|
|
|
|
amd::Memory* svmMem = getMemoryObject(*ptr, offset);
|
|
|
|
|
// Save the HIP memory flags so that they can be accessed later
|
|
|
|
|
svmMem->getUserData().flags = flags;
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(status, (ptr != nullptr)? *ptr : nullptr);
|
2019-06-13 12:47:17 -04:00
|
|
|
}
|
|
|
|
|
|
2018-05-05 00:34:05 -04:00
|
|
|
hipError_t hipMalloc(void** ptr, size_t sizeBytes) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipMalloc, ptr, sizeBytes);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-12-17 10:38:13 -05:00
|
|
|
HIP_RETURN_DURATION(ihipMalloc(ptr, sizeBytes, 0), (ptr != nullptr)? *ptr : nullptr);
|
2018-05-05 00:34:05 -04:00
|
|
|
}
|
2018-03-02 17:55:48 -05:00
|
|
|
|
2018-05-05 00:34:05 -04:00
|
|
|
hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipHostMalloc, ptr, sizeBytes, flags);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2018-05-16 16:35:53 -04:00
|
|
|
if (ptr == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-05-16 16:35:53 -04:00
|
|
|
}
|
|
|
|
|
*ptr = nullptr;
|
|
|
|
|
|
|
|
|
|
const unsigned int coherentFlags = hipHostMallocCoherent | hipHostMallocNonCoherent;
|
|
|
|
|
|
|
|
|
|
// can't have both Coherent and NonCoherent flags set at the same time
|
|
|
|
|
if ((flags & coherentFlags) == coherentFlags) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError(
|
|
|
|
|
"Cannot have both coherent and non-coherent flags "
|
|
|
|
|
"at the same time, flags: %u coherent flags: %u \n",
|
|
|
|
|
flags, coherentFlags);
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-05-16 16:35:53 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 23:33:36 +05:30
|
|
|
unsigned int ihipFlags = CL_MEM_SVM_FINE_GRAIN_BUFFER;
|
2022-04-05 00:45:56 -07:00
|
|
|
if (flags == 0 ||
|
|
|
|
|
flags & (hipHostMallocCoherent | hipHostMallocMapped | hipHostMallocNumaUser) ||
|
|
|
|
|
(!(flags & hipHostMallocNonCoherent) && HIP_HOST_COHERENT)) {
|
|
|
|
|
ihipFlags |= CL_MEM_SVM_ATOMICS;
|
|
|
|
|
}
|
2019-10-04 19:02:35 -04:00
|
|
|
|
2020-06-18 15:41:05 -04:00
|
|
|
if (flags & hipHostMallocNumaUser) {
|
2022-02-25 10:51:11 -08:00
|
|
|
ihipFlags |= CL_MEM_FOLLOW_USER_NUMA_POLICY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags & hipHostMallocNonCoherent) {
|
|
|
|
|
ihipFlags &= ~CL_MEM_SVM_ATOMICS;
|
2020-06-18 15:41:05 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 23:33:36 +05:30
|
|
|
hipError_t status = ihipMalloc(ptr, sizeBytes, ihipFlags);
|
|
|
|
|
|
|
|
|
|
if ((status == hipSuccess) && ((*ptr) != nullptr)) {
|
|
|
|
|
size_t offset = 0; // This is ignored
|
|
|
|
|
amd::Memory* svmMem = getMemoryObject(*ptr, offset);
|
|
|
|
|
// Save the HIP memory flags so that they can be accessed later
|
|
|
|
|
svmMem->getUserData().flags = flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN_DURATION(status, *ptr);
|
2018-05-05 00:34:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipFree(void* ptr) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipFree, ptr);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-04-03 12:34:59 -04:00
|
|
|
HIP_RETURN(ihipFree(ptr));
|
2018-05-05 00:34:05 -04:00
|
|
|
}
|
2018-04-19 18:35:00 -04:00
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpy_common(void* dst, const void* src, size_t sizeBytes,
|
|
|
|
|
hipMemcpyKind kind, hipStream_t stream = nullptr) {
|
|
|
|
|
CHECK_STREAM_CAPTURING();
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = nullptr;
|
2022-04-13 06:35:25 +00:00
|
|
|
|
|
|
|
|
if (stream != nullptr) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip_stream = hip::getStream(stream);
|
2022-04-13 06:35:25 +00:00
|
|
|
} else {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip_stream = hip::getNullStream();
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
2022-12-26 23:56:12 +05:30
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
return ihipMemcpy(dst, src, sizeBytes, kind, *hip_stream);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-05 00:34:05 -04:00
|
|
|
hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipMemcpy, dst, src, sizeBytes, kind);
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy_common(dst, src, sizeBytes, kind));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy_spt(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy, dst, src, sizeBytes, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy_common(dst, src, sizeBytes, kind, getPerThreadDefaultStream()));
|
2018-05-05 00:34:05 -04:00
|
|
|
}
|
2018-04-19 18:35:00 -04:00
|
|
|
|
2019-11-26 17:03:41 -05:00
|
|
|
hipError_t hipMemcpyWithStream(void* dst, const void* src, size_t sizeBytes,
|
|
|
|
|
hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyWithStream, dst, src, sizeBytes, kind, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
STREAM_CAPTURE(hipMemcpyAsync, stream, dst, src, sizeBytes, kind);
|
2023-01-17 10:54:14 -05:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
HIP_RETURN(hipErrorContextIsDestroyed);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2019-11-26 17:03:41 -05:00
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy(dst, src, sizeBytes, kind, *hip_stream, false));
|
2019-11-26 17:03:41 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipMemPtrGetInfo(void *ptr, size_t *size) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipMemPtrGetInfo, ptr, size);
|
2018-03-02 17:55:48 -05:00
|
|
|
|
2018-05-08 15:43:13 -04:00
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* svmMem = getMemoryObject(ptr, offset);
|
2018-03-02 17:55:48 -05:00
|
|
|
|
2018-04-24 14:05:20 -04:00
|
|
|
if (svmMem == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-04-24 14:05:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*size = svmMem->getSize();
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-02 17:55:48 -05:00
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipHostFree(void* ptr) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipHostFree, ptr);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2022-05-20 22:14:18 -04:00
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memory_object = getMemoryObject(ptr, offset);
|
|
|
|
|
if (memory_object != nullptr) {
|
|
|
|
|
if (memory_object->getSvmPtr() == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-03 12:34:59 -04:00
|
|
|
HIP_RETURN(ihipFree(ptr));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t ihipArrayDestroy(hipArray* array) {
|
|
|
|
|
if (array == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-05-13 12:39:47 +00:00
|
|
|
{
|
|
|
|
|
amd::ScopedLock lock(hip::hipArraySetLock);
|
|
|
|
|
if (hip::hipArraySet.find(array) == hip::hipArraySet.end()) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
2022-07-21 14:13:06 -04:00
|
|
|
} else {
|
|
|
|
|
hip::hipArraySet.erase(array);
|
2022-05-13 12:39:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
cl_mem memObj = reinterpret_cast<cl_mem>(array->data);
|
|
|
|
|
if (is_valid(memObj) == false) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-06-02 10:15:21 -07:00
|
|
|
|
2023-03-22 19:14:15 -04:00
|
|
|
auto image = as_amd(memObj);
|
|
|
|
|
// Wait on the device, associated with the current memory object during allocation
|
|
|
|
|
hip::Stream::SyncAllStreams(image->getUserData().deviceId);
|
|
|
|
|
image->release();
|
2022-06-02 10:15:21 -07:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
delete array;
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipFreeArray(hipArray* array) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipFreeArray, array);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_RETURN(ihipArrayDestroy(array));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipMemGetAddressRange, pbase, psize, dptr);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2018-04-24 14:05:20 -04:00
|
|
|
// Since we are using SVM buffer DevicePtr and HostPtr is the same
|
|
|
|
|
void* ptr = dptr;
|
2023-04-13 22:59:59 +00:00
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* svmMem = getMemoryObject(ptr, offset);
|
2018-04-24 14:05:20 -04:00
|
|
|
if (svmMem == nullptr) {
|
2022-11-23 19:48:23 +00:00
|
|
|
HIP_RETURN(hipErrorNotFound);
|
2018-04-24 14:05:20 -04:00
|
|
|
}
|
|
|
|
|
|
2018-05-08 15:43:13 -04:00
|
|
|
*pbase = svmMem->getSvmPtr();
|
2018-04-24 14:05:20 -04:00
|
|
|
*psize = svmMem->getSize();
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipMemGetInfo(size_t* free, size_t* total) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipMemGetInfo, free, total);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2022-04-21 05:56:28 +00:00
|
|
|
if (free == nullptr && total == nullptr) {
|
2022-08-16 06:55:03 +00:00
|
|
|
HIP_RETURN(hipSuccess);
|
2022-04-21 05:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-19 18:35:00 -04:00
|
|
|
size_t freeMemory[2];
|
2020-02-18 12:36:12 -08:00
|
|
|
amd::Device* device = hip::getCurrentDevice()->devices()[0];
|
2022-04-21 05:56:28 +00:00
|
|
|
if (device == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
2018-04-19 18:35:00 -04:00
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2022-04-21 05:56:28 +00:00
|
|
|
if (!device->globalFreeMemory(freeMemory)) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-04-19 18:35:00 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-21 05:56:28 +00:00
|
|
|
if (free != nullptr) {
|
|
|
|
|
*free = freeMemory[0] * Ki;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (total != nullptr) {
|
|
|
|
|
*total = device->info().globalMemSize_;
|
|
|
|
|
}
|
2018-04-19 18:35:00 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-11 07:38:59 +00:00
|
|
|
hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height, size_t depth) {
|
2018-04-19 18:35:00 -04:00
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
amd::Device* device = hip::getCurrentDevice()->devices()[0];
|
2018-04-19 18:35:00 -04:00
|
|
|
|
2022-04-21 21:05:12 +05:30
|
|
|
if ((ptr == nullptr) || (pitch == nullptr)) {
|
2018-04-19 18:35:00 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 08:39:44 -05:00
|
|
|
if ((width == 0) || (height == 0) || (depth == 0)) {
|
2020-03-26 12:42:55 -04:00
|
|
|
*ptr = nullptr;
|
|
|
|
|
return hipSuccess;
|
2018-04-19 18:35:00 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-10 06:41:23 +00:00
|
|
|
if (device && !device->info().imageSupport_) {
|
|
|
|
|
LogPrintfError("Image is not supported on device %p \n", device);
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-28 06:43:30 +00:00
|
|
|
//avoid size_t overflow for pitch calculation
|
2022-07-11 07:38:59 +00:00
|
|
|
if (width > (std::numeric_limits<size_t>::max() - device->info().imagePitchAlignment_)) {
|
2022-06-28 06:43:30 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-11 07:38:59 +00:00
|
|
|
*pitch = amd::alignUp(width, device->info().imagePitchAlignment_);
|
2018-04-19 18:35:00 -04:00
|
|
|
|
2018-04-24 14:05:20 -04:00
|
|
|
size_t sizeBytes = *pitch * height * depth;
|
2020-03-26 12:42:55 -04:00
|
|
|
|
|
|
|
|
if (device->info().maxMemAllocSize_ < sizeBytes) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 12:36:12 -08:00
|
|
|
*ptr = amd::SvmBuffer::malloc(*hip::getCurrentDevice()->asContext(), 0, sizeBytes,
|
2018-05-01 18:10:09 -04:00
|
|
|
device->info().memBaseAddrAlign_);
|
2018-04-19 18:35:00 -04:00
|
|
|
|
2018-05-02 21:08:53 -04:00
|
|
|
if (*ptr == nullptr) {
|
2019-12-30 16:46:39 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2018-04-19 18:35:00 -04:00
|
|
|
}
|
2021-09-27 16:38:30 -04:00
|
|
|
size_t offset = 0; //this is ignored
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(*ptr, offset);
|
2022-06-14 07:49:15 +00:00
|
|
|
memObj->getUserData().pitch_ = *pitch;
|
|
|
|
|
memObj->getUserData().width_ = width;
|
|
|
|
|
memObj->getUserData().height_ = height;
|
|
|
|
|
memObj->getUserData().depth_ = depth;
|
2021-09-17 19:18:10 -04:00
|
|
|
//saves the current device id so that it can be accessed later
|
|
|
|
|
memObj->getUserData().deviceId = hip::getCurrentDevice()->deviceId();
|
2018-04-19 18:35:00 -04:00
|
|
|
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipMallocPitch, ptr, pitch, width, height);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2022-07-11 07:38:59 +00:00
|
|
|
HIP_RETURN(ihipMallocPitch(ptr, pitch, width, height, 1), (ptr != nullptr)? *ptr : nullptr);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent) {
|
2020-03-23 16:31:30 -04:00
|
|
|
HIP_INIT_API(hipMalloc3D, pitchedDevPtr, extent);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2018-04-19 18:35:00 -04:00
|
|
|
size_t pitch = 0;
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2018-04-19 18:35:00 -04:00
|
|
|
if (pitchedDevPtr == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-04-19 18:35:00 -04:00
|
|
|
}
|
|
|
|
|
|
2021-11-29 17:53:36 +00:00
|
|
|
hipError_t status = ihipMallocPitch(&pitchedDevPtr->ptr, &pitch, extent.width, extent.height,
|
2022-07-11 07:38:59 +00:00
|
|
|
extent.depth);
|
2018-04-19 18:35:00 -04:00
|
|
|
|
|
|
|
|
if (status == hipSuccess) {
|
|
|
|
|
pitchedDevPtr->pitch = pitch;
|
|
|
|
|
pitchedDevPtr->xsize = extent.width;
|
|
|
|
|
pitchedDevPtr->ysize = extent.height;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 10:45:28 -07:00
|
|
|
HIP_RETURN(status, *pitchedDevPtr);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
amd::Image* ihipImageCreate(const cl_channel_order channelOrder,
|
|
|
|
|
const cl_channel_type channelType,
|
|
|
|
|
const cl_mem_object_type imageType,
|
|
|
|
|
const size_t imageWidth,
|
|
|
|
|
const size_t imageHeight,
|
|
|
|
|
const size_t imageDepth,
|
|
|
|
|
const size_t imageArraySize,
|
|
|
|
|
const size_t imageRowPitch,
|
|
|
|
|
const size_t imageSlicePitch,
|
|
|
|
|
const uint32_t numMipLevels,
|
2022-06-27 23:35:19 +05:30
|
|
|
amd::Memory* buffer,
|
|
|
|
|
hipError_t& status) {
|
|
|
|
|
status = hipSuccess;
|
2020-02-23 15:34:31 -05:00
|
|
|
const amd::Image::Format imageFormat({channelOrder, channelType});
|
|
|
|
|
if (!imageFormat.isValid()) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("Invalid Image format for channel Order:%u Type:%u \n", channelOrder,
|
|
|
|
|
channelType);
|
2022-06-27 23:35:19 +05:30
|
|
|
status = hipErrorInvalidValue;
|
2020-02-23 15:34:31 -05:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
amd::Context& context = *hip::getCurrentDevice()->asContext();
|
|
|
|
|
if (!imageFormat.isSupported(context, imageType)) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("Image type: %u not supported \n", imageType);
|
2022-06-27 23:35:19 +05:30
|
|
|
status = hipErrorInvalidValue;
|
2020-02-23 15:34:31 -05:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::vector<amd::Device*>& devices = context.devices();
|
|
|
|
|
if (!devices[0]->info().imageSupport_) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("Device: 0x%x does not support image \n", devices[0]);
|
2022-06-27 23:35:19 +05:30
|
|
|
status = hipErrorInvalidValue;
|
2020-02-23 15:34:31 -05:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!amd::Image::validateDimensions(devices,
|
|
|
|
|
imageType,
|
|
|
|
|
imageWidth,
|
|
|
|
|
imageHeight,
|
|
|
|
|
imageDepth,
|
|
|
|
|
imageArraySize)) {
|
2020-04-13 22:51:46 -04:00
|
|
|
DevLogError("Image does not have valid dimensions \n");
|
2022-06-27 23:35:19 +05:30
|
|
|
status = hipErrorInvalidValue;
|
2020-02-23 15:34:31 -05:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
if (numMipLevels > 0) {
|
|
|
|
|
size_t max_dim = std::max(std::max(imageWidth, imageHeight), imageDepth);
|
|
|
|
|
size_t mip_levels = 0;
|
|
|
|
|
for (mip_levels = 0; max_dim > 0; max_dim >>=1, mip_levels++);
|
|
|
|
|
// empty for loop
|
|
|
|
|
|
|
|
|
|
if (mip_levels < numMipLevels) {
|
|
|
|
|
LogPrintfError("Invalid Mip Levels: %d", numMipLevels);
|
2022-06-27 23:35:19 +05:30
|
|
|
status = hipErrorInvalidValue;
|
2021-03-22 15:52:46 -04:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
// TODO validate the image descriptor.
|
|
|
|
|
|
|
|
|
|
amd::Image* image = nullptr;
|
|
|
|
|
if (buffer != nullptr) {
|
|
|
|
|
switch (imageType) {
|
2020-03-18 15:30:19 -04:00
|
|
|
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
|
2020-02-23 15:34:31 -05:00
|
|
|
case CL_MEM_OBJECT_IMAGE2D:
|
|
|
|
|
image = new (context) amd::Image(*buffer->asBuffer(),
|
|
|
|
|
imageType,
|
|
|
|
|
CL_MEM_READ_WRITE,
|
|
|
|
|
imageFormat,
|
|
|
|
|
imageWidth,
|
|
|
|
|
(imageHeight == 0) ? 1 : imageHeight,
|
|
|
|
|
(imageDepth == 0) ? 1 : imageDepth,
|
|
|
|
|
imageRowPitch,
|
|
|
|
|
imageSlicePitch);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2022-09-21 19:50:06 +00:00
|
|
|
LogPrintfError("Cannot create image of imageType: 0x%x \n", imageType);
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch (imageType) {
|
|
|
|
|
case CL_MEM_OBJECT_IMAGE1D:
|
|
|
|
|
case CL_MEM_OBJECT_IMAGE2D:
|
|
|
|
|
case CL_MEM_OBJECT_IMAGE3D:
|
|
|
|
|
image = new (context) amd::Image(context,
|
|
|
|
|
imageType,
|
|
|
|
|
CL_MEM_READ_WRITE,
|
|
|
|
|
imageFormat,
|
|
|
|
|
imageWidth,
|
|
|
|
|
(imageHeight == 0) ? 1 : imageHeight,
|
|
|
|
|
(imageDepth == 0) ? 1 : imageDepth,
|
|
|
|
|
imageWidth * imageFormat.getElementSize(), /* row pitch */
|
|
|
|
|
imageWidth * imageHeight * imageFormat.getElementSize(), /* slice pitch */
|
|
|
|
|
numMipLevels);
|
|
|
|
|
break;
|
|
|
|
|
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
|
|
|
|
image = new (context) amd::Image(context,
|
|
|
|
|
imageType,
|
|
|
|
|
CL_MEM_READ_WRITE,
|
|
|
|
|
imageFormat,
|
|
|
|
|
imageWidth,
|
|
|
|
|
imageArraySize,
|
|
|
|
|
1, /* image depth */
|
|
|
|
|
imageWidth * imageFormat.getElementSize(),
|
|
|
|
|
imageWidth * imageHeight * imageFormat.getElementSize(),
|
|
|
|
|
numMipLevels);
|
|
|
|
|
break;
|
|
|
|
|
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
|
|
|
|
image = new (context) amd::Image(context,
|
|
|
|
|
imageType,
|
|
|
|
|
CL_MEM_READ_WRITE,
|
|
|
|
|
imageFormat,
|
|
|
|
|
imageWidth,
|
|
|
|
|
imageHeight,
|
|
|
|
|
imageArraySize,
|
|
|
|
|
imageWidth * imageFormat.getElementSize(),
|
|
|
|
|
imageWidth * imageHeight * imageFormat.getElementSize(),
|
|
|
|
|
numMipLevels);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2022-09-21 19:50:06 +00:00
|
|
|
LogPrintfError("Cannot create image of imageType: 0x%x \n", imageType);
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
if (image == nullptr) {
|
2022-06-27 23:35:19 +05:30
|
|
|
status = hipErrorOutOfMemory;
|
2020-02-23 15:34:31 -05:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!image->create(nullptr)) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("Cannot create image: 0x%x \n", image);
|
2022-06-27 23:35:19 +05:30
|
|
|
status = hipErrorOutOfMemory;
|
2020-02-23 15:34:31 -05:00
|
|
|
delete image;
|
|
|
|
|
return nullptr;
|
2018-05-01 18:46:32 -04:00
|
|
|
}
|
2023-03-22 19:14:15 -04:00
|
|
|
// Save device ID image was creted on
|
|
|
|
|
image->getUserData().deviceId = hip::getCurrentDevice()->deviceId();
|
2020-02-23 15:34:31 -05:00
|
|
|
return image;
|
|
|
|
|
}
|
2018-05-01 18:46:32 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t ihipArrayCreate(hipArray** array,
|
|
|
|
|
const HIP_ARRAY3D_DESCRIPTOR* pAllocateArray,
|
|
|
|
|
unsigned int numMipmapLevels) {
|
2022-04-20 19:49:30 +05:30
|
|
|
if (array == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
// NumChannels specifies the number of packed components per HIP array element; it may be 1, 2, or 4;
|
|
|
|
|
if ((pAllocateArray->NumChannels != 1) &&
|
|
|
|
|
(pAllocateArray->NumChannels != 2) &&
|
|
|
|
|
(pAllocateArray->NumChannels != 4)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-05-01 18:46:32 -04:00
|
|
|
|
2022-06-15 11:20:04 +00:00
|
|
|
if (pAllocateArray->Flags & hipArrayCubemap) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 14:11:25 -04:00
|
|
|
const cl_channel_order channelOrder = hip::getCLChannelOrder(pAllocateArray->NumChannels, 0);
|
2020-02-23 15:34:31 -05:00
|
|
|
const cl_channel_type channelType = hip::getCLChannelType(pAllocateArray->Format, hipReadModeElementType);
|
|
|
|
|
const cl_mem_object_type imageType = hip::getCLMemObjectType(pAllocateArray->Width,
|
|
|
|
|
pAllocateArray->Height,
|
|
|
|
|
pAllocateArray->Depth,
|
|
|
|
|
pAllocateArray->Flags);
|
2022-06-27 23:35:19 +05:30
|
|
|
hipError_t status = hipSuccess;
|
2020-02-23 15:34:31 -05:00
|
|
|
amd::Image* image = ihipImageCreate(channelOrder,
|
|
|
|
|
channelType,
|
|
|
|
|
imageType,
|
|
|
|
|
pAllocateArray->Width,
|
|
|
|
|
pAllocateArray->Height,
|
|
|
|
|
pAllocateArray->Depth,
|
|
|
|
|
// The number of layers is determined by the depth extent.
|
|
|
|
|
pAllocateArray->Depth, /* array size */
|
|
|
|
|
0, /* row pitch */
|
|
|
|
|
0, /* slice pitch */
|
|
|
|
|
numMipmapLevels,
|
2022-06-27 23:35:19 +05:30
|
|
|
nullptr, /* buffer */
|
|
|
|
|
status);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
|
|
|
|
if (image == nullptr) {
|
2022-06-27 23:35:19 +05:30
|
|
|
return status;
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
2019-10-15 16:43:10 -05:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
cl_mem memObj = as_cl<amd::Memory>(image);
|
|
|
|
|
*array = new hipArray{reinterpret_cast<void*>(memObj)};
|
2018-05-01 18:46:32 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
// It is UB to call hipGet*() on an array created via hipArrayCreate()/hipArray3DCreate().
|
|
|
|
|
// This is due to hip not differentiating between runtime and driver types.
|
|
|
|
|
// TODO change the hipArray struct in driver_types.h.
|
|
|
|
|
(*array)->desc = hip::getChannelFormatDesc(pAllocateArray->NumChannels, pAllocateArray->Format);
|
|
|
|
|
(*array)->width = pAllocateArray->Width;
|
|
|
|
|
(*array)->height = pAllocateArray->Height;
|
|
|
|
|
(*array)->depth = pAllocateArray->Depth;
|
|
|
|
|
(*array)->Format = pAllocateArray->Format;
|
|
|
|
|
(*array)->NumChannels = pAllocateArray->NumChannels;
|
2022-08-17 23:36:56 +05:30
|
|
|
(*array)->flags = pAllocateArray->Flags;
|
2022-05-13 12:39:47 +00:00
|
|
|
{
|
|
|
|
|
amd::ScopedLock lock(hip::hipArraySetLock);
|
|
|
|
|
hip::hipArraySet.insert(*array);
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipArrayCreate(hipArray** array,
|
|
|
|
|
const HIP_ARRAY_DESCRIPTOR* pAllocateArray) {
|
|
|
|
|
HIP_INIT_API(hipArrayCreate, array, pAllocateArray);
|
2022-07-12 08:40:41 -04:00
|
|
|
if (pAllocateArray == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_ARRAY3D_DESCRIPTOR desc = {pAllocateArray->Width,
|
|
|
|
|
pAllocateArray->Height,
|
|
|
|
|
0, /* Depth */
|
|
|
|
|
pAllocateArray->Format,
|
|
|
|
|
pAllocateArray->NumChannels,
|
|
|
|
|
hipArrayDefault /* Flags */};
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_RETURN(ihipArrayCreate(array, &desc, 0));
|
|
|
|
|
}
|
2018-04-24 14:05:20 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
|
|
|
|
|
hipError_t hipMallocArray(hipArray** array,
|
|
|
|
|
const hipChannelFormatDesc* desc,
|
|
|
|
|
size_t width,
|
|
|
|
|
size_t height,
|
|
|
|
|
unsigned int flags) {
|
|
|
|
|
HIP_INIT_API(hipMallocArray, array, desc, width, height, flags);
|
2022-05-20 23:02:49 -04:00
|
|
|
if (array == nullptr || desc == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_ARRAY3D_DESCRIPTOR allocateArray = {width,
|
|
|
|
|
height,
|
|
|
|
|
0, /* Depth */
|
|
|
|
|
hip::getArrayFormat(*desc),
|
|
|
|
|
hip::getNumChannels(*desc),
|
|
|
|
|
flags};
|
2022-04-25 12:52:35 -04:00
|
|
|
if(!hip::CheckArrayFormat(*desc)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_RETURN(ihipArrayCreate(array, &allocateArray, 0 /* numMipLevels */));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipArray3DCreate(hipArray** array,
|
|
|
|
|
const HIP_ARRAY3D_DESCRIPTOR* pAllocateArray) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipArray3DCreate, array, pAllocateArray);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2022-08-22 06:25:03 +00:00
|
|
|
if (pAllocateArray == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_RETURN(ihipArrayCreate(array, pAllocateArray, 0 /* numMipLevels */));
|
2019-09-18 14:29:25 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMalloc3DArray(hipArray_t* array,
|
|
|
|
|
const hipChannelFormatDesc* desc,
|
|
|
|
|
hipExtent extent,
|
|
|
|
|
unsigned int flags) {
|
2020-03-23 16:31:30 -04:00
|
|
|
HIP_INIT_API(hipMalloc3DArray, array, desc, extent, flags);
|
2022-05-20 23:02:49 -04:00
|
|
|
if (array == nullptr || desc == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_ARRAY3D_DESCRIPTOR allocateArray = {extent.width,
|
|
|
|
|
extent.height,
|
|
|
|
|
extent.depth,
|
|
|
|
|
hip::getArrayFormat(*desc),
|
|
|
|
|
hip::getNumChannels(*desc),
|
|
|
|
|
flags};
|
2022-08-11 07:17:01 +00:00
|
|
|
if(!hip::CheckArrayFormat(*desc)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_RETURN(ihipArrayCreate(array, &allocateArray, 0));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipHostGetFlags, flagsPtr, hostPtr);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2020-04-13 22:51:46 -04:00
|
|
|
if (flagsPtr == nullptr || hostPtr == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-05-16 16:35:53 -04:00
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2018-05-16 16:35:53 -04:00
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* svmMem = getMemoryObject(hostPtr, offset);
|
|
|
|
|
|
|
|
|
|
if (svmMem == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-05-16 16:35:53 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 23:33:36 +05:30
|
|
|
// To match with Nvidia behaviour validate that hostPtr passed was allocated using hipHostMalloc(), and not hipMalloc()
|
|
|
|
|
if (!(svmMem->getMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve HIP memory flags
|
|
|
|
|
*flagsPtr = svmMem->getUserData().flags;
|
2018-05-16 16:35:53 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-20 16:53:22 +00:00
|
|
|
hipError_t ihipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) {
|
2022-08-10 12:15:46 +00:00
|
|
|
if (hostPtr == nullptr || sizeBytes == 0 || flags > 15) {
|
2022-04-20 16:53:22 +00:00
|
|
|
return hipErrorInvalidValue;
|
2022-03-10 11:36:38 -08:00
|
|
|
} else {
|
2023-02-16 01:27:08 +00:00
|
|
|
amd::Memory* mem = new (*hip::host_context) amd::Buffer(*hip::host_context,
|
2022-02-23 18:21:04 -08:00
|
|
|
CL_MEM_USE_HOST_PTR | CL_MEM_SVM_ATOMICS, sizeBytes);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2019-06-06 11:51:22 -04:00
|
|
|
constexpr bool sysMemAlloc = false;
|
|
|
|
|
constexpr bool skipAlloc = false;
|
|
|
|
|
constexpr bool forceAlloc = true;
|
|
|
|
|
if (!mem->create(hostPtr, sysMemAlloc, skipAlloc, forceAlloc)) {
|
2018-06-01 15:01:45 -04:00
|
|
|
mem->release();
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("Cannot create memory for size: %u with flags: %d \n", sizeBytes, flags);
|
2022-04-28 12:52:26 +00:00
|
|
|
return hipErrorInvalidValue;
|
2018-06-01 15:01:45 -04:00
|
|
|
}
|
2019-06-04 10:24:11 -04:00
|
|
|
|
2022-11-01 16:34:49 -04:00
|
|
|
amd::MemObjMap::AddMemObj(hostPtr, mem);
|
2022-03-01 16:29:23 -08:00
|
|
|
for (const auto& device : g_devices) {
|
2019-06-06 11:51:22 -04:00
|
|
|
// Since the amd::Memory object is shared between all devices
|
|
|
|
|
// it's fine to have multiple addresses mapped to it
|
2022-03-01 16:29:23 -08:00
|
|
|
const device::Memory* devMem = mem->getDeviceMemory(*device->devices()[0]);
|
2022-03-08 17:19:25 -08:00
|
|
|
void* vAddr = reinterpret_cast<void*>(devMem->virtualAddress());
|
2022-11-01 16:34:49 -04:00
|
|
|
if ((hostPtr != vAddr) && (amd::MemObjMap::FindMemObj(vAddr) == nullptr)) {
|
2022-03-08 17:19:25 -08:00
|
|
|
amd::MemObjMap::AddMemObj(vAddr, mem);
|
|
|
|
|
}
|
2019-06-04 10:24:11 -04:00
|
|
|
}
|
2019-06-06 11:51:22 -04:00
|
|
|
|
2021-09-27 16:38:30 -04:00
|
|
|
if (mem != nullptr) {
|
|
|
|
|
mem->getUserData().deviceId = hip::getCurrentDevice()->deviceId();
|
2022-04-28 23:33:36 +05:30
|
|
|
// Save the HIP memory flags so that they can be accessed later
|
|
|
|
|
mem->getUserData().flags = flags;
|
2021-09-27 16:38:30 -04:00
|
|
|
}
|
2022-04-20 16:53:22 +00:00
|
|
|
return hipSuccess;
|
2018-06-01 15:01:45 -04:00
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-20 16:53:22 +00:00
|
|
|
hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) {
|
|
|
|
|
HIP_INIT_API(hipHostRegister, hostPtr, sizeBytes, flags);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2022-04-20 16:53:22 +00:00
|
|
|
HIP_RETURN(ihipHostRegister(hostPtr, sizeBytes,flags));
|
|
|
|
|
}
|
2020-02-26 08:41:18 -08:00
|
|
|
|
2022-04-20 16:53:22 +00:00
|
|
|
hipError_t ihipHostUnregister(void* hostPtr) {
|
2022-08-10 12:30:11 +00:00
|
|
|
if (hostPtr == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-04-20 18:55:38 -04:00
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* mem = getMemoryObject(hostPtr, offset);
|
|
|
|
|
|
|
|
|
|
if (mem != nullptr) {
|
|
|
|
|
// Wait on the device, associated with the current memory object during allocation
|
2023-03-22 19:14:15 -04:00
|
|
|
hip::Stream::SyncAllStreams(mem->getUserData().deviceId);
|
2022-04-20 18:55:38 -04:00
|
|
|
|
2022-11-01 16:34:49 -04:00
|
|
|
amd::MemObjMap::RemoveMemObj(hostPtr);
|
2022-04-20 18:55:38 -04:00
|
|
|
for (const auto& device: g_devices) {
|
|
|
|
|
const device::Memory* devMem = mem->getDeviceMemory(*device->devices()[0]);
|
|
|
|
|
if (devMem != nullptr) {
|
|
|
|
|
void* vAddr = reinterpret_cast<void*>(devMem->virtualAddress());
|
2022-11-01 16:34:49 -04:00
|
|
|
if ((vAddr != hostPtr) && amd::MemObjMap::FindMemObj(vAddr)) {
|
2022-04-20 18:55:38 -04:00
|
|
|
amd::MemObjMap::RemoveMemObj(vAddr);
|
2020-07-13 15:57:15 -04:00
|
|
|
}
|
2019-06-04 10:24:11 -04:00
|
|
|
}
|
2018-06-01 15:01:45 -04:00
|
|
|
}
|
2022-04-20 18:55:38 -04:00
|
|
|
mem->release();
|
2022-04-20 16:53:22 +00:00
|
|
|
return hipSuccess;
|
2018-06-01 15:01:45 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("Cannot unregister host_ptr: 0x%x \n", hostPtr);
|
2022-08-10 12:30:11 +00:00
|
|
|
return hipErrorHostMemoryNotRegistered;
|
2022-04-20 16:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hipError_t hipHostUnregister(void* hostPtr) {
|
|
|
|
|
HIP_INIT_API(hipHostUnregister, hostPtr);
|
|
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
|
|
|
|
HIP_RETURN(ihipHostUnregister(hostPtr));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2018-06-01 15:01:45 -04:00
|
|
|
// Deprecated function:
|
|
|
|
|
hipError_t hipHostAlloc(void** ptr, size_t sizeBytes, unsigned int flags) {
|
2020-12-17 10:38:13 -05:00
|
|
|
HIP_INIT_API(hipHostAlloc, ptr, sizeBytes, flags);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-12-17 10:38:13 -05:00
|
|
|
HIP_RETURN(ihipMalloc(ptr, sizeBytes, flags), (ptr != nullptr)? *ptr : nullptr);
|
2018-06-01 15:01:45 -04:00
|
|
|
};
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
inline hipError_t ihipMemcpySymbol_validate(const void* symbol, size_t sizeBytes, size_t offset, size_t &sym_size, hipDeviceptr_t &device_ptr) {
|
2020-05-18 22:40:33 -04:00
|
|
|
HIP_RETURN_ONFAIL(PlatformState::instance().getStatGlobalVar(symbol, ihipGetDevice(), &device_ptr, &sym_size));
|
2019-03-18 18:44:55 -04:00
|
|
|
|
|
|
|
|
/* Size Check to make sure offset is correct */
|
2020-04-24 18:33:26 -04:00
|
|
|
if ((offset + sizeBytes) > sym_size) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("Trying to access out of bounds, offset: %u sizeBytes: %u sym_size: %u \n",
|
2020-04-24 18:33:26 -04:00
|
|
|
offset, sizeBytes, sym_size);
|
2022-02-16 04:52:07 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2019-03-18 18:44:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
device_ptr = reinterpret_cast<address>(device_ptr) + offset;
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpyToSymbol_common(const void* symbol, const void* src, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream=nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-05-12 08:52:27 +00:00
|
|
|
|
|
|
|
|
if (kind != hipMemcpyHostToDevice && kind != hipMemcpyDeviceToDevice) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidMemcpyDirection);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
|
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, sizeBytes, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2019-03-18 18:44:55 -04:00
|
|
|
|
|
|
|
|
/* Copy memory from source to destination address */
|
2022-04-13 06:35:25 +00:00
|
|
|
return hipMemcpy_common(device_ptr, src, sizeBytes, kind, stream);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpyToSymbol(const void* symbol, const void* src, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyToSymbol, symbol, src, sizeBytes, offset, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyToSymbol_common(symbol, src, sizeBytes, offset, kind));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyToSymbol_spt(const void* symbol, const void* src, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyToSymbol, symbol, src, sizeBytes, offset, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyToSymbol_common(symbol, src, sizeBytes, offset, kind,
|
|
|
|
|
getPerThreadDefaultStream()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromSymbol_common(void* dst, const void* symbol, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream=nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-05-12 08:52:27 +00:00
|
|
|
|
|
|
|
|
if (kind != hipMemcpyDeviceToHost && kind != hipMemcpyDeviceToDevice) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidMemcpyDirection);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-18 18:44:55 -04:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, sizeBytes, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2019-03-18 18:44:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy memory from source to destination address */
|
2022-04-13 06:35:25 +00:00
|
|
|
return hipMemcpy_common(dst, device_ptr, sizeBytes, kind, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromSymbol(void* dst, const void* symbol, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyFromSymbol, symbol, dst, sizeBytes, offset, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyFromSymbol_common(dst, symbol, sizeBytes, offset, kind));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromSymbol_spt(void* dst, const void* symbol, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyFromSymbol, symbol, dst, sizeBytes, offset, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyFromSymbol_common(dst, symbol, sizeBytes, offset, kind,
|
|
|
|
|
getPerThreadDefaultStream()));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpyToSymbolAsync_common(const void* symbol, const void* src, size_t sizeBytes,
|
2018-04-05 15:02:43 -04:00
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream) {
|
2021-03-02 16:23:47 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpyToSymbolAsync, stream, symbol, src, sizeBytes, offset, kind);
|
|
|
|
|
|
2022-07-19 03:03:02 +00:00
|
|
|
if (kind != hipMemcpyHostToDevice && kind != hipMemcpyDeviceToDevice) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidMemcpyDirection;
|
2022-05-12 08:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-18 18:44:55 -04:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, sizeBytes, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2019-03-18 18:44:55 -04:00
|
|
|
}
|
|
|
|
|
/* Copy memory from source to destination address */
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipMemcpyAsync(device_ptr, src, sizeBytes, kind, stream);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpyToSymbolAsync(const void* symbol, const void* src, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyToSymbolAsync, symbol, src, sizeBytes, offset, kind, stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyToSymbolAsync_common(symbol, src, sizeBytes, offset, kind, stream));
|
|
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpyToSymbolAsync_spt(const void* symbol, const void* src, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyToSymbolAsync, symbol, src, sizeBytes, offset, kind, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyToSymbolAsync_common(symbol, src, sizeBytes, offset, kind, stream));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromSymbolAsync_common(void* dst, const void* symbol, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream) {
|
2021-03-02 16:23:47 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpyFromSymbolAsync, stream, dst, symbol, sizeBytes, offset, kind);
|
|
|
|
|
|
2022-07-19 03:03:02 +00:00
|
|
|
if (kind != hipMemcpyDeviceToHost && kind != hipMemcpyDeviceToDevice) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidMemcpyDirection;
|
2022-05-12 08:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-18 18:44:55 -04:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, sizeBytes, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2019-03-18 18:44:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy memory from source to destination address */
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipMemcpyAsync(dst, device_ptr, sizeBytes, kind, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromSymbolAsync(void* dst, const void* symbol, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyFromSymbolAsync, dst, symbol, sizeBytes, offset, kind, stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyFromSymbolAsync_common(dst, symbol, sizeBytes, offset, kind, stream));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromSymbolAsync_spt(void* dst, const void* symbol, size_t sizeBytes,
|
|
|
|
|
size_t offset, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyFromSymbolAsync, dst, symbol, sizeBytes, offset, kind, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyFromSymbolAsync_common(dst, symbol, sizeBytes, offset, kind, stream));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpyHtoD(hipDeviceptr_t dstDevice,
|
|
|
|
|
void* srcHost,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyHtoD, dstDevice, srcHost, ByteCount);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream = hip::getStream(nullptr);
|
|
|
|
|
if (stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy(dstDevice, srcHost, ByteCount, hipMemcpyHostToDevice, *stream));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpyDtoH(void* dstHost,
|
|
|
|
|
hipDeviceptr_t srcDevice,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyDtoH, dstHost, srcDevice, ByteCount);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream = hip::getStream(nullptr);
|
|
|
|
|
if (stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy(dstHost, srcDevice, ByteCount, hipMemcpyDeviceToHost, *stream));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpyDtoD(hipDeviceptr_t dstDevice,
|
|
|
|
|
hipDeviceptr_t srcDevice,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyDtoD, dstDevice, srcDevice, ByteCount);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream = hip::getStream(nullptr);
|
|
|
|
|
if (stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy(dstDevice, srcDevice, ByteCount, hipMemcpyDeviceToDevice, *stream));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpyAsync_common(void* dst, const void* src, size_t sizeBytes,
|
2018-04-05 15:02:43 -04:00
|
|
|
hipMemcpyKind kind, hipStream_t stream) {
|
2021-03-02 16:23:47 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpyAsync, stream, dst, src, sizeBytes, kind);
|
|
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
return ihipMemcpy(dst, src, sizeBytes, kind, *hip_stream, true);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes,
|
|
|
|
|
hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyAsync, dst, src, sizeBytes, kind, stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyAsync_common(dst, src, sizeBytes, kind, stream));
|
|
|
|
|
}
|
2018-05-01 18:46:32 -04:00
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpyAsync_spt(void* dst, const void* src, size_t sizeBytes,
|
|
|
|
|
hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyAsync, dst, src, sizeBytes, kind, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyAsync_common(dst, src, sizeBytes, kind, stream));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 12:01:26 -07:00
|
|
|
hipError_t hipMemcpyHtoDAsync(hipDeviceptr_t dstDevice, void* srcHost, size_t ByteCount,
|
2018-04-05 15:02:43 -04:00
|
|
|
hipStream_t stream) {
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_INIT_API(hipMemcpyHtoDAsync, dstDevice, srcHost, ByteCount, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
hipMemcpyKind kind = hipMemcpyHostToDevice;
|
|
|
|
|
STREAM_CAPTURE(hipMemcpyHtoDAsync, stream, dstDevice, srcHost, ByteCount, kind);
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
HIP_RETURN_DURATION(
|
2023-02-08 20:18:11 +00:00
|
|
|
ihipMemcpy(dstDevice, srcHost, ByteCount, kind, *hip_stream, true));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 12:01:26 -07:00
|
|
|
hipError_t hipMemcpyDtoDAsync(hipDeviceptr_t dstDevice, hipDeviceptr_t srcDevice, size_t ByteCount,
|
2018-04-05 15:02:43 -04:00
|
|
|
hipStream_t stream) {
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_INIT_API(hipMemcpyDtoDAsync, dstDevice, srcDevice, ByteCount, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
hipMemcpyKind kind = hipMemcpyDeviceToDevice;
|
|
|
|
|
STREAM_CAPTURE(hipMemcpyDtoDAsync, stream, dstDevice, srcDevice, ByteCount, kind);
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
HIP_RETURN_DURATION(
|
2023-02-08 20:18:11 +00:00
|
|
|
ihipMemcpy(dstDevice, srcDevice, ByteCount, kind, *hip_stream, true));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 12:01:26 -07:00
|
|
|
hipError_t hipMemcpyDtoHAsync(void* dstHost, hipDeviceptr_t srcDevice, size_t ByteCount,
|
2018-04-05 15:02:43 -04:00
|
|
|
hipStream_t stream) {
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_INIT_API(hipMemcpyDtoHAsync, dstHost, srcDevice, ByteCount, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
hipMemcpyKind kind = hipMemcpyDeviceToHost;
|
|
|
|
|
STREAM_CAPTURE(hipMemcpyDtoHAsync, stream, dstHost, srcDevice, ByteCount, kind);
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
HIP_RETURN_DURATION(
|
2023-02-08 20:18:11 +00:00
|
|
|
ihipMemcpy(dstHost, srcDevice, ByteCount, kind, *hip_stream, true));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
2021-10-20 03:39:00 -07:00
|
|
|
hipError_t ihipMemcpyAtoDValidate(hipArray* srcArray, void* dstDevice, amd::Coord3D& srcOrigin,
|
|
|
|
|
amd::Coord3D& dstOrigin, amd::Coord3D& copyRegion,
|
|
|
|
|
size_t dstRowPitch, size_t dstSlicePitch,
|
|
|
|
|
amd::Memory*& dstMemory, amd::Image*& srcImage,
|
|
|
|
|
amd::BufferRect& srcRect, amd::BufferRect& dstRect) {
|
2020-04-27 16:57:49 -04:00
|
|
|
size_t dstOffset = 0;
|
2021-09-28 12:51:17 -07:00
|
|
|
dstMemory = getMemoryObject(dstDevice, dstOffset);
|
2021-03-17 03:08:41 -07:00
|
|
|
if (srcArray == nullptr || (dstMemory == nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
cl_mem srcMemObj = reinterpret_cast<cl_mem>(srcArray->data);
|
|
|
|
|
if (!is_valid(srcMemObj)) {
|
2018-05-01 18:46:32 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-05-24 12:01:44 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
srcImage = as_amd(srcMemObj)->asImage();
|
2021-03-15 21:09:58 -04:00
|
|
|
// HIP assumes the width is in bytes, but OCL assumes it's in pixels.
|
|
|
|
|
const size_t elementSize = srcImage->getImageFormat().getElementSize();
|
|
|
|
|
static_cast<size_t*>(srcOrigin)[0] /= elementSize;
|
|
|
|
|
static_cast<size_t*>(copyRegion)[0] /= elementSize;
|
2018-05-24 12:01:44 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!srcRect.create(static_cast<size_t*>(srcOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
srcImage->getRowPitch(), srcImage->getSlicePitch())) {
|
2020-03-20 18:45:48 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!dstRect.create(static_cast<size_t*>(dstOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
dstRowPitch, dstSlicePitch)) {
|
2020-03-20 18:45:48 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-04-06 13:03:32 -04:00
|
|
|
dstRect.start_ += dstOffset;
|
2020-03-20 18:45:48 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
const size_t copySizeInBytes =
|
|
|
|
|
copyRegion[0] * copyRegion[1] * copyRegion[2] * srcImage->getImageFormat().getElementSize();
|
2020-03-20 18:45:48 -04:00
|
|
|
if (!srcImage->validateRegion(srcOrigin, copyRegion) ||
|
|
|
|
|
!dstMemory->validateRegion(dstOrigin, {copySizeInBytes, 0, 0})) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-05-08 15:43:13 -04:00
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-05-01 18:46:32 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyAtoDCommand(amd::Command*& command, hipArray* srcArray, void* dstDevice,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
|
|
|
|
amd::Coord3D copyRegion, size_t dstRowPitch, size_t dstSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::BufferRect srcRect;
|
|
|
|
|
amd::BufferRect dstRect;
|
|
|
|
|
amd::Memory* dstMemory;
|
|
|
|
|
amd::Image* srcImage;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipMemcpyAtoDValidate(srcArray, dstDevice, srcOrigin, dstOrigin, copyRegion, dstRowPitch,
|
|
|
|
|
dstSlicePitch, dstMemory, srcImage, srcRect, dstRect);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-11-25 07:39:13 +00:00
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
amd::CopyMemoryCommand* cpyMemCmd = new amd::CopyMemoryCommand(*stream, CL_COMMAND_COPY_IMAGE_TO_BUFFER,
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Command::EventWaitList{}, *srcImage, *dstMemory,
|
|
|
|
|
srcOrigin, dstOrigin, copyRegion, srcRect, dstRect);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2021-11-25 07:39:13 +00:00
|
|
|
if (cpyMemCmd == nullptr) {
|
2018-05-01 18:46:32 -04:00
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
2021-11-25 07:39:13 +00:00
|
|
|
|
|
|
|
|
if (!cpyMemCmd->validatePeerMemory()) {
|
|
|
|
|
delete cpyMemCmd;
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
command = cpyMemCmd;
|
2018-05-01 18:46:32 -04:00
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyDtoAValidate(void* srcDevice, hipArray* dstArray, amd::Coord3D& srcOrigin,
|
|
|
|
|
amd::Coord3D& dstOrigin, amd::Coord3D& copyRegion,
|
|
|
|
|
size_t srcRowPitch, size_t srcSlicePitch, amd::Image*& dstImage,
|
|
|
|
|
amd::Memory*& srcMemory, amd::BufferRect& dstRect,
|
|
|
|
|
amd::BufferRect& srcRect) {
|
2020-04-27 16:57:49 -04:00
|
|
|
size_t srcOffset = 0;
|
2021-09-28 12:51:17 -07:00
|
|
|
srcMemory = getMemoryObject(srcDevice, srcOffset);
|
2021-03-17 03:08:41 -07:00
|
|
|
if ((srcMemory == nullptr) || dstArray == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
cl_mem dstMemObj = reinterpret_cast<cl_mem>(dstArray->data);
|
2021-03-17 03:08:41 -07:00
|
|
|
if (!is_valid(dstMemObj)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2019-09-25 16:53:50 -04:00
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
dstImage = as_amd(dstMemObj)->asImage();
|
2021-03-15 21:09:58 -04:00
|
|
|
// HIP assumes the width is in bytes, but OCL assumes it's in pixels.
|
|
|
|
|
const size_t elementSize = dstImage->getImageFormat().getElementSize();
|
|
|
|
|
static_cast<size_t*>(dstOrigin)[0] /= elementSize;
|
|
|
|
|
static_cast<size_t*>(copyRegion)[0] /= elementSize;
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!srcRect.create(static_cast<size_t*>(srcOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
srcRowPitch, srcSlicePitch)) {
|
2020-03-20 18:45:48 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-04-06 13:03:32 -04:00
|
|
|
srcRect.start_ += srcOffset;
|
2020-03-20 18:45:48 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!dstRect.create(static_cast<size_t*>(dstOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
dstImage->getRowPitch(), dstImage->getSlicePitch())) {
|
2020-03-20 18:45:48 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
const size_t copySizeInBytes =
|
|
|
|
|
copyRegion[0] * copyRegion[1] * copyRegion[2] * dstImage->getImageFormat().getElementSize();
|
2020-02-23 15:34:31 -05:00
|
|
|
if (!srcMemory->validateRegion(srcOrigin, {copySizeInBytes, 0, 0}) ||
|
2020-03-20 18:45:48 -04:00
|
|
|
!dstImage->validateRegion(dstOrigin, copyRegion)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyDtoACommand(amd::Command*& command, void* srcDevice, hipArray* dstArray,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
|
|
|
|
amd::Coord3D copyRegion, size_t srcRowPitch, size_t srcSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Image* dstImage;
|
|
|
|
|
amd::Memory* srcMemory;
|
|
|
|
|
amd::BufferRect dstRect;
|
|
|
|
|
amd::BufferRect srcRect;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipMemcpyDtoAValidate(srcDevice, dstArray, srcOrigin, dstOrigin, copyRegion, srcRowPitch,
|
|
|
|
|
srcSlicePitch, dstImage, srcMemory, dstRect, srcRect);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
amd::CopyMemoryCommand* cpyMemCmd = new amd::CopyMemoryCommand(*stream, CL_COMMAND_COPY_BUFFER_TO_IMAGE,
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Command::EventWaitList{}, *srcMemory, *dstImage,
|
|
|
|
|
srcOrigin, dstOrigin, copyRegion, srcRect, dstRect);
|
2018-05-05 00:34:05 -04:00
|
|
|
|
2021-11-25 07:39:13 +00:00
|
|
|
if (cpyMemCmd == nullptr) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
2021-11-25 07:39:13 +00:00
|
|
|
|
|
|
|
|
if (!cpyMemCmd->validatePeerMemory()) {
|
|
|
|
|
delete cpyMemCmd;
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
command = cpyMemCmd;
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyDtoDValidate(void* srcDevice, void* dstDevice, amd::Coord3D& srcOrigin,
|
|
|
|
|
amd::Coord3D& dstOrigin, amd::Coord3D& copyRegion,
|
|
|
|
|
size_t srcRowPitch, size_t srcSlicePitch, size_t dstRowPitch,
|
|
|
|
|
size_t dstSlicePitch, amd::Memory*& srcMemory,
|
|
|
|
|
amd::Memory*& dstMemory, amd::BufferRect& srcRect,
|
|
|
|
|
amd::BufferRect& dstRect) {
|
2020-02-23 15:34:31 -05:00
|
|
|
size_t srcOffset = 0;
|
2021-09-28 12:51:17 -07:00
|
|
|
srcMemory = getMemoryObject(srcDevice, srcOffset);
|
2020-02-23 15:34:31 -05:00
|
|
|
size_t dstOffset = 0;
|
2021-09-28 12:51:17 -07:00
|
|
|
dstMemory = getMemoryObject(dstDevice, dstOffset);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2020-04-27 16:57:49 -04:00
|
|
|
if ((srcMemory == nullptr) || (dstMemory == nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!srcRect.create(static_cast<size_t*>(srcOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
srcRowPitch, srcSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-05-24 12:01:44 -04:00
|
|
|
}
|
2020-04-06 13:03:32 -04:00
|
|
|
srcRect.start_ += srcOffset;
|
2018-05-24 12:01:44 -04:00
|
|
|
|
2020-03-27 15:19:56 -04:00
|
|
|
amd::Coord3D srcStart(srcRect.start_, 0, 0);
|
2023-07-24 13:37:53 +00:00
|
|
|
amd::Coord3D srcSize(srcRect.end_, 1, 1);
|
2020-04-13 15:07:40 -04:00
|
|
|
if (!srcMemory->validateRegion(srcStart, srcSize)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-05-24 12:01:44 -04:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!dstRect.create(static_cast<size_t*>(dstOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
dstRowPitch, dstSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-05-24 12:01:44 -04:00
|
|
|
}
|
2020-04-06 13:03:32 -04:00
|
|
|
dstRect.start_ += dstOffset;
|
2018-05-24 12:01:44 -04:00
|
|
|
|
2020-03-27 15:19:56 -04:00
|
|
|
amd::Coord3D dstStart(dstRect.start_, 0, 0);
|
2023-07-24 13:37:53 +00:00
|
|
|
amd::Coord3D dstSize(dstRect.end_, 1, 1);
|
2020-04-13 15:07:40 -04:00
|
|
|
if (!dstMemory->validateRegion(dstStart, dstSize)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-05-24 12:01:44 -04:00
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-05-24 12:01:44 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyDtoDCommand(amd::Command*& command, void* srcDevice, void* dstDevice,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
|
|
|
|
amd::Coord3D copyRegion, size_t srcRowPitch, size_t srcSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
size_t dstRowPitch, size_t dstSlicePitch, hip::Stream* stream) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Memory* srcMemory;
|
|
|
|
|
amd::Memory* dstMemory;
|
|
|
|
|
amd::BufferRect srcRect;
|
|
|
|
|
amd::BufferRect dstRect;
|
|
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpyDtoDValidate(srcDevice, dstDevice, srcOrigin, dstOrigin, copyRegion,
|
|
|
|
|
srcRowPitch, srcSlicePitch, dstRowPitch, dstSlicePitch,
|
|
|
|
|
srcMemory, dstMemory, srcRect, dstRect);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
amd::Coord3D srcStart(srcRect.start_, 0, 0);
|
|
|
|
|
amd::Coord3D dstStart(dstRect.start_, 0, 0);
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::CopyMemoryCommand* copyCommand = new amd::CopyMemoryCommand(
|
2023-02-08 20:18:11 +00:00
|
|
|
*stream, CL_COMMAND_COPY_BUFFER_RECT, amd::Command::EventWaitList{}, *srcMemory, *dstMemory,
|
2021-03-11 12:10:49 -08:00
|
|
|
srcStart, dstStart, copyRegion, srcRect, dstRect);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (copyCommand == nullptr) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2018-05-24 12:01:44 -04:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!copyCommand->validatePeerMemory()) {
|
|
|
|
|
delete copyCommand;
|
2020-12-09 12:32:43 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
command = copyCommand;
|
|
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyDtoHValidate(void* srcDevice, void* dstHost, amd::Coord3D& srcOrigin,
|
|
|
|
|
amd::Coord3D& dstOrigin, amd::Coord3D& copyRegion,
|
|
|
|
|
size_t srcRowPitch, size_t srcSlicePitch, size_t dstRowPitch,
|
|
|
|
|
size_t dstSlicePitch, amd::Memory*& srcMemory,
|
|
|
|
|
amd::BufferRect& srcRect, amd::BufferRect& dstRect) {
|
2020-02-23 15:34:31 -05:00
|
|
|
size_t srcOffset = 0;
|
2021-09-28 12:51:17 -07:00
|
|
|
srcMemory = getMemoryObject(srcDevice, srcOffset);
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2020-04-27 16:57:49 -04:00
|
|
|
if ((srcMemory == nullptr) || (dstHost == nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!srcRect.create(static_cast<size_t*>(srcOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
srcRowPitch, srcSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-04-06 13:03:32 -04:00
|
|
|
srcRect.start_ += srcOffset;
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2020-03-27 15:19:56 -04:00
|
|
|
amd::Coord3D srcStart(srcRect.start_, 0, 0);
|
2023-07-24 13:37:53 +00:00
|
|
|
amd::Coord3D srcSize(srcRect.end_, 1, 1);
|
2020-04-13 15:07:40 -04:00
|
|
|
if (!srcMemory->validateRegion(srcStart, srcSize)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!dstRect.create(static_cast<size_t*>(dstOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
dstRowPitch, dstSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-04-25 12:32:11 -04:00
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyDtoHCommand(amd::Command*& command, void* srcDevice, void* dstHost,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
|
|
|
|
amd::Coord3D copyRegion, size_t srcRowPitch, size_t srcSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
size_t dstRowPitch, size_t dstSlicePitch, hip::Stream* stream,
|
2022-12-01 16:32:01 +00:00
|
|
|
bool isAsync = false) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Memory* srcMemory;
|
|
|
|
|
amd::BufferRect srcRect;
|
|
|
|
|
amd::BufferRect dstRect;
|
|
|
|
|
hipError_t status = ihipMemcpyDtoHValidate(srcDevice, dstHost, srcOrigin, dstOrigin, copyRegion,
|
|
|
|
|
srcRowPitch, srcSlicePitch, dstRowPitch, dstSlicePitch,
|
|
|
|
|
srcMemory, srcRect, dstRect);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
amd::Coord3D srcStart(srcRect.start_, 0, 0);
|
2022-12-01 16:32:01 +00:00
|
|
|
amd::CopyMetadata copyMetadata(isAsync, amd::CopyMetadata::CopyEnginePreference::SDMA);
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::ReadMemoryCommand* readCommand =
|
2023-02-08 20:18:11 +00:00
|
|
|
new amd::ReadMemoryCommand(*stream, CL_COMMAND_READ_BUFFER_RECT, amd::Command::EventWaitList{},
|
2022-12-01 16:32:01 +00:00
|
|
|
*srcMemory, srcStart, copyRegion, dstHost, srcRect, dstRect,
|
|
|
|
|
copyMetadata);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (readCommand == nullptr) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2018-04-25 12:32:11 -04:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!readCommand->validatePeerMemory()) {
|
|
|
|
|
delete readCommand;
|
2020-12-09 12:32:43 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
command = readCommand;
|
|
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyHtoDValidate(const void* srcHost, void* dstDevice, amd::Coord3D& srcOrigin,
|
|
|
|
|
amd::Coord3D& dstOrigin, amd::Coord3D& copyRegion,
|
|
|
|
|
size_t srcRowPitch, size_t srcSlicePitch, size_t dstRowPitch,
|
|
|
|
|
size_t dstSlicePitch, amd::Memory*& dstMemory,
|
|
|
|
|
amd::BufferRect& srcRect, amd::BufferRect& dstRect) {
|
2020-02-23 15:34:31 -05:00
|
|
|
size_t dstOffset = 0;
|
2021-09-28 12:51:17 -07:00
|
|
|
dstMemory = getMemoryObject(dstDevice, dstOffset);
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2020-04-27 16:57:49 -04:00
|
|
|
if ((srcHost == nullptr) || (dstMemory == nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!srcRect.create(static_cast<size_t*>(srcOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
srcRowPitch, srcSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!dstRect.create(static_cast<size_t*>(dstOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
dstRowPitch, dstSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-04-06 13:03:32 -04:00
|
|
|
dstRect.start_ += dstOffset;
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2020-03-27 15:19:56 -04:00
|
|
|
amd::Coord3D dstStart(dstRect.start_, 0, 0);
|
2023-07-24 13:37:53 +00:00
|
|
|
amd::Coord3D dstSize(dstRect.end_, 1, 1);
|
2020-04-13 15:07:40 -04:00
|
|
|
if (!dstMemory->validateRegion(dstStart, dstSize)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-04-25 12:32:11 -04:00
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyHtoDCommand(amd::Command*& command, const void* srcHost, void* dstDevice,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
|
|
|
|
amd::Coord3D copyRegion, size_t srcRowPitch, size_t srcSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
size_t dstRowPitch, size_t dstSlicePitch, hip::Stream* stream,
|
2022-12-01 16:32:01 +00:00
|
|
|
bool isAsync = false) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Memory* dstMemory;
|
|
|
|
|
amd::BufferRect srcRect;
|
|
|
|
|
amd::BufferRect dstRect;
|
|
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpyHtoDValidate(srcHost, dstDevice, srcOrigin, dstOrigin, copyRegion,
|
|
|
|
|
srcRowPitch, srcSlicePitch, dstRowPitch, dstSlicePitch,
|
|
|
|
|
dstMemory, srcRect, dstRect);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
amd::Coord3D dstStart(dstRect.start_, 0, 0);
|
2022-12-01 16:32:01 +00:00
|
|
|
amd::CopyMetadata copyMetadata(isAsync, amd::CopyMetadata::CopyEnginePreference::SDMA);
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::WriteMemoryCommand* writeCommand = new amd::WriteMemoryCommand(
|
2023-02-08 20:18:11 +00:00
|
|
|
*stream, CL_COMMAND_WRITE_BUFFER_RECT, amd::Command::EventWaitList{}, *dstMemory, dstStart,
|
2022-12-01 16:32:01 +00:00
|
|
|
copyRegion, srcHost, dstRect, srcRect, copyMetadata);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (writeCommand == nullptr) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2018-04-25 12:32:11 -04:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!writeCommand->validatePeerMemory()) {
|
|
|
|
|
delete writeCommand;
|
2020-12-09 12:32:43 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
command = writeCommand;
|
|
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipMemcpyHtoH(const void* srcHost, void* dstHost, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t srcRowPitch,
|
2022-12-21 15:04:28 +00:00
|
|
|
size_t srcSlicePitch, size_t dstRowPitch, size_t dstSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream) {
|
2020-04-27 16:57:49 -04:00
|
|
|
if ((srcHost == nullptr) || (dstHost == nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
amd::BufferRect srcRect;
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!srcRect.create(static_cast<size_t*>(srcOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
srcRowPitch, srcSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-07-31 15:07:56 -04:00
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
amd::BufferRect dstRect;
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!dstRect.create(static_cast<size_t*>(dstOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
dstRowPitch, dstSlicePitch)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-04-30 14:55:41 -04:00
|
|
|
}
|
|
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
if (stream) {
|
|
|
|
|
stream->finish();
|
2022-12-21 15:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
for (size_t slice = 0; slice < copyRegion[2]; slice++) {
|
|
|
|
|
for (size_t row = 0; row < copyRegion[1]; row++) {
|
2021-03-11 12:10:49 -08:00
|
|
|
const void* srcRow = static_cast<const char*>(srcHost) + srcRect.start_ +
|
|
|
|
|
row * srcRect.rowPitch_ + slice * srcRect.slicePitch_;
|
|
|
|
|
void* dstRow = static_cast<char*>(dstHost) + dstRect.start_ + row * dstRect.rowPitch_ +
|
|
|
|
|
slice * dstRect.slicePitch_;
|
2020-02-23 15:34:31 -05:00
|
|
|
std::memcpy(dstRow, srcRow, copyRegion[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyAtoAValidate(hipArray* srcArray, hipArray* dstArray, amd::Coord3D& srcOrigin,
|
|
|
|
|
amd::Coord3D& dstOrigin, amd::Coord3D& copyRegion,
|
|
|
|
|
amd::Image*& srcImage, amd::Image*& dstImage) {
|
2021-03-17 03:08:41 -07:00
|
|
|
if (dstArray == nullptr || srcArray == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
cl_mem srcMemObj = reinterpret_cast<cl_mem>(srcArray->data);
|
|
|
|
|
cl_mem dstMemObj = reinterpret_cast<cl_mem>(dstArray->data);
|
|
|
|
|
if (!is_valid(srcMemObj) || !is_valid(dstMemObj)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
srcImage = as_amd(srcMemObj)->asImage();
|
|
|
|
|
dstImage = as_amd(dstMemObj)->asImage();
|
2018-07-31 15:07:56 -04:00
|
|
|
|
2020-03-05 14:00:43 -05:00
|
|
|
// HIP assumes the width is in bytes, but OCL assumes it's in pixels.
|
|
|
|
|
// Note that src and dst should have the same element size.
|
2021-03-11 12:10:49 -08:00
|
|
|
assert(srcImage->getImageFormat().getElementSize() ==
|
|
|
|
|
dstImage->getImageFormat().getElementSize());
|
2020-03-05 14:00:43 -05:00
|
|
|
const size_t elementSize = srcImage->getImageFormat().getElementSize();
|
|
|
|
|
static_cast<size_t*>(srcOrigin)[0] /= elementSize;
|
|
|
|
|
static_cast<size_t*>(dstOrigin)[0] /= elementSize;
|
|
|
|
|
static_cast<size_t*>(copyRegion)[0] /= elementSize;
|
|
|
|
|
|
|
|
|
|
if (!srcImage->validateRegion(srcOrigin, copyRegion) ||
|
|
|
|
|
!dstImage->validateRegion(dstOrigin, copyRegion)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
2018-07-31 15:07:56 -04:00
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpyAtoACommand(amd::Command*& command, hipArray* srcArray, hipArray* dstArray,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
2023-02-08 20:18:11 +00:00
|
|
|
amd::Coord3D copyRegion, hip::Stream* stream) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Image* srcImage;
|
|
|
|
|
amd::Image* dstImage;
|
|
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpyAtoAValidate(srcArray, dstArray, srcOrigin, dstOrigin, copyRegion,
|
|
|
|
|
srcImage, dstImage);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
amd::CopyMemoryCommand* cpyMemCmd = new amd::CopyMemoryCommand(*stream, CL_COMMAND_COPY_IMAGE,
|
2021-11-25 07:39:13 +00:00
|
|
|
amd::Command::EventWaitList{}, *srcImage, *dstImage,
|
|
|
|
|
srcOrigin, dstOrigin, copyRegion);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2021-11-25 07:39:13 +00:00
|
|
|
if (cpyMemCmd == nullptr) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2018-04-30 14:55:41 -04:00
|
|
|
}
|
2021-11-25 07:39:13 +00:00
|
|
|
|
|
|
|
|
if (!cpyMemCmd->validatePeerMemory()) {
|
|
|
|
|
delete cpyMemCmd;
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
command = cpyMemCmd;
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipSuccess;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-20 03:39:00 -07:00
|
|
|
hipError_t ihipMemcpyHtoAValidate(const void* srcHost, hipArray* dstArray,
|
|
|
|
|
amd::Coord3D& srcOrigin, amd::Coord3D& dstOrigin,
|
|
|
|
|
amd::Coord3D& copyRegion, size_t srcRowPitch,
|
|
|
|
|
size_t srcSlicePitch, amd::Image*& dstImage,
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::BufferRect& srcRect) {
|
2021-03-17 03:08:41 -07:00
|
|
|
if ((srcHost == nullptr) || dstArray == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
cl_mem dstMemObj = reinterpret_cast<cl_mem>(dstArray->data);
|
2021-03-17 03:08:41 -07:00
|
|
|
if (!is_valid(dstMemObj)) {
|
2020-01-07 15:59:02 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!srcRect.create(static_cast<size_t*>(srcOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
srcRowPitch, srcSlicePitch)) {
|
2020-01-07 15:59:02 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
dstImage = as_amd(dstMemObj)->asImage();
|
2020-02-23 15:34:31 -05:00
|
|
|
// HIP assumes the width is in bytes, but OCL assumes it's in pixels.
|
|
|
|
|
const size_t elementSize = dstImage->getImageFormat().getElementSize();
|
|
|
|
|
static_cast<size_t*>(dstOrigin)[0] /= elementSize;
|
|
|
|
|
static_cast<size_t*>(copyRegion)[0] /= elementSize;
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
if (!dstImage->validateRegion(dstOrigin, copyRegion)) {
|
2020-01-07 15:59:02 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpyHtoACommand(amd::Command*& command, const void* srcHost, hipArray* dstArray,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
|
|
|
|
amd::Coord3D copyRegion, size_t srcRowPitch, size_t srcSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream, bool isAsync = false) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Image* dstImage;
|
|
|
|
|
amd::BufferRect srcRect;
|
|
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpyHtoAValidate(srcHost, dstArray, srcOrigin, dstOrigin, copyRegion,
|
|
|
|
|
srcRowPitch, srcSlicePitch, dstImage, srcRect);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2022-12-01 16:32:01 +00:00
|
|
|
amd::CopyMetadata copyMetadata(isAsync, amd::CopyMetadata::CopyEnginePreference::SDMA);
|
2021-11-25 07:39:13 +00:00
|
|
|
amd::WriteMemoryCommand* writeMemCmd = new amd::WriteMemoryCommand(
|
2023-02-08 20:18:11 +00:00
|
|
|
*stream, CL_COMMAND_WRITE_IMAGE, amd::Command::EventWaitList{}, *dstImage, dstOrigin,
|
2022-12-01 16:32:01 +00:00
|
|
|
copyRegion, static_cast<const char*>(srcHost) + srcRect.start_, srcRowPitch, srcSlicePitch,
|
|
|
|
|
copyMetadata);
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2021-11-25 07:39:13 +00:00
|
|
|
if (writeMemCmd == nullptr) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorOutOfMemory;
|
2020-01-07 15:59:02 -05:00
|
|
|
}
|
2021-11-25 07:39:13 +00:00
|
|
|
|
|
|
|
|
if (!writeMemCmd->validatePeerMemory()) {
|
|
|
|
|
delete writeMemCmd;
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
command = writeMemCmd;
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2019-12-04 14:06:53 -05:00
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t ihipMemcpyAtoHValidate(hipArray* srcArray, void* dstHost, amd::Coord3D& srcOrigin,
|
|
|
|
|
amd::Coord3D& dstOrigin, amd::Coord3D& copyRegion,
|
|
|
|
|
size_t dstRowPitch, size_t dstSlicePitch, amd::Image*& srcImage,
|
|
|
|
|
amd::BufferRect& dstRect) {
|
2021-03-17 03:08:41 -07:00
|
|
|
if (srcArray == nullptr || (dstHost == nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
cl_mem srcMemObj = reinterpret_cast<cl_mem>(srcArray->data);
|
2021-03-17 03:08:41 -07:00
|
|
|
if (!is_valid(srcMemObj)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if (!dstRect.create(static_cast<size_t*>(dstOrigin), static_cast<size_t*>(copyRegion),
|
|
|
|
|
dstRowPitch, dstSlicePitch)) {
|
2020-01-07 15:59:02 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
srcImage = as_amd(srcMemObj)->asImage();
|
2020-02-23 15:34:31 -05:00
|
|
|
// HIP assumes the width is in bytes, but OCL assumes it's in pixels.
|
|
|
|
|
const size_t elementSize = srcImage->getImageFormat().getElementSize();
|
|
|
|
|
static_cast<size_t*>(srcOrigin)[0] /= elementSize;
|
|
|
|
|
static_cast<size_t*>(copyRegion)[0] /= elementSize;
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
if (!srcImage->validateRegion(srcOrigin, copyRegion) ||
|
|
|
|
|
!srcImage->isRowSliceValid(dstRowPitch, dstSlicePitch, copyRegion[0], copyRegion[1])) {
|
|
|
|
|
return hipErrorInvalidValue;
|
2020-01-07 15:59:02 -05:00
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpyAtoHCommand(amd::Command*& command, hipArray* srcArray, void* dstHost,
|
|
|
|
|
amd::Coord3D srcOrigin, amd::Coord3D dstOrigin,
|
|
|
|
|
amd::Coord3D copyRegion, size_t dstRowPitch, size_t dstSlicePitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream, bool isAsync = false) {
|
2021-09-28 12:51:17 -07:00
|
|
|
amd::Image* srcImage;
|
|
|
|
|
amd::BufferRect dstRect;
|
2022-12-01 16:32:01 +00:00
|
|
|
amd::CopyMetadata copyMetadata(isAsync, amd::CopyMetadata::CopyEnginePreference::SDMA);
|
2021-09-28 12:51:17 -07:00
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpyAtoHValidate(srcArray, dstHost, srcOrigin, dstOrigin, copyRegion,
|
|
|
|
|
dstRowPitch, dstSlicePitch, srcImage, dstRect);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2021-11-25 07:39:13 +00:00
|
|
|
amd::ReadMemoryCommand* readMemCmd = new amd::ReadMemoryCommand(
|
2023-02-08 20:18:11 +00:00
|
|
|
*stream, CL_COMMAND_READ_IMAGE, amd::Command::EventWaitList{}, *srcImage, srcOrigin,
|
2022-12-01 16:32:01 +00:00
|
|
|
copyRegion, static_cast<char*>(dstHost) + dstRect.start_, dstRowPitch, dstSlicePitch,
|
|
|
|
|
copyMetadata);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2021-11-25 07:39:13 +00:00
|
|
|
if (readMemCmd == nullptr) {
|
2020-01-07 15:59:02 -05:00
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
2021-11-25 07:39:13 +00:00
|
|
|
|
|
|
|
|
if (!readMemCmd->validatePeerMemory()) {
|
|
|
|
|
delete readMemCmd;
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
command = readMemCmd;
|
2020-01-07 15:59:02 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipGetMemcpyParam3DCommand(amd::Command*& command, const HIP_MEMCPY3D* pCopy,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream) {
|
2023-01-17 16:27:11 -08:00
|
|
|
size_t offset = 0;
|
2021-03-11 12:10:49 -08:00
|
|
|
// If {src/dst}MemoryType is hipMemoryTypeUnified, {src/dst}Device and {src/dst}Pitch specify the
|
2023-02-21 16:32:29 -08:00
|
|
|
// (unified virtual address space) base address of the source data and the bytes per row to
|
|
|
|
|
// apply. {src/dst}Array is ignored.
|
2020-02-23 15:34:31 -05:00
|
|
|
hipMemoryType srcMemoryType = pCopy->srcMemoryType;
|
|
|
|
|
if (srcMemoryType == hipMemoryTypeUnified) {
|
2023-02-21 16:32:29 -08:00
|
|
|
amd::Memory* memObj = getMemoryObject(pCopy->srcDevice, offset);
|
|
|
|
|
if (memObj != nullptr) {
|
|
|
|
|
srcMemoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
|
|
|
|
memObj->getMemFlags()) ? hipMemoryTypeHost : hipMemoryTypeDevice;
|
|
|
|
|
} else {
|
|
|
|
|
srcMemoryType = hipMemoryTypeHost;
|
|
|
|
|
}
|
2020-07-20 11:02:48 -04:00
|
|
|
if (srcMemoryType == hipMemoryTypeHost) {
|
2021-03-11 12:10:49 -08:00
|
|
|
// {src/dst}Host may be unitialized. Copy over {src/dst}Device into it if we detect system
|
|
|
|
|
// memory.
|
2020-07-20 11:02:48 -04:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->srcHost = pCopy->srcDevice;
|
2023-01-17 16:27:11 -08:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->srcXInBytes += offset;
|
2020-07-20 11:02:48 -04:00
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
2023-01-17 16:27:11 -08:00
|
|
|
offset = 0;
|
2020-02-23 15:34:31 -05:00
|
|
|
hipMemoryType dstMemoryType = pCopy->dstMemoryType;
|
|
|
|
|
if (dstMemoryType == hipMemoryTypeUnified) {
|
2023-02-21 16:32:29 -08:00
|
|
|
amd::Memory* memObj = getMemoryObject(pCopy->dstDevice, offset);
|
|
|
|
|
if (memObj != nullptr) {
|
|
|
|
|
dstMemoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
|
|
|
|
memObj->getMemFlags()) ? hipMemoryTypeHost : hipMemoryTypeDevice;
|
|
|
|
|
} else {
|
|
|
|
|
dstMemoryType = hipMemoryTypeHost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dstMemoryType == hipMemoryTypeHost) {
|
2020-07-20 11:02:48 -04:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->dstHost = pCopy->dstDevice;
|
2023-01-17 16:27:11 -08:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->dstXInBytes += offset;
|
2020-07-20 11:02:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If {src/dst}MemoryType is hipMemoryTypeHost, check if the memory was prepinned.
|
|
|
|
|
// In that case upgrade the copy type to hipMemoryTypeDevice to avoid extra pinning.
|
2023-01-17 16:27:11 -08:00
|
|
|
offset = 0;
|
2020-07-20 11:02:48 -04:00
|
|
|
if (srcMemoryType == hipMemoryTypeHost) {
|
2023-02-21 16:32:29 -08:00
|
|
|
srcMemoryType = getMemoryObject(pCopy->srcHost, offset) ? hipMemoryTypeDevice :
|
|
|
|
|
hipMemoryTypeHost;
|
|
|
|
|
|
2020-07-20 11:02:48 -04:00
|
|
|
if (srcMemoryType == hipMemoryTypeDevice) {
|
|
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->srcDevice = const_cast<void*>(pCopy->srcHost);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-17 16:27:11 -08:00
|
|
|
offset = 0;
|
2020-07-20 11:02:48 -04:00
|
|
|
if (dstMemoryType == hipMemoryTypeHost) {
|
2023-02-21 16:32:29 -08:00
|
|
|
dstMemoryType = getMemoryObject(pCopy->dstHost, offset) ? hipMemoryTypeDevice :
|
|
|
|
|
hipMemoryTypeHost;
|
|
|
|
|
|
2020-07-20 11:02:48 -04:00
|
|
|
if (dstMemoryType == hipMemoryTypeDevice) {
|
2022-12-20 11:37:49 +00:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->dstDevice = const_cast<void*>(pCopy->dstHost);
|
2020-07-20 11:02:48 -04:00
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
amd::Coord3D srcOrigin = {pCopy->srcXInBytes, pCopy->srcY, pCopy->srcZ};
|
|
|
|
|
amd::Coord3D dstOrigin = {pCopy->dstXInBytes, pCopy->dstY, pCopy->dstZ};
|
2021-02-11 06:47:32 -08:00
|
|
|
amd::Coord3D copyRegion = {pCopy->WidthInBytes, pCopy->Height, pCopy->Depth};
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
if ((srcMemoryType == hipMemoryTypeHost) && (dstMemoryType == hipMemoryTypeDevice)) {
|
2020-02-23 15:34:31 -05:00
|
|
|
// Host to Device.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyHtoDCommand(command, pCopy->srcHost, pCopy->dstDevice, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, pCopy->srcPitch, pCopy->srcPitch * pCopy->srcHeight,
|
2023-02-08 20:18:11 +00:00
|
|
|
pCopy->dstPitch, pCopy->dstPitch * pCopy->dstHeight, stream);
|
2020-02-23 15:34:31 -05:00
|
|
|
} else if ((srcMemoryType == hipMemoryTypeDevice) && (dstMemoryType == hipMemoryTypeHost)) {
|
|
|
|
|
// Device to Host.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyDtoHCommand(command, pCopy->srcDevice, pCopy->dstHost, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, pCopy->srcPitch, pCopy->srcPitch * pCopy->srcHeight,
|
2023-02-08 20:18:11 +00:00
|
|
|
pCopy->dstPitch, pCopy->dstPitch * pCopy->dstHeight, stream);
|
2020-02-23 15:34:31 -05:00
|
|
|
} else if ((srcMemoryType == hipMemoryTypeDevice) && (dstMemoryType == hipMemoryTypeDevice)) {
|
|
|
|
|
// Device to Device.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyDtoDCommand(command, pCopy->srcDevice, pCopy->dstDevice, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, pCopy->srcPitch, pCopy->srcPitch * pCopy->srcHeight,
|
2023-02-08 20:18:11 +00:00
|
|
|
pCopy->dstPitch, pCopy->dstPitch * pCopy->dstHeight, stream);
|
2020-02-23 15:34:31 -05:00
|
|
|
} else if ((srcMemoryType == hipMemoryTypeHost) && (dstMemoryType == hipMemoryTypeArray)) {
|
|
|
|
|
// Host to Image.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyHtoACommand(command, pCopy->srcHost, pCopy->dstArray, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, pCopy->srcPitch, pCopy->srcPitch * pCopy->srcHeight,
|
2023-02-08 20:18:11 +00:00
|
|
|
stream);
|
2020-02-23 15:34:31 -05:00
|
|
|
} else if ((srcMemoryType == hipMemoryTypeArray) && (dstMemoryType == hipMemoryTypeHost)) {
|
|
|
|
|
// Image to Host.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyAtoHCommand(command, pCopy->srcArray, pCopy->dstHost, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, pCopy->dstPitch, pCopy->dstPitch * pCopy->dstHeight,
|
2023-02-08 20:18:11 +00:00
|
|
|
stream);
|
2020-02-23 15:34:31 -05:00
|
|
|
} else if ((srcMemoryType == hipMemoryTypeDevice) && (dstMemoryType == hipMemoryTypeArray)) {
|
|
|
|
|
// Device to Image.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyDtoACommand(command, pCopy->srcDevice, pCopy->dstArray, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, pCopy->srcPitch, pCopy->srcPitch * pCopy->srcHeight,
|
2023-02-08 20:18:11 +00:00
|
|
|
stream);
|
2020-02-23 15:34:31 -05:00
|
|
|
} else if ((srcMemoryType == hipMemoryTypeArray) && (dstMemoryType == hipMemoryTypeDevice)) {
|
|
|
|
|
// Image to Device.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyAtoDCommand(command, pCopy->srcArray, pCopy->dstDevice, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, pCopy->dstPitch, pCopy->dstPitch * pCopy->dstHeight,
|
2023-02-08 20:18:11 +00:00
|
|
|
stream);
|
2020-02-23 15:34:31 -05:00
|
|
|
} else if ((srcMemoryType == hipMemoryTypeArray) && (dstMemoryType == hipMemoryTypeArray)) {
|
|
|
|
|
// Image to Image.
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyAtoACommand(command, pCopy->srcArray, pCopy->dstArray, srcOrigin, dstOrigin,
|
2023-02-08 20:18:11 +00:00
|
|
|
copyRegion, stream);
|
2020-01-07 15:59:02 -05:00
|
|
|
} else {
|
|
|
|
|
ShouldNotReachHere();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
inline hipError_t ihipMemcpyCmdEnqueue(amd::Command* command, bool isAsync = false) {
|
|
|
|
|
hipError_t status = hipSuccess;
|
|
|
|
|
if (command == nullptr) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
command->enqueue();
|
|
|
|
|
if (!isAsync) {
|
|
|
|
|
if (!command->awaitCompletion()) {
|
|
|
|
|
status = hipErrorUnknown;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
command->release();
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpyParam3D(const HIP_MEMCPY3D* pCopy, hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
hipError_t status;
|
2023-01-17 16:27:11 -08:00
|
|
|
size_t offset = 0;
|
2022-12-20 12:43:58 +00:00
|
|
|
if (pCopy == nullptr) {
|
2021-09-06 11:20:17 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-20 12:43:58 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
if (pCopy->WidthInBytes == 0 || pCopy->Height == 0 || pCopy->Depth == 0) {
|
|
|
|
|
LogPrintfInfo("Either Width :%d or Height: %d and Depth: %d is zero", pCopy->WidthInBytes,
|
|
|
|
|
pCopy->Height, pCopy->Depth);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2021-04-30 17:52:33 +00:00
|
|
|
// If {src/dst}MemoryType is hipMemoryTypeUnified, {src/dst}Device and {src/dst}Pitch specify the (unified virtual address space)
|
|
|
|
|
// base address of the source data and the bytes per row to apply. {src/dst}Array is ignored.
|
|
|
|
|
hipMemoryType srcMemoryType = pCopy->srcMemoryType;
|
|
|
|
|
if (srcMemoryType == hipMemoryTypeUnified) {
|
2023-02-21 16:32:29 -08:00
|
|
|
amd::Memory* memObj = getMemoryObject(pCopy->srcDevice, offset);
|
|
|
|
|
if (memObj != nullptr) {
|
|
|
|
|
srcMemoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
|
|
|
|
memObj->getMemFlags()) ? hipMemoryTypeHost : hipMemoryTypeDevice;
|
|
|
|
|
} else {
|
|
|
|
|
srcMemoryType = hipMemoryTypeHost;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 17:52:33 +00:00
|
|
|
if (srcMemoryType == hipMemoryTypeHost) {
|
|
|
|
|
// {src/dst}Host may be unitialized. Copy over {src/dst}Device into it if we detect system memory.
|
|
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->srcHost = pCopy->srcDevice;
|
2023-01-17 16:27:11 -08:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->srcXInBytes += offset;
|
2023-06-29 19:01:52 -04:00
|
|
|
// We don't need detect memory type again for hipMemoryTypeUnified
|
|
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->srcMemoryType = srcMemoryType;
|
2021-04-30 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-17 16:27:11 -08:00
|
|
|
offset = 0;
|
2021-04-30 17:52:33 +00:00
|
|
|
hipMemoryType dstMemoryType = pCopy->dstMemoryType;
|
|
|
|
|
if (dstMemoryType == hipMemoryTypeUnified) {
|
2023-02-21 16:32:29 -08:00
|
|
|
amd::Memory* memObj = getMemoryObject(pCopy->dstDevice, offset);
|
|
|
|
|
if (memObj != nullptr) {
|
|
|
|
|
dstMemoryType = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
|
|
|
|
memObj->getMemFlags()) ? hipMemoryTypeHost : hipMemoryTypeDevice;
|
|
|
|
|
} else {
|
|
|
|
|
dstMemoryType = hipMemoryTypeHost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dstMemoryType == hipMemoryTypeHost) {
|
2021-04-30 17:52:33 +00:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->dstHost = pCopy->dstDevice;
|
2023-01-17 16:27:11 -08:00
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->dstXInBytes += offset;
|
2023-06-29 19:01:52 -04:00
|
|
|
// We don't need detect memory type again for hipMemoryTypeUnified
|
|
|
|
|
const_cast<HIP_MEMCPY3D*>(pCopy)->dstMemoryType = dstMemoryType;
|
2021-04-30 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If {src/dst}MemoryType is hipMemoryTypeHost, check if the memory was prepinned.
|
|
|
|
|
// In that case upgrade the copy type to hipMemoryTypeDevice to avoid extra pinning.
|
2023-01-17 16:27:11 -08:00
|
|
|
offset = 0;
|
2021-04-30 17:52:33 +00:00
|
|
|
if (srcMemoryType == hipMemoryTypeHost) {
|
2023-02-21 16:32:29 -08:00
|
|
|
srcMemoryType = getMemoryObject(pCopy->srcHost, offset) ? hipMemoryTypeDevice :
|
|
|
|
|
hipMemoryTypeHost;
|
2021-04-30 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
if (dstMemoryType == hipMemoryTypeHost) {
|
2023-02-21 16:32:29 -08:00
|
|
|
dstMemoryType = getMemoryObject(pCopy->dstHost, offset) ? hipMemoryTypeDevice :
|
|
|
|
|
hipMemoryTypeHost;
|
2021-04-30 17:52:33 +00:00
|
|
|
}
|
2023-02-21 16:32:29 -08:00
|
|
|
|
2021-04-30 17:52:33 +00:00
|
|
|
if ((srcMemoryType == hipMemoryTypeHost) && (dstMemoryType == hipMemoryTypeHost)) {
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Coord3D srcOrigin = {pCopy->srcXInBytes, pCopy->srcY, pCopy->srcZ};
|
|
|
|
|
amd::Coord3D dstOrigin = {pCopy->dstXInBytes, pCopy->dstY, pCopy->dstZ};
|
|
|
|
|
amd::Coord3D copyRegion = {pCopy->WidthInBytes, (pCopy->Height != 0) ? pCopy->Height : 1,
|
|
|
|
|
(pCopy->Depth != 0) ? pCopy->Depth : 1};
|
2022-12-21 15:04:28 +00:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
// Host to Host.
|
|
|
|
|
return ihipMemcpyHtoH(pCopy->srcHost, pCopy->dstHost, srcOrigin, dstOrigin, copyRegion,
|
|
|
|
|
pCopy->srcPitch, pCopy->srcPitch * pCopy->srcHeight, pCopy->dstPitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
pCopy->dstPitch * pCopy->dstHeight, hip::getStream(stream));
|
2021-03-11 12:10:49 -08:00
|
|
|
} else {
|
2021-11-29 17:53:36 +00:00
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
status = ihipGetMemcpyParam3DCommand(command, pCopy, hip_stream);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
2022-12-21 15:04:28 +00:00
|
|
|
|
2023-02-21 16:32:29 -08:00
|
|
|
// Transfers from device memory to pageable host memory and transfers from any
|
|
|
|
|
// host memory to any host memory are synchronous with respect to the host.
|
|
|
|
|
// Device to Device copies do not need to host side synchronization.
|
2022-12-21 15:04:28 +00:00
|
|
|
if (dstMemoryType == hipMemoryTypeHost ||
|
2023-02-21 16:32:29 -08:00
|
|
|
((pCopy->srcMemoryType == hipMemoryTypeHost) &&
|
|
|
|
|
(pCopy->dstMemoryType == hipMemoryTypeHost))) {
|
|
|
|
|
isAsync = false;
|
|
|
|
|
} else if ((pCopy->srcMemoryType == hipMemoryTypeDevice) &&
|
|
|
|
|
(pCopy->dstMemoryType == hipMemoryTypeDevice)) {
|
|
|
|
|
// Device to Device copies dont need to wait for host synchronization
|
|
|
|
|
isAsync = true;
|
2022-12-21 15:04:28 +00:00
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t ihipMemcpyParam2D(const hip_Memcpy2D* pCopy,
|
|
|
|
|
hipStream_t stream,
|
|
|
|
|
bool isAsync = false) {
|
2020-03-09 14:05:16 -04:00
|
|
|
HIP_MEMCPY3D desc = hip::getDrvMemcpy3DDesc(*pCopy);
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
return ihipMemcpyParam3D(&desc, stream, isAsync);
|
|
|
|
|
}
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t ihipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
|
2020-03-01 13:40:14 -05:00
|
|
|
size_t height, hipMemcpyKind kind, hipStream_t stream, bool isAsync = false) {
|
2020-02-23 15:34:31 -05:00
|
|
|
hip_Memcpy2D desc = {};
|
2022-05-18 23:25:14 +05:30
|
|
|
if ((width == 0) || (height == 0)) {
|
2020-11-02 11:45:03 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2022-05-18 23:25:14 +05:30
|
|
|
if ((width > dpitch) || (width > spitch)) {
|
|
|
|
|
return hipErrorInvalidPitchValue;
|
|
|
|
|
}
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
desc.srcXInBytes = 0;
|
|
|
|
|
desc.srcY = 0;
|
|
|
|
|
desc.srcMemoryType = std::get<0>(hip::getMemoryType(kind));
|
|
|
|
|
desc.srcHost = src;
|
|
|
|
|
desc.srcDevice = const_cast<void*>(src);
|
|
|
|
|
desc.srcArray = nullptr; // Ignored.
|
|
|
|
|
desc.srcPitch = spitch;
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
desc.dstXInBytes = 0;
|
|
|
|
|
desc.dstY = 0;
|
|
|
|
|
desc.dstMemoryType = std::get<1>(hip::getMemoryType(kind));
|
|
|
|
|
desc.dstHost = dst;
|
|
|
|
|
desc.dstDevice = dst;
|
|
|
|
|
desc.dstArray = nullptr; // Ignored.
|
|
|
|
|
desc.dstPitch = dpitch;
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
desc.WidthInBytes = width;
|
|
|
|
|
desc.Height = height;
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
return ihipMemcpyParam2D(&desc, stream, isAsync);
|
|
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpyParam2D(const hip_Memcpy2D* pCopy) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyParam2D, pCopy);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyParam2D(pCopy, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2022-12-17 12:23:06 -05:00
|
|
|
hipError_t hipMemcpy2DValidateParams(hipMemcpyKind kind, hipStream_t stream = nullptr) {
|
|
|
|
|
|
|
|
|
|
if (kind < hipMemcpyHostToHost || kind > hipMemcpyDefault) {
|
|
|
|
|
return hipErrorInvalidMemcpyDirection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy2DValidateBuffer(const void* buf, size_t pitch, size_t width) {
|
|
|
|
|
|
|
|
|
|
if (buf == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pitch == 0 || pitch < width) {
|
|
|
|
|
return hipErrorInvalidPitchValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy2DValidateArray(hipArray_const_t arr, size_t wOffset, size_t hOffset,
|
|
|
|
|
size_t width, size_t height) {
|
|
|
|
|
|
|
|
|
|
if (arr == nullptr) {
|
|
|
|
|
return hipErrorInvalidHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FormatSize = hip::getElementSize(arr);
|
|
|
|
|
if ((width + wOffset) > (arr->width * FormatSize)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
if (arr->height == 0) {//1D hipArray
|
|
|
|
|
if (height + hOffset > 1) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
} else if ((height + hOffset) > (arr->height)) {//2D hipArray
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpy2D_common(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
|
2022-12-17 12:23:06 -05:00
|
|
|
size_t height, hipMemcpyKind kind, hipStream_t stream = nullptr,
|
|
|
|
|
bool isAsync = false) {
|
|
|
|
|
|
2022-12-26 23:56:12 +05:30
|
|
|
hipError_t validateParams = hipSuccess, validateSrc = hipSuccess, validateDst = hipSuccess;
|
2022-12-17 12:23:06 -05:00
|
|
|
if ((validateParams = hipMemcpy2DValidateParams(kind,stream)) != hipSuccess) {
|
|
|
|
|
return validateParams;
|
|
|
|
|
}
|
|
|
|
|
if ((validateSrc = hipMemcpy2DValidateBuffer(src,spitch,width)) != hipSuccess) {
|
|
|
|
|
return validateSrc;
|
|
|
|
|
}
|
|
|
|
|
if ((validateDst = hipMemcpy2DValidateBuffer(dst,dpitch, width)) != hipSuccess) {
|
|
|
|
|
return validateDst;
|
|
|
|
|
}
|
|
|
|
|
return ihipMemcpy2D(dst, dpitch, src, spitch, width, height, kind, stream, isAsync);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
|
|
|
|
|
size_t height, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2D, dst, dpitch, src, spitch, width, height, kind);
|
2022-12-17 12:23:06 -05:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy2D_common(dst, dpitch, src, spitch, width, height, kind));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy2D_spt(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
|
|
|
|
|
size_t height, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2D, dst, dpitch, src, spitch, width, height, kind);
|
2022-12-17 12:23:06 -05:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy2D_common(dst, dpitch, src, spitch, width, height, kind,
|
|
|
|
|
getPerThreadDefaultStream()));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
|
|
|
|
|
size_t height, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DAsync, dst, dpitch, src, spitch, width, height, kind, stream);
|
2022-12-17 12:23:06 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpy2DAsync, stream, dst, dpitch, src, spitch, width, height, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy2D_common(dst, dpitch, src, spitch, width, height, kind, stream, true));
|
2022-07-05 03:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy2DAsync_spt(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
|
|
|
|
|
size_t height, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DAsync, dst, dpitch, src, spitch, width, height, kind, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
2022-12-17 12:23:06 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpy2DAsync, stream, dst, dpitch, src, spitch, width, height, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy2D_common(dst, dpitch, src, spitch, width, height, kind, stream, true));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpy2DToArray(hipArray_t dst, size_t wOffset, size_t hOffset, const void* src, size_t spitch, size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream, bool isAsync = false) {
|
2021-03-18 11:25:55 +00:00
|
|
|
if (dst == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hip_Memcpy2D desc = {};
|
|
|
|
|
|
|
|
|
|
desc.srcXInBytes = 0;
|
|
|
|
|
desc.srcY = 0;
|
|
|
|
|
desc.srcMemoryType = std::get<0>(hip::getMemoryType(kind));
|
|
|
|
|
desc.srcHost = const_cast<void*>(src);
|
|
|
|
|
desc.srcDevice = const_cast<void*>(src);
|
|
|
|
|
desc.srcArray = nullptr;
|
|
|
|
|
desc.srcPitch = spitch;
|
|
|
|
|
|
|
|
|
|
desc.dstXInBytes = wOffset;
|
|
|
|
|
desc.dstY = hOffset;
|
|
|
|
|
desc.dstMemoryType = hipMemoryTypeArray;
|
|
|
|
|
desc.dstHost = nullptr;
|
|
|
|
|
desc.dstDevice = nullptr;
|
|
|
|
|
desc.dstArray = dst;
|
|
|
|
|
desc.dstPitch = 0; // Ignored.
|
|
|
|
|
|
|
|
|
|
desc.WidthInBytes = width;
|
|
|
|
|
desc.Height = height;
|
|
|
|
|
|
|
|
|
|
return ihipMemcpyParam2D(&desc, stream, isAsync);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpy2DToArray_common(hipArray* dst, size_t wOffset, size_t hOffset,
|
|
|
|
|
const void* src, size_t spitch, size_t width,
|
2022-12-17 12:23:06 -05:00
|
|
|
size_t height, hipMemcpyKind kind, hipStream_t stream=nullptr,
|
|
|
|
|
bool isAsync = false) {
|
|
|
|
|
|
2023-01-13 18:00:52 -05:00
|
|
|
hipError_t validateParams = hipSuccess, validateSrc = hipSuccess, validateDst = hipSuccess;
|
2022-12-17 12:23:06 -05:00
|
|
|
if ((validateParams = hipMemcpy2DValidateParams(kind,stream)) != hipSuccess) {
|
|
|
|
|
return validateParams;
|
2022-11-23 21:15:35 +00:00
|
|
|
}
|
2022-12-17 12:23:06 -05:00
|
|
|
if ((validateSrc = hipMemcpy2DValidateBuffer(src,spitch,width)) != hipSuccess) {
|
|
|
|
|
return validateSrc;
|
2022-11-23 21:15:35 +00:00
|
|
|
}
|
2022-12-17 12:23:06 -05:00
|
|
|
if ((validateDst = hipMemcpy2DValidateArray(dst, wOffset, hOffset, width, height)) != hipSuccess) {
|
|
|
|
|
return validateDst;
|
2022-11-23 21:15:35 +00:00
|
|
|
}
|
2022-12-17 12:23:06 -05:00
|
|
|
return ihipMemcpy2DToArray(dst, wOffset, hOffset, src, spitch, width, height, kind, stream, isAsync);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
2021-03-18 11:25:55 +00:00
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpy2DToArray(hipArray* dst, size_t wOffset, size_t hOffset, const void* src, size_t spitch, size_t width, size_t height, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DToArray, dst, wOffset, hOffset, src, spitch, width, height, kind);
|
2022-12-17 12:23:06 -05:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DToArray_common(dst, wOffset, hOffset, src, spitch, width, height, kind));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy2DToArray_spt(hipArray* dst, size_t wOffset, size_t hOffset, const void* src, size_t spitch, size_t width, size_t height, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DToArray, dst, wOffset, hOffset, src, spitch, width, height, kind);
|
2022-12-17 12:23:06 -05:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-06-16 16:12:54 -07:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DToArray_common(dst, wOffset, hOffset, src, spitch,
|
2022-04-13 06:35:25 +00:00
|
|
|
width, height, kind, getPerThreadDefaultStream()));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyToArray(hipArray* dst, size_t wOffset, size_t hOffset, const void* src, size_t count, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyToArray, dst, wOffset, hOffset, src, count, kind);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-02-23 15:34:31 -05:00
|
|
|
if (dst == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-04-30 14:55:41 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
const size_t arrayHeight = (dst->height != 0) ? dst->height : 1;
|
|
|
|
|
const size_t witdthInBytes = count / arrayHeight;
|
|
|
|
|
|
2020-03-27 13:47:44 -04:00
|
|
|
const size_t height = (count / dst->width) / hip::getElementSize(dst);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy2DToArray(dst, wOffset, hOffset, src, 0 /* spitch */, witdthInBytes, height, kind, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpy2DFromArray(void* dst, size_t dpitch, hipArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream, bool isAsync = false) {
|
2021-03-08 07:48:24 -08:00
|
|
|
if (src == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hip_Memcpy2D desc = {};
|
|
|
|
|
|
|
|
|
|
desc.srcXInBytes = wOffsetSrc;
|
|
|
|
|
desc.srcY = hOffsetSrc;
|
|
|
|
|
desc.srcMemoryType = hipMemoryTypeArray;
|
|
|
|
|
desc.srcHost = nullptr;
|
|
|
|
|
desc.srcDevice = nullptr;
|
|
|
|
|
desc.srcArray = const_cast<hipArray_t>(src);
|
|
|
|
|
desc.srcPitch = 0; // Ignored.
|
|
|
|
|
|
|
|
|
|
desc.dstXInBytes = 0;
|
|
|
|
|
desc.dstY = 0;
|
|
|
|
|
desc.dstMemoryType = std::get<1>(hip::getMemoryType(kind));
|
|
|
|
|
desc.dstHost = dst;
|
|
|
|
|
desc.dstDevice = dst;
|
|
|
|
|
desc.dstArray = nullptr;
|
|
|
|
|
desc.dstPitch = dpitch;
|
|
|
|
|
|
|
|
|
|
desc.WidthInBytes = width;
|
|
|
|
|
desc.Height = height;
|
|
|
|
|
|
|
|
|
|
return ihipMemcpyParam2D(&desc, stream, isAsync);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpyFromArray_common(void* dst, hipArray_const_t src, size_t wOffsetSrc,
|
|
|
|
|
size_t hOffset, size_t count, hipMemcpyKind kind, hipStream_t stream) {
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-02-23 15:34:31 -05:00
|
|
|
if (src == nullptr) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidValue;
|
2020-01-07 15:59:02 -05:00
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
const size_t arrayHeight = (src->height != 0) ? src->height : 1;
|
|
|
|
|
const size_t witdthInBytes = count / arrayHeight;
|
|
|
|
|
|
2020-03-27 13:47:44 -04:00
|
|
|
const size_t height = (count / src->width) / hip::getElementSize(src);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
return ihipMemcpy2DFromArray(dst, 0 /* dpitch */, src, wOffsetSrc, hOffset, witdthInBytes, height, kind, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t src, size_t wOffsetSrc, size_t hOffset, size_t count, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyFromArray, dst, src, wOffsetSrc, hOffset, count, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyFromArray_common(dst, src, wOffsetSrc, hOffset, count, kind, nullptr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromArray_spt(void* dst, hipArray_const_t src, size_t wOffsetSrc, size_t hOffset, size_t count, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyFromArray, dst, src, wOffsetSrc, hOffset, count, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpyFromArray_common(dst, src, wOffsetSrc, hOffset, count, kind,
|
|
|
|
|
getPerThreadDefaultStream()));
|
2020-01-07 15:59:02 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipMemcpyAtoD(hipArray* srcArray, void* dstDevice, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t dstRowPitch,
|
|
|
|
|
size_t dstSlicePitch, hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status =
|
|
|
|
|
ihipMemcpyAtoDCommand(command, srcArray, dstDevice, srcOrigin, dstOrigin, copyRegion,
|
2023-02-08 20:18:11 +00:00
|
|
|
dstRowPitch, dstSlicePitch, hip_stream);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
hipError_t ihipMemcpyDtoA(void* srcDevice, hipArray* dstArray, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t srcRowPitch,
|
|
|
|
|
size_t srcSlicePitch, hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status =
|
|
|
|
|
ihipMemcpyDtoACommand(command, srcDevice, dstArray, srcOrigin, dstOrigin, copyRegion,
|
2023-02-08 20:18:11 +00:00
|
|
|
srcRowPitch, srcSlicePitch, hip_stream);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
hipError_t ihipMemcpyDtoD(void* srcDevice, void* dstDevice, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t srcRowPitch,
|
|
|
|
|
size_t srcSlicePitch, size_t dstRowPitch, size_t dstSlicePitch,
|
|
|
|
|
hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status = ihipMemcpyDtoDCommand(command, srcDevice, dstDevice, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, srcRowPitch, srcSlicePitch, dstRowPitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
dstSlicePitch, hip_stream);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
hipError_t ihipMemcpyDtoH(void* srcDevice, void* dstHost, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t srcRowPitch,
|
|
|
|
|
size_t srcSlicePitch, size_t dstRowPitch, size_t dstSlicePitch,
|
|
|
|
|
hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status = ihipMemcpyDtoHCommand(command, srcDevice, dstHost, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, srcRowPitch, srcSlicePitch, dstRowPitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
dstSlicePitch, hip_stream, isAsync);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
hipError_t ihipMemcpyHtoD(const void* srcHost, void* dstDevice, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t srcRowPitch,
|
|
|
|
|
size_t srcSlicePitch, size_t dstRowPitch, size_t dstSlicePitch,
|
|
|
|
|
hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status = ihipMemcpyHtoDCommand(command, srcHost, dstDevice, srcOrigin, dstOrigin,
|
|
|
|
|
copyRegion, srcRowPitch, srcSlicePitch, dstRowPitch,
|
2023-02-08 20:18:11 +00:00
|
|
|
dstSlicePitch, hip_stream, isAsync);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
hipError_t ihipMemcpyAtoA(hipArray* srcArray, hipArray* dstArray, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, hipStream_t stream,
|
|
|
|
|
bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status = ihipMemcpyAtoACommand(command, srcArray, dstArray, srcOrigin, dstOrigin,
|
2023-02-08 20:18:11 +00:00
|
|
|
copyRegion, hip_stream);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
hipError_t ihipMemcpyHtoA(const void* srcHost, hipArray* dstArray, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t srcRowPitch,
|
|
|
|
|
size_t srcSlicePitch, hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status =
|
|
|
|
|
ihipMemcpyHtoACommand(command, srcHost, dstArray, srcOrigin, dstOrigin, copyRegion,
|
2023-02-08 20:18:11 +00:00
|
|
|
srcRowPitch, srcSlicePitch, hip_stream, isAsync);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
hipError_t ihipMemcpyAtoH(hipArray* srcArray, void* dstHost, amd::Coord3D srcOrigin,
|
|
|
|
|
amd::Coord3D dstOrigin, amd::Coord3D copyRegion, size_t dstRowPitch,
|
|
|
|
|
size_t dstSlicePitch, hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
if (hip_stream == nullptr) {
|
2022-12-26 23:56:12 +05:30
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t status =
|
|
|
|
|
ihipMemcpyAtoHCommand(command, srcArray, dstHost, srcOrigin, dstOrigin, copyRegion,
|
2023-02-08 20:18:11 +00:00
|
|
|
dstRowPitch, dstSlicePitch, hip_stream, isAsync);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) return status;
|
|
|
|
|
return ihipMemcpyCmdEnqueue(command, isAsync);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpyHtoA(hipArray* dstArray,
|
|
|
|
|
size_t dstOffset,
|
|
|
|
|
const void* srcHost,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyHtoA, dstArray, dstOffset, srcHost, ByteCount);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyHtoA(srcHost, dstArray, {0, 0, 0}, {dstOffset, 0, 0}, {ByteCount, 1, 1}, 0, 0, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyAtoH(void* dstHost,
|
|
|
|
|
hipArray* srcArray,
|
|
|
|
|
size_t srcOffset,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyAtoH, dstHost, srcArray, srcOffset, ByteCount);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyAtoH(srcArray, dstHost, {srcOffset, 0, 0}, {0, 0, 0}, {ByteCount, 1, 1}, 0, 0, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipMemcpy3D_validate(const hipMemcpy3DParms* p) {
|
2022-01-11 15:49:48 +00:00
|
|
|
// Passing more than one non-zero source or destination will cause hipMemcpy3D() to
|
2021-03-11 12:10:49 -08:00
|
|
|
// return an error.
|
2021-03-31 04:31:19 -07:00
|
|
|
if (p == nullptr || ((p->srcArray != nullptr) && (p->srcPtr.ptr != nullptr)) ||
|
2020-03-01 13:40:14 -05:00
|
|
|
((p->dstArray != nullptr) && (p->dstPtr.ptr != nullptr))) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-01-11 15:49:48 +00:00
|
|
|
// The struct passed to hipMemcpy3D() must specify one of srcArray or srcPtr and one of dstArray
|
|
|
|
|
// or dstPtr.
|
|
|
|
|
if (((p->srcArray == nullptr) && (p->srcPtr.ptr == nullptr)) ||
|
|
|
|
|
((p->dstArray == nullptr) && (p->dstPtr.ptr == nullptr))) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2020-03-01 13:40:14 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
// If the source and destination are both arrays, hipMemcpy3D() will return an error if they do
|
|
|
|
|
// not have the same element size.
|
2020-03-01 13:40:14 -05:00
|
|
|
if (((p->srcArray != nullptr) && (p->dstArray != nullptr)) &&
|
2020-03-27 13:47:44 -04:00
|
|
|
(hip::getElementSize(p->dstArray) != hip::getElementSize(p->dstArray))) {
|
2020-03-01 13:40:14 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 18:07:00 +00:00
|
|
|
|
|
|
|
|
// Pitch should not be less than width for both src and dst.
|
|
|
|
|
if (p->srcPtr.pitch < p->srcPtr.xsize || p->dstPtr.pitch < p->dstPtr.xsize) {
|
|
|
|
|
return hipErrorInvalidPitchValue;
|
|
|
|
|
}
|
2023-04-11 19:32:56 +00:00
|
|
|
// dst/src pitch must be less than max pitch
|
|
|
|
|
auto* deviceHandle = g_devices[hip::getCurrentDevice()->deviceId()]->devices()[0];
|
|
|
|
|
const auto& info = deviceHandle->info();
|
|
|
|
|
constexpr auto int32_max = static_cast<uint64_t>(std::numeric_limits<int32_t>::max());
|
|
|
|
|
auto maxPitch = std::min(info.maxMemAllocSize_, int32_max);
|
2022-12-17 12:23:06 -05:00
|
|
|
|
2023-04-11 19:32:56 +00:00
|
|
|
// negative pitch cases
|
|
|
|
|
if (p->dstPtr.pitch >= maxPitch || p->srcPtr.pitch >= maxPitch) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p->dstArray == nullptr && p->srcArray == nullptr) {
|
|
|
|
|
if ((p->extent.width + p->dstPos.x > p->dstPtr.pitch) ||
|
|
|
|
|
(p->extent.width + p->srcPos.x > p->srcPtr.pitch)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
auto totalExtentBytes = p->extent.width * p->extent.height * p->extent.depth;
|
|
|
|
|
// get memory obj of the PitchPtr
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* srcPtrMemObj = getMemoryObject(p->srcPtr.ptr, offset);
|
|
|
|
|
amd::Memory* dstPtrMemObj = getMemoryObject(p->dstPtr.ptr, offset);
|
|
|
|
|
|
|
|
|
|
if (dstPtrMemObj != nullptr && (p->dstPtr.xsize != 0 && p->dstPtr.ysize != 0)) {
|
|
|
|
|
// Use the memoryObj to get 3d data
|
|
|
|
|
const auto& dstUsrData = dstPtrMemObj->getUserData();
|
|
|
|
|
// dst ptr out of bound cases for linear memory
|
|
|
|
|
if (dstUsrData.pitch_ == 0 || dstUsrData.height_ == 0 || dstUsrData.depth_ == 0) {
|
|
|
|
|
auto dstDepth = dstPtrMemObj->getSize() / (p->dstPtr.xsize * p->dstPtr.ysize);
|
|
|
|
|
if ((p->dstPtr.xsize * (p->dstPtr.ysize - p->dstPos.y) *
|
|
|
|
|
(dstDepth - p->dstPos.z)) < totalExtentBytes) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
// out of bound dst ptr for 3d memory
|
|
|
|
|
} else if ((dstUsrData.pitch_ * (dstUsrData.height_ - p->dstPos.y) *
|
|
|
|
|
(dstUsrData.depth_ - p->dstPos.z)) < totalExtentBytes) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (srcPtrMemObj != nullptr && (p->srcPtr.xsize != 0 && p->srcPtr.ysize != 0)) {
|
|
|
|
|
const auto& srcUsrData = srcPtrMemObj->getUserData();
|
|
|
|
|
// src ptr out of bound cases for linear memory
|
|
|
|
|
if (srcUsrData.pitch_ == 0 || srcUsrData.height_ == 0 || srcUsrData.depth_ == 0) {
|
|
|
|
|
auto srcDepth = srcPtrMemObj->getSize() / (p->srcPtr.xsize * p->srcPtr.ysize);
|
|
|
|
|
if ((p->srcPtr.xsize * (p->srcPtr.ysize - p->srcPos.y) *
|
|
|
|
|
(srcDepth - p->srcPos.z)) < totalExtentBytes) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
// out of bound src ptr for 3d memory
|
|
|
|
|
} else if ((srcUsrData.pitch_ * (srcUsrData.height_ - p->srcPos.y) *
|
|
|
|
|
(srcUsrData.depth_ - p->srcPos.z)) < totalExtentBytes) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-17 12:23:06 -05:00
|
|
|
if (p->kind < hipMemcpyHostToHost || p->kind > hipMemcpyDefault) {
|
|
|
|
|
return hipErrorInvalidMemcpyDirection;
|
|
|
|
|
}
|
2023-01-02 13:08:13 +00:00
|
|
|
//If src and dst ptr are null then kind must be either h2h or def.
|
|
|
|
|
if (!IsHtoHMemcpyValid(p->dstPtr.ptr, p->srcPtr.ptr, p->kind)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipMemcpy3DCommand(amd::Command*& command, const hipMemcpy3DParms* p,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream) {
|
2021-03-11 12:10:49 -08:00
|
|
|
const HIP_MEMCPY3D desc = hip::getDrvMemcpy3DDesc(*p);
|
2023-02-08 20:18:11 +00:00
|
|
|
return ihipGetMemcpyParam3DCommand(command, &desc, stream);
|
2021-03-11 12:10:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpy3D(const hipMemcpy3DParms* p, hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
hipError_t status = ihipMemcpy3D_validate(p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2020-03-09 14:05:16 -04:00
|
|
|
const HIP_MEMCPY3D desc = hip::getDrvMemcpy3DDesc(*p);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2020-03-06 14:33:52 -05:00
|
|
|
return ihipMemcpyParam3D(&desc, stream, isAsync);
|
2020-01-07 15:59:02 -05:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpy3D_common(const hipMemcpy3DParms* p, hipStream_t stream = nullptr) {
|
|
|
|
|
CHECK_STREAM_CAPTURING();
|
|
|
|
|
return ihipMemcpy3D(p, stream);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpy3D(const hipMemcpy3DParms* p) {
|
2020-01-07 15:59:02 -05:00
|
|
|
HIP_INIT_API(hipMemcpy3D, p);
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy3D_common(p));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy3D_spt(const hipMemcpy3DParms* p) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy3D, p);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy3D_common(p, getPerThreadDefaultStream()));
|
2020-01-07 15:59:02 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpy3DAsync_common(const hipMemcpy3DParms* p, hipStream_t stream) {
|
|
|
|
|
STREAM_CAPTURE(hipMemcpy3DAsync, stream, p);
|
|
|
|
|
return ihipMemcpy3D(p, stream, true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipMemcpy3DAsync(const hipMemcpy3DParms* p, hipStream_t stream) {
|
2020-01-07 15:59:02 -05:00
|
|
|
HIP_INIT_API(hipMemcpy3DAsync, p, stream);
|
2022-07-05 03:53:31 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy3DAsync_common(p, stream));
|
|
|
|
|
}
|
2020-01-07 15:59:02 -05:00
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpy3DAsync_spt(const hipMemcpy3DParms* p, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy3DAsync, p, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy3DAsync_common(p, stream));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-03-09 14:05:16 -04:00
|
|
|
hipError_t hipDrvMemcpy3D(const HIP_MEMCPY3D* pCopy) {
|
2020-03-01 13:40:14 -05:00
|
|
|
HIP_INIT_API(hipDrvMemcpy3D, pCopy);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyParam3D(pCopy, nullptr));
|
2020-03-01 13:40:14 -05:00
|
|
|
}
|
|
|
|
|
|
2020-03-09 14:05:16 -04:00
|
|
|
hipError_t hipDrvMemcpy3DAsync(const HIP_MEMCPY3D* pCopy, hipStream_t stream) {
|
2020-03-01 13:40:14 -05:00
|
|
|
HIP_INIT_API(hipDrvMemcpy3DAsync, pCopy, stream);
|
|
|
|
|
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyParam3D(pCopy, stream, true));
|
2020-03-01 13:40:14 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t packFillMemoryCommand(amd::Command*& command, amd::Memory* memory, size_t offset,
|
|
|
|
|
int64_t value, size_t valueSize, size_t sizeBytes,
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* stream) {
|
|
|
|
|
if ((memory == nullptr) || (stream == nullptr)) {
|
2020-04-22 18:29:31 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
amd::Command::EventWaitList waitList;
|
|
|
|
|
amd::Coord3D fillOffset(offset, 0, 0);
|
|
|
|
|
amd::Coord3D fillSize(sizeBytes, 1, 1);
|
2021-09-17 09:31:54 +00:00
|
|
|
// surface=[pitch, width, height]
|
|
|
|
|
amd::Coord3D surface(sizeBytes, sizeBytes, 1);
|
2021-12-20 15:05:51 +00:00
|
|
|
amd::FillMemoryCommand* fillMemCommand =
|
2023-02-08 20:18:11 +00:00
|
|
|
new amd::FillMemoryCommand(*stream, CL_COMMAND_FILL_BUFFER, waitList, *memory->asBuffer(),
|
2021-09-17 09:31:54 +00:00
|
|
|
&value, valueSize, fillOffset, fillSize, surface);
|
2021-12-20 15:05:51 +00:00
|
|
|
if (fillMemCommand == nullptr) {
|
2020-04-22 18:29:31 -04:00
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
2021-12-20 15:05:51 +00:00
|
|
|
|
|
|
|
|
if (!fillMemCommand->validatePeerMemory()) {
|
|
|
|
|
delete fillMemCommand;
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
command = fillMemCommand;
|
2020-04-22 18:29:31 -04:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t ihipMemset_validate(void* dst, int64_t value, size_t valueSize,
|
2021-03-11 12:10:49 -08:00
|
|
|
size_t sizeBytes) {
|
2019-10-17 14:09:46 -04:00
|
|
|
if (sizeBytes == 0) {
|
|
|
|
|
// Skip if nothing needs filling.
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2018-05-08 15:43:13 -04:00
|
|
|
if (dst == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2018-05-08 15:43:13 -04:00
|
|
|
size_t offset = 0;
|
2020-06-19 00:12:36 -04:00
|
|
|
amd::Memory* memory = getMemoryObject(dst, offset);
|
2020-04-22 18:29:31 -04:00
|
|
|
if (memory == nullptr) {
|
2020-07-08 00:04:55 -04:00
|
|
|
// dst ptr is host ptr hence error
|
|
|
|
|
return hipErrorInvalidValue;
|
2020-04-22 18:29:31 -04:00
|
|
|
}
|
2022-08-15 20:50:13 +00:00
|
|
|
// Return error if sizeBytes passed to memcpy is more than the actual size allocated
|
|
|
|
|
if (sizeBytes > (memory->getSize() - offset)){
|
2022-04-05 14:30:16 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2022-01-21 23:50:18 +00:00
|
|
|
hipError_t ihipGraphMemsetParams_validate(const hipMemsetParams* pNodeParams) {
|
|
|
|
|
if (pNodeParams == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 11:48:52 +00:00
|
|
|
|
|
|
|
|
if (pNodeParams->width == 0) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-21 23:50:18 +00:00
|
|
|
if (pNodeParams->elementSize != 1 && pNodeParams->elementSize != 2 && pNodeParams->elementSize != 4) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pNodeParams->height <= 0) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2023-01-02 11:12:52 +00:00
|
|
|
|
2023-01-17 16:27:11 -08:00
|
|
|
size_t discardOffset = 0;
|
|
|
|
|
amd::Memory *memObj = getMemoryObject(pNodeParams->dst, discardOffset);
|
2023-01-02 11:12:52 +00:00
|
|
|
if (memObj != nullptr) {
|
|
|
|
|
if ((pNodeParams->pitch * pNodeParams->height) > memObj->getSize()) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-21 23:50:18 +00:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipMemsetCommand(std::vector<amd::Command*>& commands, void* dst, int64_t value,
|
2023-02-08 20:18:11 +00:00
|
|
|
size_t valueSize, size_t sizeBytes, hip::Stream* stream) {
|
2020-04-22 18:29:31 -04:00
|
|
|
hipError_t hip_error = hipSuccess;
|
2021-03-11 12:10:49 -08:00
|
|
|
auto aligned_dst = amd::alignUp(reinterpret_cast<address>(dst), sizeof(uint64_t));
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memory = getMemoryObject(dst, offset);
|
2020-05-12 15:14:06 -04:00
|
|
|
size_t n_head_bytes = 0;
|
|
|
|
|
size_t n_tail_bytes = 0;
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::Command* command;
|
|
|
|
|
|
2021-08-23 21:51:09 -04:00
|
|
|
hip_error = packFillMemoryCommand(command, memory, offset, value, valueSize, sizeBytes,
|
2023-02-08 20:18:11 +00:00
|
|
|
stream);
|
2021-08-23 21:51:09 -04:00
|
|
|
commands.push_back(command);
|
2020-04-22 18:29:31 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
return hip_error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemset(void* dst, int64_t value, size_t valueSize, size_t sizeBytes,
|
|
|
|
|
hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
hipError_t hip_error = hipSuccess;
|
2021-11-09 09:27:10 -05:00
|
|
|
do {
|
|
|
|
|
// Nothing to do, fill size is 0. Returns hipSuccess.
|
|
|
|
|
if (sizeBytes == 0) {
|
|
|
|
|
break;
|
2021-03-11 12:10:49 -08:00
|
|
|
}
|
2021-11-09 09:27:10 -05:00
|
|
|
|
|
|
|
|
// In case of validation failure stop processing. Returns hip_error.
|
|
|
|
|
hip_error = ihipMemset_validate(dst, value, valueSize, sizeBytes);
|
|
|
|
|
if (hip_error != hipSuccess) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-08-18 09:43:09 +00:00
|
|
|
// This is required to comply with the spec
|
|
|
|
|
// spec says hipMemset will be asynchronous when destination memory is device memory
|
|
|
|
|
// and pointer is non-offseted
|
|
|
|
|
if (isAsync == false) {
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(dst, offset);
|
|
|
|
|
auto flags = memObj->getMemFlags();
|
2023-01-13 18:00:52 -05:00
|
|
|
if ((memObj->getUserData().sync_mem_ops_)
|
2022-10-07 16:45:22 -04:00
|
|
|
|| (offset == 0 && !(flags & (CL_MEM_SVM_FINE_GRAIN_BUFFER
|
|
|
|
|
| CL_MEM_SVM_ATOMICS | CL_MEM_USE_HOST_PTR)))) {
|
2022-08-18 09:43:09 +00:00
|
|
|
isAsync = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-09 09:27:10 -05:00
|
|
|
std::vector<amd::Command*> commands;
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
|
|
|
|
hip_error = ihipMemsetCommand(commands, dst, value, valueSize, sizeBytes, hip_stream);
|
2021-11-09 09:27:10 -05:00
|
|
|
if (hip_error != hipSuccess) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto command : commands) {
|
|
|
|
|
command->enqueue();
|
|
|
|
|
if (!isAsync) {
|
|
|
|
|
command->awaitCompletion();
|
|
|
|
|
}
|
|
|
|
|
command->release();
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
2020-04-22 18:29:31 -04:00
|
|
|
return hip_error;
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemset_common(void* dst, int value, size_t sizeBytes, hipStream_t stream=nullptr) {
|
|
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-08-18 09:43:09 +00:00
|
|
|
return ihipMemset(dst, value, sizeof(int8_t), sizeBytes, stream);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemset_spt(void* dst, int value, size_t sizeBytes) {
|
|
|
|
|
HIP_INIT_API(hipMemset, dst, value, sizeBytes);
|
|
|
|
|
HIP_RETURN(hipMemset_common(dst, value, sizeBytes, getPerThreadDefaultStream()));
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemset(void* dst, int value, size_t sizeBytes) {
|
|
|
|
|
HIP_INIT_API(hipMemset, dst, value, sizeBytes);
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN(hipMemset_common(dst, value, sizeBytes));
|
2018-05-05 00:34:05 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemsetAsync_common(void* dst, int value, size_t sizeBytes, hipStream_t stream) {
|
2021-03-02 16:23:47 -05:00
|
|
|
size_t valueSize = sizeof(int8_t);
|
|
|
|
|
STREAM_CAPTURE(hipMemsetAsync, stream, dst, value, valueSize, sizeBytes);
|
2022-07-05 03:53:31 +00:00
|
|
|
return ihipMemset(dst, value, sizeof(int8_t), sizeBytes, stream, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemsetAsync, dst, value, sizeBytes, stream);
|
|
|
|
|
HIP_RETURN(hipMemsetAsync_common(dst, value, sizeBytes, stream));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemsetAsync_spt(void* dst, int value, size_t sizeBytes, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemsetAsync, dst, value, sizeBytes, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipMemsetAsync_common(dst, value, sizeBytes, stream));
|
2019-10-17 14:09:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t count) {
|
|
|
|
|
HIP_INIT_API(hipMemsetD8, dst, value, count);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-08-18 09:43:09 +00:00
|
|
|
HIP_RETURN(ihipMemset(dst, value, sizeof(int8_t), count * sizeof(int8_t), nullptr));
|
2018-05-02 19:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemsetD8Async(hipDeviceptr_t dst, unsigned char value, size_t count,
|
|
|
|
|
hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemsetD8Async, dst, value, count, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
int iValue = value;
|
|
|
|
|
size_t valueSize = sizeof(int8_t);
|
|
|
|
|
size_t sizeBytes = count * sizeof(int8_t);
|
|
|
|
|
STREAM_CAPTURE(hipMemsetAsync, stream, dst, iValue, valueSize, sizeBytes);
|
|
|
|
|
HIP_RETURN(ihipMemset(dst, value, valueSize, sizeBytes, stream, true));
|
2019-10-17 14:09:46 -04:00
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemsetD16(hipDeviceptr_t dst, unsigned short value, size_t count) {
|
|
|
|
|
HIP_INIT_API(hipMemsetD16, dst, value, count);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-08-18 09:43:09 +00:00
|
|
|
HIP_RETURN(ihipMemset(dst, value, sizeof(int16_t), count * sizeof(int16_t), nullptr));
|
2019-10-17 14:09:46 -04:00
|
|
|
}
|
2018-04-30 14:55:41 -04:00
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemsetD16Async(hipDeviceptr_t dst, unsigned short value, size_t count,
|
|
|
|
|
hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemsetD16Async, dst, value, count, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
int iValue = value;
|
|
|
|
|
size_t valueSize = sizeof(int16_t);
|
|
|
|
|
size_t sizeBytes = count * sizeof(int16_t);
|
|
|
|
|
STREAM_CAPTURE(hipMemsetAsync, stream, dst, iValue, valueSize, sizeBytes);
|
|
|
|
|
HIP_RETURN(ihipMemset(dst, value, valueSize, sizeBytes, stream, true));
|
2019-10-08 14:55:27 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemsetD32(hipDeviceptr_t dst, int value, size_t count) {
|
|
|
|
|
HIP_INIT_API(hipMemsetD32, dst, value, count);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-08-18 09:43:09 +00:00
|
|
|
HIP_RETURN(ihipMemset(dst, value, sizeof(int32_t), count * sizeof(int32_t), nullptr));
|
2019-10-08 14:55:27 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemsetD32Async(hipDeviceptr_t dst, int value, size_t count,
|
|
|
|
|
hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemsetD32Async, dst, value, count, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
int iValue = value;
|
|
|
|
|
size_t valueSize = sizeof(int32_t);
|
|
|
|
|
size_t sizeBytes = count * sizeof(int32_t);
|
|
|
|
|
STREAM_CAPTURE(hipMemsetAsync, stream, dst, iValue, valueSize, sizeBytes);
|
|
|
|
|
HIP_RETURN(ihipMemset(dst, value, valueSize, sizeBytes, stream, true));
|
2019-10-17 14:09:46 -04:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t ihipMemset3D_validate(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent,
|
2021-04-27 04:30:18 -07:00
|
|
|
size_t sizeBytes) {
|
2020-10-05 13:20:58 -04:00
|
|
|
size_t offset = 0;
|
2022-04-01 11:12:04 -04:00
|
|
|
amd::Memory* memory = getMemoryObject(pitchedDevPtr.ptr, offset, sizeBytes);
|
2020-10-05 13:20:58 -04:00
|
|
|
|
|
|
|
|
if (memory == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-08-15 20:50:13 +00:00
|
|
|
// Return error if sizeBytes passed to memcpy is more than the actual size allocated
|
|
|
|
|
if (sizeBytes > (memory->getSize() - offset)){
|
2020-10-05 13:20:58 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-06-14 07:49:15 +00:00
|
|
|
if (pitchedDevPtr.pitch == memory->getUserData().pitch_) {
|
|
|
|
|
if (extent.height > memory->getUserData().height_) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2020-10-05 13:20:58 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
hipError_t ihipMemset3DCommand(std::vector<amd::Command*> &commands, hipPitchedPtr pitchedDevPtr,
|
2023-02-08 20:18:11 +00:00
|
|
|
int value, hipExtent extent, hip::Stream* stream, size_t elementSize = 1) {
|
2021-03-11 12:10:49 -08:00
|
|
|
size_t offset = 0;
|
|
|
|
|
auto sizeBytes = extent.width * extent.height * extent.depth;
|
|
|
|
|
amd::Memory* memory = getMemoryObject(pitchedDevPtr.ptr, offset);
|
2020-03-31 16:15:57 -04:00
|
|
|
if (pitchedDevPtr.pitch == extent.width) {
|
2022-12-26 09:28:34 +00:00
|
|
|
return ihipMemsetCommand(commands, pitchedDevPtr.ptr, value, elementSize,
|
2023-02-08 20:18:11 +00:00
|
|
|
static_cast<size_t>(sizeBytes), stream);
|
2020-03-31 16:15:57 -04:00
|
|
|
}
|
2020-10-05 13:20:58 -04:00
|
|
|
// Workaround for cases when pitch > row until fill kernel will be updated to support pitch.
|
|
|
|
|
// Fall back to filling one row at a time.
|
2020-03-31 16:15:57 -04:00
|
|
|
amd::Coord3D origin(offset);
|
2021-09-17 09:31:54 +00:00
|
|
|
amd::Coord3D region(extent.width, extent.height, extent.depth);
|
|
|
|
|
amd::Coord3D surface(pitchedDevPtr.pitch, pitchedDevPtr.xsize, pitchedDevPtr.ysize);
|
2020-03-31 16:15:57 -04:00
|
|
|
amd::BufferRect rect;
|
2020-07-08 00:04:55 -04:00
|
|
|
if (pitchedDevPtr.pitch == 0 ||
|
2021-09-17 09:31:54 +00:00
|
|
|
!rect.create(static_cast<size_t*>(origin),
|
|
|
|
|
static_cast<size_t*>(amd::Coord3D{pitchedDevPtr.xsize, pitchedDevPtr.ysize, extent.depth}),
|
|
|
|
|
pitchedDevPtr.pitch, 0)) {
|
2020-03-31 16:15:57 -04:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
amd::FillMemoryCommand* command;
|
2021-09-17 09:31:54 +00:00
|
|
|
command = new amd::FillMemoryCommand(
|
2023-02-08 20:18:11 +00:00
|
|
|
*stream, CL_COMMAND_FILL_BUFFER, amd::Command::EventWaitList{}, *memory->asBuffer(),
|
2022-12-26 09:28:34 +00:00
|
|
|
&value, elementSize, origin, region, surface);
|
2021-09-17 09:31:54 +00:00
|
|
|
commands.push_back(command);
|
2021-03-11 12:10:49 -08:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2020-03-31 16:15:57 -04:00
|
|
|
|
2021-03-11 12:10:49 -08:00
|
|
|
|
|
|
|
|
hipError_t ihipMemset3D(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent,
|
|
|
|
|
hipStream_t stream, bool isAsync = false) {
|
2021-04-27 04:30:18 -07:00
|
|
|
auto sizeBytes = extent.width * extent.height * extent.depth;
|
|
|
|
|
|
|
|
|
|
if (sizeBytes == 0) {
|
|
|
|
|
// sizeBytes is zero hence returning early as nothing to be set
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
hipError_t status = ihipMemset3D_validate(pitchedDevPtr, value, extent, sizeBytes);
|
2021-03-11 12:10:49 -08:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2022-08-18 09:43:09 +00:00
|
|
|
// This is required to comply with the spec
|
|
|
|
|
// spec says hipMemset will be asynchronous when destination memory is device memory
|
|
|
|
|
// and pointer is non-offseted
|
|
|
|
|
if (isAsync == false) {
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(pitchedDevPtr.ptr, offset);
|
|
|
|
|
auto flags = memObj->getMemFlags();
|
|
|
|
|
if (offset == 0 &&
|
|
|
|
|
!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_SVM_ATOMICS | CL_MEM_SVM_FINE_GRAIN_BUFFER))) {
|
|
|
|
|
isAsync = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
2021-03-11 12:10:49 -08:00
|
|
|
std::vector<amd::Command*> commands;
|
2023-02-08 20:18:11 +00:00
|
|
|
status = ihipMemset3DCommand(commands, pitchedDevPtr, value, extent, hip_stream);
|
2021-10-19 07:54:50 -07:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-03-11 12:10:49 -08:00
|
|
|
for (auto& command : commands) {
|
2021-04-27 04:30:18 -07:00
|
|
|
command->enqueue();
|
2020-10-05 13:20:58 -04:00
|
|
|
if (!isAsync) {
|
|
|
|
|
command->awaitCompletion();
|
2020-03-31 16:15:57 -04:00
|
|
|
}
|
2020-10-05 13:20:58 -04:00
|
|
|
command->release();
|
2020-03-31 16:15:57 -04:00
|
|
|
}
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemset2D_common(void* dst, size_t pitch, int value, size_t width,
|
|
|
|
|
size_t height, hipStream_t stream=nullptr) {
|
|
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-08-18 09:43:09 +00:00
|
|
|
return ihipMemset3D({dst, pitch, width, height}, value, {width, height, 1}, stream);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemset2D_spt(void* dst, size_t pitch, int value, size_t width, size_t height) {
|
|
|
|
|
HIP_INIT_API(hipMemset2D, dst, pitch, value, width, height);
|
|
|
|
|
hipStream_t stream = getPerThreadDefaultStream();
|
|
|
|
|
HIP_RETURN(hipMemset2D_common(dst, pitch, value, width, height, stream));
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t height) {
|
|
|
|
|
HIP_INIT_API(hipMemset2D, dst, pitch, value, width, height);
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN(hipMemset2D_common(dst, pitch, value, width, height));
|
2019-10-17 14:09:46 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemset2DAsync_common(void* dst, size_t pitch, int value,
|
|
|
|
|
size_t width, size_t height, hipStream_t stream) {
|
|
|
|
|
STREAM_CAPTURE(hipMemset2DAsync, stream, dst, pitch, value, width, height);
|
|
|
|
|
|
|
|
|
|
return ihipMemset3D({dst, pitch, width, height}, value, {width, height, 1}, stream, true);
|
|
|
|
|
}
|
2022-04-13 06:35:25 +00:00
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemset2DAsync(void* dst, size_t pitch, int value,
|
|
|
|
|
size_t width, size_t height, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemset2DAsync, dst, pitch, value, width, height, stream);
|
2022-07-05 03:53:31 +00:00
|
|
|
HIP_RETURN(hipMemset2DAsync_common(dst, pitch, value, width, height, stream));
|
|
|
|
|
}
|
2019-10-17 14:09:46 -04:00
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemset2DAsync_spt(void* dst, size_t pitch, int value,
|
|
|
|
|
size_t width, size_t height, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemset2DAsync, dst, pitch, value, width, height, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipMemset2DAsync_common(dst, pitch, value, width, height, stream));
|
2019-10-17 14:09:46 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemset3D_common(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent, hipStream_t stream=nullptr) {
|
|
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-08-18 09:43:09 +00:00
|
|
|
return ihipMemset3D(pitchedDevPtr, value, extent, stream);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemset3D(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent) {
|
2020-03-23 16:31:30 -04:00
|
|
|
HIP_INIT_API(hipMemset3D, pitchedDevPtr, value, extent);
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN(hipMemset3D_common(pitchedDevPtr, value, extent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemset3D_spt(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent) {
|
|
|
|
|
HIP_INIT_API(hipMemset3D, pitchedDevPtr, value, extent);
|
|
|
|
|
hipStream_t stream = getPerThreadDefaultStream();
|
|
|
|
|
HIP_RETURN(hipMemset3D_common(pitchedDevPtr, value, extent,stream));
|
2019-10-17 14:09:46 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemset3DAsync_common(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent, hipStream_t stream) {
|
|
|
|
|
STREAM_CAPTURE(hipMemset3DAsync, stream, pitchedDevPtr, value, extent);
|
|
|
|
|
return ihipMemset3D(pitchedDevPtr, value, extent, stream, true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:09:46 -04:00
|
|
|
hipError_t hipMemset3DAsync(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent, hipStream_t stream) {
|
2020-03-23 16:31:30 -04:00
|
|
|
HIP_INIT_API(hipMemset3DAsync, pitchedDevPtr, value, extent, stream);
|
2022-07-05 03:53:31 +00:00
|
|
|
HIP_RETURN(hipMemset3DAsync_common(pitchedDevPtr, value, extent, stream));
|
|
|
|
|
}
|
2019-10-17 14:09:46 -04:00
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemset3DAsync_spt(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemset3DAsync, pitchedDevPtr, value, extent, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipMemset3DAsync_common(pitchedDevPtr, value, extent, stream));
|
2019-10-08 14:55:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemAllocPitch(hipDeviceptr_t* dptr, size_t* pitch, size_t widthInBytes,
|
|
|
|
|
size_t height, unsigned int elementSizeBytes) {
|
|
|
|
|
HIP_INIT_API(hipMemAllocPitch, dptr, pitch, widthInBytes, height, elementSizeBytes);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2022-09-05 09:47:42 +00:00
|
|
|
if (widthInBytes == 0 || height == 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-04-28 12:52:26 +00:00
|
|
|
if (elementSizeBytes != 4 && elementSizeBytes != 8 && elementSizeBytes != 16) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2019-10-08 14:55:27 -04:00
|
|
|
HIP_RETURN(hipMallocPitch(dptr, pitch, widthInBytes, height));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemAllocHost(void** ptr, size_t size) {
|
|
|
|
|
HIP_INIT_API(hipMemAllocHost, ptr, size);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(hipHostMalloc(ptr, size, 0));
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-25 19:18:53 -05:00
|
|
|
hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* dev_ptr) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipIpcGetMemHandle, handle, dev_ptr);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2020-06-23 09:28:01 -04:00
|
|
|
amd::Device* device = nullptr;
|
2019-01-25 19:18:53 -05:00
|
|
|
ihipIpcMemHandle_t* ihandle = nullptr;
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2019-01-25 19:18:53 -05:00
|
|
|
if ((handle == nullptr) || (dev_ptr == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 09:28:01 -04:00
|
|
|
device = hip::getCurrentDevice()->devices()[0];
|
2019-01-25 19:18:53 -05:00
|
|
|
ihandle = reinterpret_cast<ihipIpcMemHandle_t *>(handle);
|
2020-06-23 09:28:01 -04:00
|
|
|
|
2020-11-10 14:57:02 -05:00
|
|
|
if(!device->IpcCreate(dev_ptr, &(ihandle->psize), &(ihandle->ipc_handle), &(ihandle->poffset))) {
|
2021-02-17 23:54:39 +05:30
|
|
|
LogPrintfError("IPC memory creation failed for memory: 0x%x", dev_ptr);
|
2022-09-29 12:18:07 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2020-05-22 18:06:37 -04:00
|
|
|
}
|
2022-11-29 10:16:54 +00:00
|
|
|
ihandle->owners_process_id = amd::Os::getProcessId();
|
2019-01-25 19:18:53 -05:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-25 19:18:53 -05:00
|
|
|
hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigned int flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipIpcOpenMemHandle, dev_ptr, &handle, flags);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2019-01-25 19:18:53 -05:00
|
|
|
amd::Memory* amd_mem_obj = nullptr;
|
|
|
|
|
amd::Device* device = nullptr;
|
|
|
|
|
ihipIpcMemHandle_t* ihandle = nullptr;
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2020-10-05 16:33:32 -04:00
|
|
|
if (dev_ptr == nullptr || flags != hipIpcMemLazyEnablePeerAccess) {
|
2019-01-25 19:18:53 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Call the IPC Attach from Device class */
|
2020-02-18 12:36:12 -08:00
|
|
|
device = hip::getCurrentDevice()->devices()[0];
|
2019-01-25 19:18:53 -05:00
|
|
|
ihandle = reinterpret_cast<ihipIpcMemHandle_t *>(&handle);
|
|
|
|
|
|
2020-10-05 16:33:32 -04:00
|
|
|
if (ihandle->psize == 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 10:16:54 +00:00
|
|
|
if (ihandle->owners_process_id == amd::Os::getProcessId()) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidContext);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 14:57:02 -05:00
|
|
|
if(!device->IpcAttach(&(ihandle->ipc_handle), ihandle->psize,
|
|
|
|
|
ihandle->poffset, flags, dev_ptr)) {
|
|
|
|
|
LogPrintfError("Cannot attach ipc_handle: with ipc_size: %u"
|
|
|
|
|
"ipc_offset: %u flags: %u", ihandle->psize, flags);
|
2019-01-25 19:18:53 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidDevicePointer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-04 13:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-25 19:18:53 -05:00
|
|
|
hipError_t hipIpcCloseMemHandle(void* dev_ptr) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipIpcCloseMemHandle, dev_ptr);
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2019-01-25 19:18:53 -05:00
|
|
|
amd::Device* device = nullptr;
|
|
|
|
|
amd::Memory* amd_mem_obj = nullptr;
|
2018-04-04 13:24:15 -04:00
|
|
|
|
2019-01-25 19:18:53 -05:00
|
|
|
hip::getNullStream()->finish();
|
|
|
|
|
|
|
|
|
|
if (dev_ptr == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Call IPC Detach from Device class */
|
2020-02-18 12:36:12 -08:00
|
|
|
device = hip::getCurrentDevice()->devices()[0];
|
2019-01-25 19:18:53 -05:00
|
|
|
if (device == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorNoDevice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* detach the memory */
|
2020-06-23 09:28:01 -04:00
|
|
|
if (!device->IpcDetach(dev_ptr)){
|
2022-09-29 12:18:07 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2020-05-21 06:07:57 -04:00
|
|
|
}
|
2019-01-25 19:18:53 -05:00
|
|
|
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-04 13:50:42 +00:00
|
|
|
|
2018-04-10 17:41:24 -04:00
|
|
|
hipError_t hipHostGetDevicePointer(void** devicePointer, void* hostPointer, unsigned flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipHostGetDevicePointer, devicePointer, hostPointer, flags);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2022-04-04 13:50:42 +00:00
|
|
|
if (devicePointer == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 13:29:56 -04:00
|
|
|
size_t offset = 0;
|
|
|
|
|
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(hostPointer, offset);
|
|
|
|
|
if (!memObj) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-05-01 18:10:09 -04:00
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
*devicePointer = reinterpret_cast<void*>(memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0])->virtualAddress() + offset);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
2020-10-09 18:25:29 -04:00
|
|
|
// ================================================================================================
|
2018-04-10 17:41:24 -04:00
|
|
|
hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipPointerGetAttributes, attributes, ptr);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2020-09-01 05:49:23 -04:00
|
|
|
if (attributes == nullptr || ptr == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2018-05-23 13:40:52 -04:00
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(ptr, offset);
|
|
|
|
|
int device = 0;
|
2022-03-18 15:52:19 -04:00
|
|
|
device::Memory* devMem = nullptr;
|
2020-09-01 05:49:23 -04:00
|
|
|
memset(attributes, 0, sizeof(hipPointerAttribute_t));
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-05-23 13:40:52 -04:00
|
|
|
if (memObj != nullptr) {
|
2022-08-04 17:27:12 +05:30
|
|
|
attributes->type = ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
2020-10-09 18:25:29 -04:00
|
|
|
memObj->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice;
|
2022-08-04 17:27:12 +05:30
|
|
|
if (attributes->type == hipMemoryTypeHost) {
|
2020-11-30 03:58:00 -05:00
|
|
|
if (memObj->getHostMem() != nullptr) {
|
|
|
|
|
attributes->hostPointer = static_cast<char*>(memObj->getHostMem()) + offset;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attributes->hostPointer = static_cast<char*>(memObj->getSvmPtr()) + offset;
|
|
|
|
|
}
|
2020-09-01 05:49:23 -04:00
|
|
|
}
|
2022-03-18 15:52:19 -04:00
|
|
|
// the pointer that attribute is retrieved for might not be on the current device
|
|
|
|
|
for (const auto& device : g_devices) {
|
|
|
|
|
if(device->deviceId() == memObj->getUserData().deviceId) {
|
|
|
|
|
devMem = memObj->getDeviceMemory(*device->devices()[0]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-26 16:56:33 +05:30
|
|
|
//getDeviceMemory can fail, hence validate the sanity of the mem obtained
|
|
|
|
|
if (nullptr == devMem) {
|
|
|
|
|
DevLogPrintfError("getDeviceMemory for ptr failed : %p \n", ptr);
|
|
|
|
|
HIP_RETURN(hipErrorMemoryAllocation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attributes->devicePointer = reinterpret_cast<char*>(devMem->virtualAddress() + offset);
|
2020-10-09 18:25:29 -04:00
|
|
|
constexpr uint32_t kManagedAlloc = (CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_ALLOC_HOST_PTR);
|
|
|
|
|
attributes->isManaged =
|
|
|
|
|
((memObj->getMemFlags() & kManagedAlloc) == kManagedAlloc) ? true : false;
|
2022-04-28 23:33:36 +05:30
|
|
|
attributes->allocationFlags = memObj->getUserData().flags;
|
2021-09-08 11:01:02 -07:00
|
|
|
attributes->device = memObj->getUserData().deviceId;
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2018-05-23 13:40:52 -04:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 21:13:18 -07:00
|
|
|
LogPrintfError("Cannot get amd_mem_obj for ptr: %p \n", ptr);
|
2019-04-05 14:51:37 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2022-10-07 16:45:22 -04:00
|
|
|
// ================================================================================================
|
|
|
|
|
hipError_t ihipPointerSetAttribute(const void* value, hipPointer_attribute attribute,
|
|
|
|
|
hipDeviceptr_t ptr) {
|
|
|
|
|
if (attribute != HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(ptr, offset);
|
|
|
|
|
if (memObj == nullptr) {
|
|
|
|
|
return hipErrorInvalidDevicePointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memObj->getUserData().sync_mem_ops_
|
|
|
|
|
= static_cast<const bool>(*(reinterpret_cast<const unsigned int*>(value)));
|
|
|
|
|
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 19:08:32 +00:00
|
|
|
// ================================================================================================
|
2022-03-11 09:58:43 +00:00
|
|
|
hipError_t ihipPointerGetAttributes(void* data, hipPointer_attribute attribute,
|
|
|
|
|
hipDeviceptr_t ptr) {
|
2021-09-27 19:08:32 +00:00
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
amd::Memory* memObj = getMemoryObject(ptr, offset);
|
|
|
|
|
constexpr uint32_t kManagedAlloc = (CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_ALLOC_HOST_PTR);
|
|
|
|
|
|
|
|
|
|
hipError_t status = hipSuccess;
|
|
|
|
|
|
2022-03-11 09:58:43 +00:00
|
|
|
switch (attribute) {
|
2021-09-27 19:08:32 +00:00
|
|
|
case HIP_POINTER_ATTRIBUTE_CONTEXT : {
|
|
|
|
|
status = hipErrorNotSupported;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_MEMORY_TYPE : {
|
|
|
|
|
if (memObj) { // checks for host type or device type
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) =
|
2021-09-27 19:08:32 +00:00
|
|
|
((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) &
|
|
|
|
|
memObj->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice;
|
|
|
|
|
} else { // checks for array type
|
|
|
|
|
cl_mem dstMemObj = reinterpret_cast<cl_mem>((static_cast<hipArray*>(ptr))->data);
|
|
|
|
|
if (!is_valid(dstMemObj)) {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = 0;
|
2021-09-27 19:08:32 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
amd::Image* dstImage = as_amd(dstMemObj)->asImage();
|
|
|
|
|
if (dstImage){
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = hipMemoryTypeArray;
|
2021-09-27 19:08:32 +00:00
|
|
|
} else {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = 0;
|
2021-09-27 19:08:32 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_DEVICE_POINTER : {
|
|
|
|
|
if (memObj) {
|
|
|
|
|
device::Memory* devMem = memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]);
|
|
|
|
|
|
|
|
|
|
//getDeviceMemory can fail, hence validate the sanity of the mem obtained
|
|
|
|
|
if (nullptr == devMem) {
|
|
|
|
|
DevLogPrintfError("getDeviceMemory for ptr failed : %p \n", ptr);
|
|
|
|
|
return hipErrorMemoryAllocation;
|
|
|
|
|
}
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<hipDeviceptr_t*>(data) =
|
2021-09-27 19:08:32 +00:00
|
|
|
reinterpret_cast<hipDeviceptr_t*>(devMem->virtualAddress() + offset);
|
|
|
|
|
} else {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<hipDeviceptr_t*>(data) = nullptr;
|
2021-09-27 19:08:32 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_HOST_POINTER : {
|
|
|
|
|
if (memObj) {
|
|
|
|
|
if ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) & memObj->getMemFlags()) {
|
|
|
|
|
if (memObj->getHostMem() != nullptr) {
|
|
|
|
|
// Registered memory
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<char**>(data) =
|
2021-09-27 19:08:32 +00:00
|
|
|
static_cast<char*>(memObj->getHostMem()) + offset;
|
|
|
|
|
} else {
|
|
|
|
|
// Prepinned memory
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<char**>(data) =
|
2021-09-27 19:08:32 +00:00
|
|
|
static_cast<char*>(memObj->getSvmPtr()) + offset;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<char**>(data) = nullptr;
|
2022-02-10 20:00:12 -05:00
|
|
|
status = hipErrorInvalidValue;
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
} else { // Host Memory
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<char**>(data) = nullptr;
|
|
|
|
|
status = hipErrorInvalidValue;
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_P2P_TOKENS : {
|
|
|
|
|
// Currently not supported, deprecated in cuda as well
|
|
|
|
|
status = hipErrorNotSupported;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS : {
|
|
|
|
|
// This attribute is ideally used in hipPointerSetAttribute, defaults to true
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<bool*>(data) = true;
|
2021-09-27 19:08:32 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_BUFFER_ID : {
|
|
|
|
|
if (memObj) {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = memObj->getUniqueId();
|
2021-09-27 19:08:32 +00:00
|
|
|
} else { // ptr passed must be allocated using HIP memory allocation API
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = 0;
|
2021-09-27 19:08:32 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_IS_MANAGED : {
|
|
|
|
|
if (memObj) {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<bool*>(data) =
|
2021-09-27 19:08:32 +00:00
|
|
|
((memObj->getMemFlags() & kManagedAlloc) == kManagedAlloc) ? true : false;
|
|
|
|
|
} else {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<bool*>(data) = false;
|
2021-09-27 19:08:32 +00:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL : {
|
|
|
|
|
if (memObj) {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<int*>(data) = memObj->getUserData().deviceId;
|
2021-09-27 19:08:32 +00:00
|
|
|
} else {
|
2022-03-11 09:58:43 +00:00
|
|
|
// for host memory, -2 is returned by default similar to cuda
|
|
|
|
|
*reinterpret_cast<int*>(data) = -2;
|
|
|
|
|
status = hipErrorInvalidValue;
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_IS_LEGACY_HIP_IPC_CAPABLE : {
|
|
|
|
|
// TODO: Unclear what to be done for this attribute
|
|
|
|
|
status = hipErrorNotSupported;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_RANGE_START_ADDR : {
|
|
|
|
|
if (memObj) {
|
|
|
|
|
if (memObj->getHostMem() != nullptr) {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<hipDeviceptr_t*>(data) =
|
2021-09-27 19:08:32 +00:00
|
|
|
static_cast<char*>(memObj->getHostMem());
|
|
|
|
|
} else {
|
|
|
|
|
device::Memory* devMem =
|
|
|
|
|
memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]);
|
|
|
|
|
|
|
|
|
|
//getDeviceMemory can fail, hence validate the sanity of the mem obtained
|
|
|
|
|
if (nullptr == devMem) {
|
|
|
|
|
DevLogPrintfError("getDeviceMemory for ptr failed : %p \n", ptr);
|
|
|
|
|
return hipErrorMemoryAllocation;
|
|
|
|
|
}
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<hipDeviceptr_t*>(data) =
|
2021-09-27 19:08:32 +00:00
|
|
|
reinterpret_cast<char*>(devMem->virtualAddress());
|
|
|
|
|
}
|
2022-02-10 20:00:12 -05:00
|
|
|
} else {
|
|
|
|
|
// Input is host memory pointer, invalid for device.
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<hipDeviceptr_t*>(data) = nullptr;
|
2022-02-10 20:00:12 -05:00
|
|
|
status = hipErrorInvalidValue;
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_RANGE_SIZE : {
|
|
|
|
|
if (memObj) {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = memObj->getSize();
|
2021-09-27 19:08:32 +00:00
|
|
|
} else {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = 0;
|
|
|
|
|
status = hipErrorInvalidValue;
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_MAPPED : {
|
2022-03-11 09:58:43 +00:00
|
|
|
if (memObj) {
|
|
|
|
|
*reinterpret_cast<bool*>(data) = true;
|
|
|
|
|
} else {
|
|
|
|
|
*reinterpret_cast<bool*>(data) = false;
|
|
|
|
|
status = hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-09-27 19:08:32 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES : {
|
|
|
|
|
// hipMemAllocationHandleType is not yet supported
|
2022-03-11 09:58:43 +00:00
|
|
|
LogPrintfWarning("attribute %d is not supported.", attribute);
|
2021-09-27 19:08:32 +00:00
|
|
|
status = hipErrorNotSupported;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE : {
|
2022-03-11 09:58:43 +00:00
|
|
|
// GPUDirect RDMA API is not yet supported
|
|
|
|
|
LogPrintfWarning("attribute %d is not supported.", attribute);
|
2022-02-10 20:00:12 -05:00
|
|
|
status = hipErrorNotSupported;
|
2021-09-27 19:08:32 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_ACCESS_FLAGS : {
|
|
|
|
|
if (memObj) {
|
2022-04-28 23:33:36 +05:30
|
|
|
*reinterpret_cast<uint32_t*>(data) = memObj->getUserData().flags;
|
2021-09-27 19:08:32 +00:00
|
|
|
} else {
|
2022-03-11 09:58:43 +00:00
|
|
|
*reinterpret_cast<uint32_t*>(data) = 0;
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case HIP_POINTER_ATTRIBUTE_MEMPOOL_HANDLE : {
|
2022-03-11 09:58:43 +00:00
|
|
|
// allocations from mempool are not yet supported
|
|
|
|
|
LogPrintfWarning("attribute %d is not supported.", attribute);
|
2022-02-10 20:00:12 -05:00
|
|
|
status = hipErrorNotSupported;
|
2021-09-27 19:08:32 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
2022-03-11 09:58:43 +00:00
|
|
|
LogPrintfError("Invalid attribute: %d ", attribute);
|
2021-09-27 19:08:32 +00:00
|
|
|
status = hipErrorInvalidValue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================================================================================================
|
2022-10-07 16:45:22 -04:00
|
|
|
hipError_t hipPointerSetAttribute(const void* value, hipPointer_attribute attribute,
|
|
|
|
|
hipDeviceptr_t ptr) {
|
|
|
|
|
HIP_INIT_API(hipPointerSetAttribute, value, attribute, ptr);
|
|
|
|
|
|
|
|
|
|
if (ptr == nullptr || value == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(ihipPointerSetAttribute(value, attribute, ptr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
|
2021-09-27 19:08:32 +00:00
|
|
|
hipError_t hipPointerGetAttribute(void* data, hipPointer_attribute attribute, hipDeviceptr_t ptr) {
|
|
|
|
|
HIP_INIT_API(hipPointerGetAttribute, data, attribute, ptr);
|
|
|
|
|
|
|
|
|
|
if (ptr == nullptr || data == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 09:58:43 +00:00
|
|
|
HIP_RETURN(ihipPointerGetAttributes(data, attribute, ptr));
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
hipError_t hipDrvPointerGetAttributes(unsigned int numAttributes, hipPointer_attribute* attributes,
|
|
|
|
|
void** data, hipDeviceptr_t ptr) {
|
|
|
|
|
HIP_INIT_API(hipDrvPointerGetAttributes, numAttributes, attributes, data, ptr);
|
|
|
|
|
|
|
|
|
|
if (numAttributes == 0 || attributes == nullptr || data == nullptr || ptr == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 09:58:43 +00:00
|
|
|
// Ignore the status, hipDrvPointerGetAttributes always returns success
|
|
|
|
|
// If the ptr is invalid, the queried attributes will be assigned default values
|
|
|
|
|
for (int i = 0; i < numAttributes; ++i) {
|
|
|
|
|
hipError_t status = ihipPointerGetAttributes(data[i], attributes[i], ptr);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2021-09-27 19:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-09 18:25:29 -04:00
|
|
|
// ================================================================================================
|
2020-02-23 15:34:31 -05:00
|
|
|
hipError_t hipArrayDestroy(hipArray* array) {
|
|
|
|
|
HIP_INIT_API(hipArrayDestroy, array);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_RETURN(ihipArrayDestroy(array));
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 23:36:56 +05:30
|
|
|
hipError_t ihipArray3DGetDescriptor(HIP_ARRAY3D_DESCRIPTOR* desc,
|
|
|
|
|
hipArray* array) {
|
|
|
|
|
{
|
|
|
|
|
amd::ScopedLock lock(hip::hipArraySetLock);
|
|
|
|
|
if (hip::hipArraySet.find(array) == hip::hipArraySet.end()) {
|
|
|
|
|
return hipErrorInvalidHandle;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2022-08-17 23:36:56 +05:30
|
|
|
desc->Width = array->width;
|
|
|
|
|
desc->Height = array->height;
|
|
|
|
|
desc->Depth = array->depth;
|
|
|
|
|
desc->Format = array->Format;
|
|
|
|
|
desc->NumChannels = array->NumChannels;
|
|
|
|
|
desc->Flags = array->flags;
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2022-08-17 23:36:56 +05:30
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipArrayGetInfo(hipChannelFormatDesc* desc,
|
|
|
|
|
hipExtent* extent,
|
|
|
|
|
unsigned int* flags,
|
|
|
|
|
hipArray* array) {
|
|
|
|
|
HIP_INIT_API(hipArrayGetInfo, desc, extent, flags, array);
|
|
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
|
|
|
|
|
|
|
|
|
if (array == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If all output parameters are nullptr, then no need to proceed further
|
|
|
|
|
if ((desc == nullptr) && (extent == nullptr) && (flags == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_ARRAY3D_DESCRIPTOR array3DDescriptor;
|
|
|
|
|
hipError_t status = ihipArray3DGetDescriptor(&array3DDescriptor, array);
|
|
|
|
|
|
|
|
|
|
// Fill each output parameter
|
|
|
|
|
if (status == hipSuccess) {
|
|
|
|
|
if (desc != nullptr) {
|
|
|
|
|
*desc = hip::getChannelFormatDesc(array3DDescriptor.NumChannels, array3DDescriptor.Format);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (extent != nullptr) {
|
|
|
|
|
extent->width = array3DDescriptor.Width;
|
|
|
|
|
extent->height = array3DDescriptor.Height;
|
|
|
|
|
extent->depth = array3DDescriptor.Depth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags != nullptr) {
|
|
|
|
|
*flags = array3DDescriptor.Flags;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(status);
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipArrayGetDescriptor(HIP_ARRAY_DESCRIPTOR* pArrayDescriptor,
|
|
|
|
|
hipArray* array) {
|
|
|
|
|
HIP_INIT_API(hipArrayGetDescriptor, pArrayDescriptor, array);
|
2022-08-17 23:36:56 +05:30
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2022-08-17 23:36:56 +05:30
|
|
|
if (array == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2022-08-17 23:36:56 +05:30
|
|
|
if (pArrayDescriptor == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_ARRAY3D_DESCRIPTOR array3DDescriptor;
|
|
|
|
|
hipError_t status = ihipArray3DGetDescriptor(&array3DDescriptor, array);
|
|
|
|
|
|
|
|
|
|
// Fill each output parameter
|
|
|
|
|
if (status == hipSuccess) {
|
|
|
|
|
pArrayDescriptor->Width = array3DDescriptor.Width;
|
|
|
|
|
pArrayDescriptor->Height = array3DDescriptor.Height;
|
|
|
|
|
pArrayDescriptor->Format = array3DDescriptor.Format;
|
|
|
|
|
pArrayDescriptor->NumChannels = array3DDescriptor.NumChannels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipArray3DGetDescriptor(HIP_ARRAY3D_DESCRIPTOR* pArrayDescriptor,
|
|
|
|
|
hipArray* array) {
|
|
|
|
|
HIP_INIT_API(hipArray3DGetDescriptor, pArrayDescriptor, array);
|
|
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
|
|
|
|
|
|
|
|
|
if (array == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pArrayDescriptor == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(ihipArray3DGetDescriptor(pArrayDescriptor, array));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyParam2DAsync(const hip_Memcpy2D* pCopy,
|
|
|
|
|
hipStream_t stream) {
|
2020-05-14 03:50:34 -05:00
|
|
|
HIP_INIT_API(hipMemcpyParam2DAsync, pCopy);
|
2021-10-28 12:01:26 -07:00
|
|
|
STREAM_CAPTURE(hipMemcpyParam2DAsync, stream, pCopy);
|
2020-02-23 15:34:31 -05:00
|
|
|
HIP_RETURN(ihipMemcpyParam2D(pCopy, stream, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipMemcpy2DArrayToArray(hipArray_t dst, size_t wOffsetDst, size_t hOffsetDst, hipArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream, bool isAsync = false) {
|
|
|
|
|
hip_Memcpy2D desc = {};
|
|
|
|
|
|
|
|
|
|
desc.srcXInBytes = wOffsetSrc;
|
|
|
|
|
desc.srcY = hOffsetSrc;
|
|
|
|
|
desc.srcMemoryType = hipMemoryTypeArray;
|
|
|
|
|
desc.srcHost = nullptr;
|
|
|
|
|
desc.srcDevice = nullptr;
|
|
|
|
|
desc.srcArray = const_cast<hipArray_t>(src);
|
|
|
|
|
desc.srcPitch = 0; // Ignored.
|
|
|
|
|
|
|
|
|
|
desc.dstXInBytes = wOffsetDst;
|
|
|
|
|
desc.dstY = hOffsetDst;
|
|
|
|
|
desc.dstMemoryType = hipMemoryTypeArray;
|
|
|
|
|
desc.dstHost = nullptr;
|
|
|
|
|
desc.dstDevice = nullptr;
|
|
|
|
|
desc.dstArray = dst;
|
|
|
|
|
desc.dstPitch = 0; // Ignored.
|
|
|
|
|
|
|
|
|
|
desc.WidthInBytes = width;
|
|
|
|
|
desc.Height = height;
|
|
|
|
|
|
|
|
|
|
return ihipMemcpyParam2D(&desc, stream, isAsync);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpy2DArrayToArray(hipArray_t dst, size_t wOffsetDst, size_t hOffsetDst, hipArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t height, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DArrayToArray, dst, wOffsetDst, hOffsetDst, src, wOffsetSrc, hOffsetSrc, width, height, kind);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-12-17 12:23:06 -05:00
|
|
|
hipError_t validateParam = hipSuccess, validateSrc = hipSuccess, validateDst = hipSuccess;
|
|
|
|
|
if ((validateParam = hipMemcpy2DValidateParams(kind)) != hipSuccess) {
|
|
|
|
|
HIP_RETURN(validateParam);
|
|
|
|
|
}
|
|
|
|
|
if ((validateSrc = hipMemcpy2DValidateArray(src, wOffsetSrc, hOffsetSrc, width, height)) != hipSuccess) {
|
|
|
|
|
HIP_RETURN(validateSrc);
|
|
|
|
|
}
|
|
|
|
|
if ((validateDst = hipMemcpy2DValidateArray(dst, wOffsetDst, hOffsetDst, width, height)) != hipSuccess) {
|
|
|
|
|
HIP_RETURN(validateDst);
|
|
|
|
|
}
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy2DArrayToArray(dst, wOffsetDst, hOffsetDst, src, wOffsetSrc, hOffsetSrc, width, height, kind, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyArrayToArray(hipArray_t dst, size_t wOffsetDst, size_t hOffsetDst, hipArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t height, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyArrayToArray, dst, wOffsetDst, hOffsetDst, src, wOffsetSrc, hOffsetSrc, width, height, kind);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy2DArrayToArray(dst, wOffsetDst, hOffsetDst, src, wOffsetSrc, hOffsetSrc, width, height, kind, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpy2DFromArray_common(void* dst, size_t dpitch, hipArray_const_t src,
|
|
|
|
|
size_t wOffsetSrc, size_t hOffset, size_t width,
|
2022-12-17 12:23:06 -05:00
|
|
|
size_t height, hipMemcpyKind kind, hipStream_t stream=nullptr,
|
|
|
|
|
bool isAsync=false) {
|
|
|
|
|
|
2023-01-13 18:00:52 -05:00
|
|
|
hipError_t validateParam = hipSuccess, validateSrc = hipSuccess, validateDst = hipSuccess;
|
2022-12-17 12:23:06 -05:00
|
|
|
if ((validateParam = hipMemcpy2DValidateParams(kind,stream)) != hipSuccess) {
|
|
|
|
|
return validateParam;
|
2022-11-23 21:15:35 +00:00
|
|
|
}
|
2022-12-17 12:23:06 -05:00
|
|
|
if ((validateSrc = hipMemcpy2DValidateArray(src,wOffsetSrc, hOffset, width, height)) != hipSuccess) {
|
|
|
|
|
return validateSrc;
|
2022-11-23 21:15:35 +00:00
|
|
|
}
|
2022-12-17 12:23:06 -05:00
|
|
|
if ((validateDst = hipMemcpy2DValidateBuffer(dst,dpitch,width)) != hipSuccess) {
|
|
|
|
|
return validateDst;
|
2022-11-23 21:15:35 +00:00
|
|
|
}
|
2022-12-17 12:23:06 -05:00
|
|
|
return ihipMemcpy2DFromArray(dst, dpitch, src, wOffsetSrc, hOffset, width, height, kind, stream, isAsync);
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-17 12:23:06 -05:00
|
|
|
hipError_t hipMemcpy2DFromArray(void* dst, size_t dpitch,hipArray_const_t src, size_t wOffsetSrc, size_t hOffset, size_t width, size_t height, hipMemcpyKind kind) {
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_INIT_API(hipMemcpy2DFromArray, dst, dpitch, src, wOffsetSrc, hOffset, width, height, kind);
|
2022-12-17 12:23:06 -05:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DFromArray_common(dst, dpitch, src, wOffsetSrc, hOffset, width, height, kind));
|
|
|
|
|
}
|
2021-03-08 07:48:24 -08:00
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipMemcpy2DFromArray_spt(void* dst, size_t dpitch, hipArray_const_t src, size_t wOffsetSrc, size_t hOffset, size_t width, size_t height, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DFromArray, dst, dpitch, src, wOffsetSrc, hOffset, width, height, kind);
|
|
|
|
|
hipStream_t stream = getPerThreadDefaultStream();
|
2022-12-17 12:23:06 -05:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2022-04-13 06:35:25 +00:00
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DFromArray_common(dst, dpitch, src, wOffsetSrc, hOffset, width, height, kind, stream));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpy2DFromArrayAsync(void* dst, size_t dpitch, hipArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DFromArrayAsync, dst, dpitch, src, wOffsetSrc, hOffsetSrc, width, height, kind, stream);
|
2022-12-17 12:23:06 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpy2DFromArrayAsync, stream, dst, dpitch, src, wOffsetSrc, hOffsetSrc, width,
|
|
|
|
|
height, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DFromArray_common(dst, dpitch, src, wOffsetSrc, hOffsetSrc, width, height, kind, stream, true));
|
2022-07-05 03:53:31 +00:00
|
|
|
}
|
2021-03-08 07:48:24 -08:00
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpy2DFromArrayAsync_spt(void* dst, size_t dpitch, hipArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DFromArrayAsync, dst, dpitch, src, wOffsetSrc, hOffsetSrc, width, height, kind, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
2022-12-17 12:23:06 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpy2DFromArrayAsync, stream, dst, dpitch, src, wOffsetSrc, hOffsetSrc, width,
|
|
|
|
|
height, kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DFromArray_common(dst, dpitch, src, wOffsetSrc, hOffsetSrc, width, height, kind, stream, true));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyFromArrayAsync(void* dst, hipArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t count, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyFromArrayAsync, dst, src, wOffsetSrc, hOffsetSrc, count, kind, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
STREAM_CAPTURE(hipMemcpyFromArrayAsync, stream, dst, src, wOffsetSrc, hOffsetSrc, count, kind);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
|
|
|
|
if (src == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const size_t arrayHeight = (src->height != 0) ? src->height : 1;
|
|
|
|
|
const size_t widthInBytes = count / arrayHeight;
|
|
|
|
|
|
2020-03-27 13:47:44 -04:00
|
|
|
const size_t height = (count / src->width) / hip::getElementSize(src);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy2DFromArray(dst, 0 /* dpitch */, src, wOffsetSrc, hOffsetSrc, widthInBytes, height, kind, stream, true));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpy2DToArrayAsync(hipArray* dst, size_t wOffset, size_t hOffset, const void* src, size_t spitch, size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DToArrayAsync, dst, wOffset, hOffset, src, spitch, width, height, kind, stream);
|
2022-12-17 12:23:06 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpy2DToArrayAsync, stream, dst, wOffset, hOffset, src, spitch, width, height,
|
|
|
|
|
kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DToArray_common(dst, wOffset, hOffset, src, spitch, width, height, kind, stream, true));
|
2022-07-05 03:53:31 +00:00
|
|
|
}
|
2021-03-18 11:25:55 +00:00
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipMemcpy2DToArrayAsync_spt(hipArray* dst, size_t wOffset, size_t hOffset, const void* src, size_t spitch, size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpy2DToArrayAsync, dst, wOffset, hOffset, src, spitch, width, height, kind, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
2022-12-17 12:23:06 -05:00
|
|
|
STREAM_CAPTURE(hipMemcpy2DToArrayAsync, stream, dst, wOffset, hOffset, src, spitch, width, height,
|
|
|
|
|
kind);
|
|
|
|
|
HIP_RETURN_DURATION(hipMemcpy2DToArray_common(dst, wOffset, hOffset, src, spitch, width, height, kind, stream, true));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyToArrayAsync(hipArray_t dst, size_t wOffset, size_t hOffset, const void* src, size_t count, hipMemcpyKind kind, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyToArrayAsync, dst, wOffset, hOffset, src, count, kind);
|
2021-10-28 12:01:26 -07:00
|
|
|
STREAM_CAPTURE(hipMemcpyToArrayAsync, stream, dst, wOffset, hOffset, src, count, kind);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
|
|
|
|
if (dst == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const size_t arrayHeight = (dst->height != 0) ? dst->height : 1;
|
|
|
|
|
const size_t widthInBytes = count / arrayHeight;
|
|
|
|
|
|
2020-03-27 13:47:44 -04:00
|
|
|
const size_t height = (count / dst->width) / hip::getElementSize(dst);
|
2020-02-23 15:34:31 -05:00
|
|
|
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpy2DToArray(dst, wOffset, hOffset, src, 0 /* spitch */, widthInBytes, height, kind, stream, true));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyAtoA(hipArray* dstArray,
|
|
|
|
|
size_t dstOffset,
|
|
|
|
|
hipArray* srcArray,
|
|
|
|
|
size_t srcOffset,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyAtoA, dstArray, dstOffset, srcArray, srcOffset, ByteCount);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyAtoA(srcArray, dstArray, {srcOffset, 0, 0}, {dstOffset, 0, 0}, {ByteCount, 1, 1}, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyAtoD(hipDeviceptr_t dstDevice,
|
|
|
|
|
hipArray* srcArray,
|
|
|
|
|
size_t srcOffset,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyAtoD, dstDevice, srcArray, srcOffset, ByteCount);
|
|
|
|
|
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyAtoD(srcArray, dstDevice, {srcOffset, 0, 0}, {0, 0, 0}, {ByteCount, 1, 1}, 0, 0, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyAtoHAsync(void* dstHost,
|
|
|
|
|
hipArray* srcArray,
|
|
|
|
|
size_t srcOffset,
|
|
|
|
|
size_t ByteCount,
|
|
|
|
|
hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyAtoHAsync, dstHost, srcArray, srcOffset, ByteCount, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
STREAM_CAPTURE(hipMemcpyAtoHAsync, stream, dstHost, srcArray, srcOffset, ByteCount);
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyAtoH(srcArray, dstHost, {srcOffset, 0, 0}, {0, 0, 0}, {ByteCount, 1, 1}, 0, 0, stream, true));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyDtoA(hipArray* dstArray,
|
|
|
|
|
size_t dstOffset,
|
|
|
|
|
hipDeviceptr_t srcDevice,
|
|
|
|
|
size_t ByteCount) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyDtoA, dstArray, dstOffset, srcDevice, ByteCount);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURING();
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyDtoA(srcDevice, dstArray, {0, 0, 0}, {dstOffset, 0, 0}, {ByteCount, 1, 1}, 0, 0, nullptr));
|
2020-02-23 15:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMemcpyHtoAAsync(hipArray* dstArray,
|
|
|
|
|
size_t dstOffset,
|
|
|
|
|
const void* srcHost,
|
|
|
|
|
size_t ByteCount,
|
|
|
|
|
hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipMemcpyHtoAAsync, dstArray, dstOffset, srcHost, ByteCount, stream);
|
2021-10-28 12:01:26 -07:00
|
|
|
STREAM_CAPTURE(hipMemcpyHtoAAsync, stream, dstArray, dstOffset, srcHost, ByteCount);
|
2020-07-28 09:37:10 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMemcpyHtoA(srcHost, dstArray, {0, 0, 0}, {dstOffset, 0, 0}, {ByteCount, 1, 1}, 0, 0, stream, true));
|
2020-02-26 08:41:18 -08:00
|
|
|
}
|
2020-03-23 16:26:21 -04:00
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
hipError_t hipMallocHost(void** ptr,
|
|
|
|
|
size_t size) {
|
|
|
|
|
HIP_INIT_API(hipMallocHost, ptr, size);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2021-03-22 15:52:46 -04:00
|
|
|
HIP_RETURN_DURATION(ihipMalloc(ptr, size, CL_MEM_SVM_FINE_GRAIN_BUFFER), (ptr != nullptr)? *ptr : nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipFreeHost(void *ptr) {
|
|
|
|
|
HIP_INIT_API(hipFreeHost, ptr);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2021-03-22 15:52:46 -04:00
|
|
|
HIP_RETURN(ihipFree(ptr));
|
|
|
|
|
}
|
2020-03-23 16:26:21 -04:00
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
hipError_t hipDrvMemcpy2DUnaligned(const hip_Memcpy2D* pCopy) {
|
|
|
|
|
HIP_INIT_API(hipDrvMemcpy2DUnaligned, pCopy);
|
|
|
|
|
|
|
|
|
|
HIP_MEMCPY3D desc = hip::getDrvMemcpy3DDesc(*pCopy);
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(ihipMemcpyParam3D(&desc, nullptr));
|
2020-03-23 16:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
hipError_t ihipMipmapArrayCreate(hipMipmappedArray_t* mipmapped_array_pptr,
|
|
|
|
|
HIP_ARRAY3D_DESCRIPTOR* mipmapped_array_desc_ptr,
|
|
|
|
|
unsigned int num_mipmap_levels) {
|
2023-02-27 17:07:05 +00:00
|
|
|
bool mipMapSupport = true;
|
|
|
|
|
amd::Context& context = *hip::getCurrentDevice()->asContext();
|
|
|
|
|
const std::vector<amd::Device*>& devices = context.devices();
|
|
|
|
|
for (auto& dev : devices) {
|
|
|
|
|
if (!dev->settings().checkExtension(ClKhrMipMapImage)) {
|
|
|
|
|
mipMapSupport = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mipMapSupport == false) {
|
|
|
|
|
LogPrintfError("Mipmap not supported on one of the devices, Mip Level: %d", num_mipmap_levels);
|
|
|
|
|
return hipErrorNotSupported;
|
|
|
|
|
}
|
2021-03-22 15:52:46 -04:00
|
|
|
const cl_channel_order channel_order = hip::getCLChannelOrder(
|
|
|
|
|
mipmapped_array_desc_ptr->NumChannels, 0);
|
|
|
|
|
const cl_channel_type channel_type = hip::getCLChannelType(mipmapped_array_desc_ptr->Format,
|
|
|
|
|
hipReadModeElementType);
|
|
|
|
|
const cl_mem_object_type image_type = hip::getCLMemObjectType(mipmapped_array_desc_ptr->Width,
|
|
|
|
|
mipmapped_array_desc_ptr->Height,
|
|
|
|
|
mipmapped_array_desc_ptr->Depth,
|
|
|
|
|
mipmapped_array_desc_ptr->Flags);
|
2022-06-27 23:35:19 +05:30
|
|
|
hipError_t status = hipSuccess;
|
2021-03-22 15:52:46 -04:00
|
|
|
// Create a new amd::Image with mipmap
|
|
|
|
|
amd::Image* image = ihipImageCreate(channel_order,
|
|
|
|
|
channel_type,
|
|
|
|
|
image_type,
|
|
|
|
|
mipmapped_array_desc_ptr->Width,
|
|
|
|
|
mipmapped_array_desc_ptr->Height,
|
|
|
|
|
mipmapped_array_desc_ptr->Depth,
|
|
|
|
|
mipmapped_array_desc_ptr->Depth,
|
|
|
|
|
0 /* row pitch */,
|
|
|
|
|
0 /* slice pitch */,
|
|
|
|
|
num_mipmap_levels,
|
2022-06-27 23:35:19 +05:30
|
|
|
nullptr, /* buffer */
|
|
|
|
|
status);
|
2020-03-27 14:02:46 -04:00
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
if (image == nullptr) {
|
2022-06-27 23:35:19 +05:30
|
|
|
return status;
|
2021-03-22 15:52:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_mem cl_mem_obj = as_cl<amd::Memory>(image);
|
|
|
|
|
*mipmapped_array_pptr = new hipMipmappedArray();
|
|
|
|
|
(*mipmapped_array_pptr)->data = reinterpret_cast<void*>(cl_mem_obj);
|
|
|
|
|
|
|
|
|
|
(*mipmapped_array_pptr)->desc = hip::getChannelFormatDesc(
|
|
|
|
|
mipmapped_array_desc_ptr->NumChannels,
|
|
|
|
|
mipmapped_array_desc_ptr->Format);
|
|
|
|
|
(*mipmapped_array_pptr)->type = image_type;
|
|
|
|
|
(*mipmapped_array_pptr)->width = mipmapped_array_desc_ptr->Width;
|
|
|
|
|
(*mipmapped_array_pptr)->height = mipmapped_array_desc_ptr->Height;
|
|
|
|
|
(*mipmapped_array_pptr)->depth = mipmapped_array_desc_ptr->Depth;
|
|
|
|
|
(*mipmapped_array_pptr)->min_mipmap_level = 0;
|
|
|
|
|
(*mipmapped_array_pptr)->max_mipmap_level = num_mipmap_levels;
|
|
|
|
|
(*mipmapped_array_pptr)->flags = mipmapped_array_desc_ptr->Flags;
|
|
|
|
|
(*mipmapped_array_pptr)->format = mipmapped_array_desc_ptr->Format;
|
2023-06-01 18:31:48 -04:00
|
|
|
(*mipmapped_array_pptr)->num_channels = mipmapped_array_desc_ptr->NumChannels;
|
2021-03-22 15:52:46 -04:00
|
|
|
|
|
|
|
|
return hipSuccess;
|
2020-03-27 15:19:56 -04:00
|
|
|
}
|
2020-04-03 12:34:59 -04:00
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
hipError_t ihipMipmappedArrayDestroy(hipMipmappedArray_t mipmapped_array_ptr) {
|
|
|
|
|
if (mipmapped_array_ptr == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_mem mem_obj = reinterpret_cast<cl_mem>(mipmapped_array_ptr->data);
|
|
|
|
|
if (is_valid(mem_obj) == false) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 19:14:15 -04:00
|
|
|
auto image = as_amd(mem_obj);
|
|
|
|
|
// Wait on the device, associated with the current memory object during allocation
|
|
|
|
|
hip::Stream::SyncAllStreams(image->getUserData().deviceId);
|
|
|
|
|
image->release();
|
2021-03-22 15:52:46 -04:00
|
|
|
|
|
|
|
|
delete mipmapped_array_ptr;
|
|
|
|
|
return hipSuccess;
|
2020-04-03 12:34:59 -04:00
|
|
|
}
|
2021-02-26 09:57:36 -05:00
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
hipError_t ihipMipmappedArrayGetLevel(hipArray_t* level_array_pptr,
|
|
|
|
|
hipMipmappedArray_t mipmapped_array_ptr,
|
|
|
|
|
unsigned int mip_level) {
|
2021-02-26 09:57:36 -05:00
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
if (level_array_pptr == nullptr || mipmapped_array_ptr == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-02-26 09:57:36 -05:00
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
// Convert the raw data to amd::Image
|
|
|
|
|
cl_mem cl_mem_obj = reinterpret_cast<cl_mem>(mipmapped_array_ptr->data);
|
|
|
|
|
if (is_valid(cl_mem_obj) == false) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
amd::Image* image = as_amd(cl_mem_obj)->asImage();
|
|
|
|
|
if (image == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create new hip Array parameter and create an image view with new mip level.
|
|
|
|
|
(*level_array_pptr) = new hipArray();
|
|
|
|
|
(*level_array_pptr)->data = as_cl<amd::Memory>(image->createView(image->getContext(),
|
|
|
|
|
image->getImageFormat(),
|
|
|
|
|
NULL, mip_level, 0));
|
|
|
|
|
|
|
|
|
|
// Copy the new width, height & depth details of the flag to hipArray.
|
|
|
|
|
cl_mem cl_mip_mem_obj = reinterpret_cast<cl_mem>((*level_array_pptr)->data);
|
|
|
|
|
if (is_valid(cl_mem_obj) == false) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fill the hip_array info from newly created amd::Image's view
|
|
|
|
|
amd::Image* mipmap_image = as_amd(cl_mip_mem_obj)->asImage();
|
|
|
|
|
(*level_array_pptr)->width = mipmap_image->getWidth();
|
|
|
|
|
(*level_array_pptr)->height = mipmap_image->getHeight();
|
|
|
|
|
(*level_array_pptr)->depth = mipmap_image->getDepth();
|
|
|
|
|
|
|
|
|
|
const cl_mem_object_type image_type = hip::getCLMemObjectType((*level_array_pptr)->width,
|
|
|
|
|
(*level_array_pptr)->height,
|
|
|
|
|
(*level_array_pptr)->depth,
|
|
|
|
|
mipmapped_array_ptr->flags);
|
|
|
|
|
(*level_array_pptr)->type = image_type;
|
|
|
|
|
(*level_array_pptr)->Format = mipmapped_array_ptr->format;
|
|
|
|
|
(*level_array_pptr)->desc = mipmapped_array_ptr->desc;
|
|
|
|
|
(*level_array_pptr)->NumChannels = hip::getNumChannels((*level_array_pptr)->desc);
|
|
|
|
|
(*level_array_pptr)->isDrv = 0;
|
|
|
|
|
(*level_array_pptr)->textureType = 0;
|
|
|
|
|
|
2023-06-01 18:31:48 -04:00
|
|
|
amd::ScopedLock lock(hip::hipArraySetLock);
|
|
|
|
|
hip::hipArraySet.insert(*level_array_pptr);
|
|
|
|
|
|
2021-03-22 15:52:46 -04:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMipmappedArrayCreate(hipMipmappedArray_t* mipmapped_array_pptr,
|
|
|
|
|
HIP_ARRAY3D_DESCRIPTOR* mipmapped_array_desc_ptr,
|
|
|
|
|
unsigned int num_mipmap_levels) {
|
|
|
|
|
HIP_INIT_API(hipMipmappedArrayCreate, mipmapped_array_pptr, mipmapped_array_desc_ptr,
|
|
|
|
|
num_mipmap_levels);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2021-03-22 15:52:46 -04:00
|
|
|
HIP_RETURN(ihipMipmapArrayCreate(mipmapped_array_pptr, mipmapped_array_desc_ptr,
|
|
|
|
|
num_mipmap_levels));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMipmappedArrayDestroy(hipMipmappedArray_t mipmapped_array_ptr) {
|
|
|
|
|
HIP_INIT_API(hipMipmappedArrayDestroy, mipmapped_array_ptr);
|
2021-10-28 12:01:26 -07:00
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
2021-03-22 15:52:46 -04:00
|
|
|
HIP_RETURN(ihipMipmappedArrayDestroy(mipmapped_array_ptr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipMipmappedArrayGetLevel(hipArray_t* level_array_pptr,
|
|
|
|
|
hipMipmappedArray_t mipmapped_array_ptr,
|
|
|
|
|
unsigned int mip_level) {
|
|
|
|
|
HIP_INIT_API(hipMipmappedArrayGetLevel, level_array_pptr, mipmapped_array_ptr, mip_level);
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(ihipMipmappedArrayGetLevel(level_array_pptr, mipmapped_array_ptr, mip_level));
|
2021-02-26 09:57:36 -05:00
|
|
|
}
|
|
|
|
|
|
2023-06-01 18:31:48 -04:00
|
|
|
hipError_t hipMallocMipmappedArray(hipMipmappedArray_t *mipmappedArray,
|
|
|
|
|
const hipChannelFormatDesc* desc,
|
|
|
|
|
hipExtent extent,
|
|
|
|
|
unsigned int numLevels,
|
|
|
|
|
unsigned int flags) {
|
|
|
|
|
HIP_INIT_API(hipMallocMipmappedArray, mipmappedArray, desc, extent, numLevels, flags);
|
|
|
|
|
if (mipmappedArray == nullptr || desc == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
|
|
|
|
HIP_ARRAY3D_DESCRIPTOR allocateArray = {extent.width,
|
|
|
|
|
extent.height,
|
|
|
|
|
extent.depth,
|
|
|
|
|
hip::getArrayFormat(*desc),
|
|
|
|
|
hip::getNumChannels(*desc),
|
|
|
|
|
flags};
|
|
|
|
|
if(!hip::CheckArrayFormat(*desc)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(ihipMipmapArrayCreate(mipmappedArray, &allocateArray, numLevels));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipFreeMipmappedArray(hipMipmappedArray_t mipmappedArray) {
|
|
|
|
|
HIP_INIT_API(hipFreeMipmappedArray, mipmappedArray);
|
|
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
|
|
|
|
HIP_RETURN(ihipMipmappedArrayDestroy(mipmappedArray));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGetMipmappedArrayLevel(hipArray_t *levelArray,
|
|
|
|
|
hipMipmappedArray_const_t mipmappedArray,
|
|
|
|
|
unsigned int level) {
|
|
|
|
|
HIP_INIT_API(hipGetMipmappedArrayLevel, levelArray, mipmappedArray, level);
|
|
|
|
|
CHECK_STREAM_CAPTURE_SUPPORTED();
|
|
|
|
|
HIP_RETURN(ihipMipmappedArrayGetLevel(levelArray,
|
|
|
|
|
const_cast<hipMipmappedArray_t>(mipmappedArray),
|
|
|
|
|
level));
|
|
|
|
|
}
|