From 68e33fdf84e1371aeb96fb244ccf4dff3ae9905e Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 16 Apr 2018 18:37:17 -0400
Subject: [PATCH] P4 to Git Change 1541938 by cpaquot@cpaquot-ocl-lc-lnx on
2018/04/16 18:27:17
SWDEV-145570 - [HIP] Set/GetDevice and Create/DestroyTextureObject
Implemented Set/GetDevice relying on g_context (current context)
Implemented create linear/2D texture object function
Implemented hipDestroyTextureObject
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#4 edit
[ROCm/hip commit: 250e08f31fa2f036070c9f51b486ab2675a0b8ad]
---
projects/hip/api/hip/hip_device_runtime.cpp | 17 ++-
projects/hip/api/hip/hip_texture.cpp | 118 +++++++++++++++++++-
2 files changed, 126 insertions(+), 9 deletions(-)
diff --git a/projects/hip/api/hip/hip_device_runtime.cpp b/projects/hip/api/hip/hip_device_runtime.cpp
index 7c5c063ea6..d0d9c1145b 100644
--- a/projects/hip/api/hip/hip_device_runtime.cpp
+++ b/projects/hip/api/hip/hip_device_runtime.cpp
@@ -382,13 +382,17 @@ hipError_t hipGetDevice ( int* deviceId ) {
HIP_INIT_API(deviceId);
if (deviceId != nullptr) {
- // this needs to return default device. For now return 0 always
- *deviceId = 0;
+ for (unsigned int i = 0; i < g_devices.size(); i++) {
+ if (g_devices[i] == g_context) {
+ *deviceId = i;
+ return hipSuccess;
+ }
+ }
} else {
return hipErrorInvalidValue;
}
- return hipSuccess;
+ return hipErrorUnknown;
}
hipError_t hipGetDeviceCount ( int* count ) {
@@ -420,9 +424,12 @@ hipError_t hipIpcOpenEventHandle ( hipEvent_t* event, hipIpcEventHandle_t handle
hipError_t hipSetDevice ( int device ) {
HIP_INIT_API(device);
- assert(0 && "Unimplemented");
+ if (static_cast(device) < g_devices.size()) {
+ g_context = g_devices[device];
- return hipErrorUnknown;
+ return hipSuccess;
+ }
+ return hipErrorInvalidValue;
}
hipError_t hipSetDeviceFlags ( unsigned int flags ) {
diff --git a/projects/hip/api/hip/hip_texture.cpp b/projects/hip/api/hip/hip_texture.cpp
index 59adad761a..715c39eb97 100644
--- a/projects/hip/api/hip/hip_texture.cpp
+++ b/projects/hip/api/hip/hip_texture.cpp
@@ -24,13 +24,123 @@ THE SOFTWARE.
#include
#include "hip_internal.hpp"
+void getChannelOrderAndType(const hipChannelFormatDesc& desc, enum hipTextureReadMode readMode,
+ cl_channel_order* channelOrder, cl_channel_type* channelType) {
+ if (desc.x != 0 && desc.y != 0 && desc.z != 0 && desc.w != 0) {
+ *channelOrder = CL_RGBA;
+ } else if (desc.x != 0 && desc.y != 0 && desc.z != 0 && desc.w == 0) {
+ *channelOrder = CL_RGB;
+ } else if (desc.x != 0 && desc.y != 0 && desc.z == 0 && desc.w == 0) {
+ *channelOrder = CL_RG;
+ } else if (desc.x != 0 && desc.y == 0 && desc.z == 0 && desc.w == 0) {
+ *channelOrder = CL_R;
+ } else {
+ }
+
+ switch (desc.f) {
+ case hipChannelFormatKindUnsigned:
+ switch (desc.x) {
+ case 32:
+ *channelType = CL_UNSIGNED_INT32;
+ break;
+ case 16:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_UNORM_INT16
+ : CL_UNSIGNED_INT16;
+ break;
+ case 8:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_UNORM_INT8
+ : CL_UNSIGNED_INT8;
+ break;
+ default:
+ *channelType = CL_UNSIGNED_INT32;
+ }
+ break;
+ case hipChannelFormatKindSigned:
+ switch (desc.x) {
+ case 32:
+ *channelType = CL_SIGNED_INT32;
+ break;
+ case 16:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_SNORM_INT16
+ : CL_SIGNED_INT16;
+ break;
+ case 8:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_SNORM_INT8
+ : CL_SIGNED_INT8;
+ break;
+ default:
+ *channelType = CL_SIGNED_INT32;
+ }
+ break;
+ case hipChannelFormatKindFloat:
+ switch (desc.x) {
+ case 32:
+ *channelType = CL_FLOAT;
+ break;
+ case 16:
+ *channelType = CL_HALF_FLOAT;
+ break;
+ case 8:
+ break;
+ default:
+ *channelType = CL_FLOAT;
+ }
+ break;
+ case hipChannelFormatKindNone:
+ default:
+ break;
+ }
+}
hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResourceDesc* pResDesc,
const hipTextureDesc* pTexDesc,
const hipResourceViewDesc* pResViewDesc) {
HIP_INIT_API(pTexObject, pResDesc, pTexDesc, pResViewDesc);
- assert(0 && "Unimplemented");
+ if (!g_context->devices()[0]->info().imageSupport_) {
+ return hipErrorInvalidValue;
+ }
+
+ amd::Image* image = nullptr;
+
+ cl_image_format image_format;
+ getChannelOrderAndType(pResDesc->res.pitch2D.desc, pTexDesc->readMode,
+ &image_format.image_channel_order, &image_format.image_channel_data_type);
+
+ const amd::Image::Format imageFormat(image_format);
+
+ amd::Memory* memory = nullptr;
+
+ switch (pResDesc->resType) {
+ case hipResourceTypeArray:
+ assert(0);
+ break;
+ case hipResourceTypeMipmappedArray:
+ assert(0);
+ break;
+ case hipResourceTypeLinear:
+ assert(pResViewDesc == nullptr);
+
+ memory = amd::SvmManager::FindSvmBuffer(pResDesc->res.linear.devPtr);
+ image = new (*g_context) amd::Image(*memory->asBuffer(), CL_MEM_OBJECT_IMAGE1D, memory->getMemFlags(), imageFormat,
+ pResDesc->res.linear.sizeInBytes / imageFormat.getElementSize(), 1, 1,
+ pResDesc->res.linear.sizeInBytes, 0);
+ break;
+ case hipResourceTypePitch2D:
+ assert(pResViewDesc == nullptr);
+
+ memory = amd::SvmManager::FindSvmBuffer(pResDesc->res.pitch2D.devPtr);
+ image = new (*g_context) amd::Image(*memory->asBuffer(), CL_MEM_OBJECT_IMAGE2D, memory->getMemFlags(), imageFormat,
+ pResDesc->res.pitch2D.width, pResDesc->res.pitch2D.height, 1,
+ pResDesc->res.pitch2D.pitchInBytes, 0);
+ break;
+ default: return hipErrorInvalidValue;
+ }
+ *pTexObject = reinterpret_cast(as_cl(image));
return hipErrorUnknown;
}
@@ -38,9 +148,9 @@ hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResou
hipError_t hipDestroyTextureObject(hipTextureObject_t textureObject) {
HIP_INIT_API(textureObject);
- assert(0 && "Unimplemented");
+ as_amd(reinterpret_cast(textureObject))->release();
- return hipErrorUnknown;
+ return hipSuccess;
}
hipError_t hipGetTextureObjectResourceDesc(hipResourceDesc* pResDesc,
@@ -205,4 +315,4 @@ hipError_t hipTexRefSetAddress2D(textureReference* tex, const HIP_ARRAY_DESCRIPT
assert(0 && "Unimplemented");
return hipErrorUnknown;
-}
\ No newline at end of file
+}