SWDEV-316128 - HIP surface API support

Change-Id: I7b5ef4769efb07188915a68caeb4d35360c7aa95


[ROCm/clr commit: 40a6ec42a5]
Esse commit está contido em:
haoyuan2
2022-01-07 15:15:59 -08:00
commit de Hao Yuan
commit 94ea419da7
+62 -2
Ver Arquivo
@@ -23,15 +23,75 @@
#include "hip_internal.hpp"
#include <hip/surface_types.h>
hipError_t ihipFree(void* ptr);
struct __hip_surface {
uint32_t imageSRD[HIP_IMAGE_OBJECT_SIZE_DWORD];
amd::Image* image;
hipResourceDesc resDesc;
__hip_surface(amd::Image* image_, const hipResourceDesc& resDesc_)
: image(image_), resDesc(resDesc_) {
amd::Context& context = *hip::getCurrentDevice()->asContext();
amd::Device& device = *context.devices()[0];
device::Memory* imageMem = image->getDeviceMemory(device);
std::memcpy(imageSRD, imageMem->cpuSrd(), sizeof(imageSRD));
}
};
hipError_t ihipCreateSurfaceObject(hipSurfaceObject_t* pSurfObject,
const hipResourceDesc* pResDesc) {
amd::Device* device = hip::getCurrentDevice()->devices()[0];
const device::Info& info = device->info();
// Validate input params
if (pSurfObject == nullptr || pResDesc == nullptr) {
return hipErrorInvalidValue;
}
// the type of resource must be a HIP array
// hipResourceDesc::res::array::array must be set to a valid HIP array handle.
if ((pResDesc->resType != hipResourceTypeArray) || (pResDesc->res.array.array == nullptr)) {
return hipErrorInvalidValue;
}
amd::Image* image = nullptr;
cl_mem memObj = reinterpret_cast<cl_mem>(pResDesc->res.array.array->data);
if (!is_valid(memObj)) {
return hipErrorInvalidValue;
}
image = as_amd(memObj)->asImage();
void* surfObjectBuffer = nullptr;
ihipMalloc(&surfObjectBuffer, sizeof(__hip_surface), CL_MEM_SVM_FINE_GRAIN_BUFFER);
if (surfObjectBuffer == nullptr) {
return hipErrorOutOfMemory;
}
*pSurfObject = new (surfObjectBuffer) __hip_surface{image, *pResDesc};
return hipSuccess;
}
hipError_t hipCreateSurfaceObject(hipSurfaceObject_t* pSurfObject,
const hipResourceDesc* pResDesc) {
HIP_INIT_API(hipCreateSurfaceObject, pSurfObject, pResDesc);
HIP_RETURN(hipErrorNotSupported);
HIP_RETURN(ihipCreateSurfaceObject(pSurfObject, pResDesc));
}
hipError_t ihipDestroySurfaceObject(hipSurfaceObject_t surfaceObject) {
HIP_INIT_API(hipDestroySurfaceObject, surfaceObject);
if (surfaceObject == nullptr) {
return hipSuccess;
}
return ihipFree(surfaceObject);
}
hipError_t hipDestroySurfaceObject(hipSurfaceObject_t surfaceObject) {
HIP_INIT_API(hipDestroySurfaceObject, surfaceObject);
HIP_RETURN(hipErrorNotSupported);
HIP_RETURN(ihipDestroySurfaceObject(surfaceObject));
}