Skip to content

Commit 0c7b74e

Browse files
committed
Merge branch 'petr/hip-get-mem-info' into benie/hip-cts-fixes-combined
2 parents dd1e816 + 8e7f785 commit 0c7b74e

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

source/adapters/hip/memory.cpp

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,91 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate(
525525
return Result;
526526
}
527527

528-
/// \TODO Not implemented
529-
UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t,
530-
ur_image_info_t, size_t,
531-
void *, size_t *) {
532-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
528+
UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory,
529+
ur_image_info_t propName,
530+
size_t propSize,
531+
void *pPropValue,
532+
size_t *pPropSizeRet) {
533+
UR_ASSERT(hMemory->isImage(), UR_RESULT_ERROR_INVALID_MEM_OBJECT);
534+
ScopedContext Active(hMemory->getContext()->getDevice());
535+
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
536+
537+
try {
538+
539+
HIP_ARRAY3D_DESCRIPTOR ArrayInfo;
540+
UR_CHECK_ERROR(hipArray3DGetDescriptor(
541+
&ArrayInfo, std::get<SurfaceMem>(hMemory->Mem).Array));
542+
543+
const auto hip2urFormat =
544+
[](hipArray_Format HipFormat) -> ur_image_channel_type_t {
545+
switch (HipFormat) {
546+
case HIP_AD_FORMAT_UNSIGNED_INT8:
547+
return UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT8;
548+
case HIP_AD_FORMAT_UNSIGNED_INT16:
549+
return UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT16;
550+
case HIP_AD_FORMAT_UNSIGNED_INT32:
551+
return UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32;
552+
case HIP_AD_FORMAT_SIGNED_INT8:
553+
return UR_IMAGE_CHANNEL_TYPE_SIGNED_INT8;
554+
case HIP_AD_FORMAT_SIGNED_INT16:
555+
return UR_IMAGE_CHANNEL_TYPE_SIGNED_INT16;
556+
case HIP_AD_FORMAT_SIGNED_INT32:
557+
return UR_IMAGE_CHANNEL_TYPE_SIGNED_INT32;
558+
case HIP_AD_FORMAT_HALF:
559+
return UR_IMAGE_CHANNEL_TYPE_HALF_FLOAT;
560+
case HIP_AD_FORMAT_FLOAT:
561+
return UR_IMAGE_CHANNEL_TYPE_FLOAT;
562+
563+
default:
564+
detail::ur::die("Invalid Hip format specified.");
565+
}
566+
};
567+
568+
const auto hipFormatToElementSize =
569+
[](hipArray_Format HipFormat) -> size_t {
570+
switch (HipFormat) {
571+
case HIP_AD_FORMAT_UNSIGNED_INT8:
572+
case HIP_AD_FORMAT_SIGNED_INT8:
573+
return 1;
574+
case HIP_AD_FORMAT_UNSIGNED_INT16:
575+
case HIP_AD_FORMAT_SIGNED_INT16:
576+
case HIP_AD_FORMAT_HALF:
577+
return 2;
578+
case HIP_AD_FORMAT_UNSIGNED_INT32:
579+
case HIP_AD_FORMAT_SIGNED_INT32:
580+
case HIP_AD_FORMAT_FLOAT:
581+
return 4;
582+
default:
583+
detail::ur::die("Invalid Hip format specified.");
584+
}
585+
};
586+
587+
switch (propName) {
588+
case UR_IMAGE_INFO_FORMAT:
589+
return ReturnValue(ur_image_format_t{UR_IMAGE_CHANNEL_ORDER_RGBA,
590+
hip2urFormat(ArrayInfo.Format)});
591+
case UR_IMAGE_INFO_WIDTH:
592+
return ReturnValue(ArrayInfo.Width);
593+
case UR_IMAGE_INFO_HEIGHT:
594+
return ReturnValue(ArrayInfo.Height);
595+
case UR_IMAGE_INFO_DEPTH:
596+
return ReturnValue(ArrayInfo.Depth);
597+
case UR_IMAGE_INFO_ELEMENT_SIZE:
598+
return ReturnValue(hipFormatToElementSize(ArrayInfo.Format));
599+
case UR_IMAGE_INFO_ROW_PITCH:
600+
case UR_IMAGE_INFO_SLICE_PITCH:
601+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
602+
603+
default:
604+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
605+
}
606+
607+
} catch (ur_result_t Err) {
608+
return Err;
609+
} catch (...) {
610+
return UR_RESULT_ERROR_UNKNOWN;
611+
}
612+
return UR_RESULT_SUCCESS;
533613
}
534614

535615
UR_APIEXPORT ur_result_t UR_APICALL urMemRetain(ur_mem_handle_t hMem) {

0 commit comments

Comments
 (0)