Skip to content

Commit 0912559

Browse files
GeorgeWebProGTX
andcommitted
[UR][Bindless] Initial implementation of bindless images for HIP
TODO: Complete the description with more information. Signed-off-by: Georgi Mirazchiyski <[email protected]> Co-authored-by: Peter Žužek <[email protected]>
1 parent 54b3b86 commit 0912559

File tree

7 files changed

+1539
-122
lines changed

7 files changed

+1539
-122
lines changed

source/adapters/hip/common.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ ur_result_t mapErrorUR(hipError_t Result) {
4343
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
4444
case hipErrorLaunchOutOfResources:
4545
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
46+
case hipErrorNotInitialized:
47+
return UR_RESULT_ERROR_UNINITIALIZED;
48+
case hipErrorNotSupported:
49+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
4650
default:
4751
return UR_RESULT_ERROR_UNKNOWN;
4852
}

source/adapters/hip/device.cpp

+140
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "event.hpp"
1515
#include "logger/ur_logger.hpp"
1616

17+
#include <hip/hip_runtime.h>
1718
#include <sstream>
1819

1920
int getAttribute(ur_device_handle_t Device, hipDeviceAttribute_t Attribute) {
@@ -785,6 +786,145 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
785786
return ReturnValue(int32_t{1});
786787
}
787788

789+
case UR_DEVICE_INFO_BINDLESS_IMAGES_SUPPORT_EXP: {
790+
// On HIP bindless images are implemented but support is device-dependent.
791+
return ReturnValue(
792+
static_cast<ur_bool_t>(hDevice->supportsHardwareImages()));
793+
}
794+
case UR_DEVICE_INFO_BINDLESS_IMAGES_SHARED_USM_SUPPORT_EXP: {
795+
// On HIP bindless images can be backed by shared (managed) USM.
796+
return ReturnValue(
797+
static_cast<ur_bool_t>(hDevice->supportsHardwareImages()));
798+
}
799+
case UR_DEVICE_INFO_BINDLESS_IMAGES_1D_USM_SUPPORT_EXP: {
800+
// On HIP 1D bindless image USM is supported, but sampling is not.
801+
// More specifically, image creation from with sampler using linear
802+
// filtering is unstable and somtimes passes while other times returns
803+
// unsupported error code.
804+
return ReturnValue(
805+
static_cast<ur_bool_t>(hDevice->supportsHardwareImages()));
806+
}
807+
case UR_DEVICE_INFO_BINDLESS_IMAGES_2D_USM_SUPPORT_EXP: {
808+
// On HIP 2D bindless image USM is supported, but sampling is not.
809+
// More specifically, image creation from with sampler using linear
810+
// filtering is unstable and somtimes passes while other times returns
811+
// unsupported error code.
812+
return ReturnValue(
813+
static_cast<ur_bool_t>(hDevice->supportsHardwareImages()));
814+
}
815+
case UR_DEVICE_INFO_IMAGE_PITCH_ALIGN_EXP: {
816+
int32_t tex_pitch_align{0};
817+
UR_CHECK_ERROR(hipDeviceGetAttribute(
818+
&tex_pitch_align, hipDeviceAttributeTexturePitchAlignment,
819+
hDevice->get()));
820+
detail::ur::assertion(tex_pitch_align >= 0);
821+
return ReturnValue(static_cast<uint32_t>(tex_pitch_align));
822+
}
823+
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_WIDTH_EXP: {
824+
// Default values due to non-existent hipamd queries for linear sizes.
825+
constexpr uint32_t MaxLinearWidth{1};
826+
return ReturnValue(MaxLinearWidth);
827+
}
828+
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_HEIGHT_EXP: {
829+
// Default values due to non-existent hipamd queries for linear sizes.
830+
constexpr uint32_t MaxLinearHeight{1};
831+
return ReturnValue(MaxLinearHeight);
832+
}
833+
case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_PITCH_EXP: {
834+
// Default values due to non-existent hipamd queries for linear sizes.
835+
constexpr uint32_t MaxLinearPitch{1};
836+
return ReturnValue(MaxLinearPitch);
837+
}
838+
case UR_DEVICE_INFO_MIPMAP_SUPPORT_EXP: {
839+
// HIP supports mipmaps.
840+
// TODO: DPC++ doesn't implement the required mipmap builtins for SYCL.
841+
return ReturnValue(ur_bool_t{false});
842+
}
843+
case UR_DEVICE_INFO_MIPMAP_ANISOTROPY_SUPPORT_EXP: {
844+
// HIP supports anisotropic filtering.
845+
// TODO: DPC++ doesn't implement the required mipmap builtins for SYCL.
846+
return ReturnValue(ur_bool_t{false});
847+
}
848+
case UR_DEVICE_INFO_MIPMAP_MAX_ANISOTROPY_EXP: {
849+
// HIP has no query for this, but documentation states max value is 16.
850+
constexpr float MaxAnisotropy{16.f};
851+
return ReturnValue(MaxAnisotropy);
852+
}
853+
case UR_DEVICE_INFO_MIPMAP_LEVEL_REFERENCE_SUPPORT_EXP: {
854+
// HIP supports creation of images from individual mipmap levels.
855+
// TODO: DPC++ doesn't implement the required mipmap builtins for SYCL.
856+
return ReturnValue(ur_bool_t{false});
857+
}
858+
859+
case UR_DEVICE_INFO_EXTERNAL_MEMORY_IMPORT_SUPPORT_EXP: {
860+
// Importing external memory is supported, but there are current
861+
// issues in the HIP runtime due to which mapping the external array memory
862+
// does not work at the moment. Linear/buffer memory mapping is supported.
863+
return ReturnValue(ur_bool_t{false});
864+
}
865+
case UR_DEVICE_INFO_EXTERNAL_SEMAPHORE_IMPORT_SUPPORT_EXP: {
866+
// HIP supports importing external semaphores.
867+
// TODO: Importing external semaphores should be supported in the adapter,
868+
// but there are still current issues as not all related tests are passing.
869+
return ReturnValue(ur_bool_t{false});
870+
}
871+
case UR_DEVICE_INFO_CUBEMAP_SUPPORT_EXP: {
872+
// HIP supports cubemaps.
873+
// TODO: DPC++ doesn't implement the required builtins for SYCL.
874+
return ReturnValue(ur_bool_t{false});
875+
}
876+
case UR_DEVICE_INFO_CUBEMAP_SEAMLESS_FILTERING_SUPPORT_EXP: {
877+
// HIP supports cubemap seamless filtering.
878+
// TODO: DPC++ doesn't implement the required builtins for SYCL.
879+
return ReturnValue(ur_bool_t{false});
880+
}
881+
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_1D_USM_EXP: {
882+
// HIP does support fetching 1D USM sampled image data.
883+
// TODO: DPC++ doesn't implement the required builtins for SYCL.
884+
return ReturnValue(ur_bool_t{false});
885+
}
886+
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_1D_EXP: {
887+
// HIP does not support fetching 1D non-USM sampled image data.
888+
// TODO: DPC++ doesn't implement the required builtins for SYCL.
889+
return ReturnValue(ur_bool_t{false});
890+
}
891+
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_USM_EXP: {
892+
// HIP does support fetching 2D USM sampled image data.
893+
// TODO: DPC++ doesn't implement the required builtins for SYCL.
894+
return ReturnValue(ur_bool_t{false});
895+
}
896+
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_EXP: {
897+
// HIP does support fetching 2D non-USM sampled image data.
898+
// TODO: DPC++ doesn't implement the required builtins for SYCL.
899+
return ReturnValue(ur_bool_t{false});
900+
}
901+
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_3D_EXP: {
902+
// HIP does support fetching 3D non-USM sampled image data.
903+
// TODO: DPC++ doesn't implement the required builtins for SYCL.
904+
return ReturnValue(ur_bool_t{false});
905+
}
906+
case UR_DEVICE_INFO_IMAGE_ARRAY_SUPPORT_EXP: {
907+
// TODO: Our HIP adapter implements image arrays but DPC++ end-to-end
908+
// testing currently fails due to various runtime errors that could be
909+
// arch-specific driver support, as well missing builtins. Hence, this
910+
// feature is marked unsupported until those issues are resolved.
911+
return ReturnValue(ur_bool_t{false});
912+
}
913+
case UR_DEVICE_INFO_BINDLESS_UNIQUE_ADDRESSING_PER_DIM_EXP: {
914+
// HIP does not support unique addressing per dimension
915+
return ReturnValue(ur_bool_t{false});
916+
}
917+
case UR_DEVICE_INFO_BINDLESS_SAMPLE_1D_USM_EXP: {
918+
// HIP does support sampling 1D USM sampled image data.
919+
return ReturnValue(
920+
static_cast<ur_bool_t>(hDevice->supportsHardwareImages()));
921+
}
922+
case UR_DEVICE_INFO_BINDLESS_SAMPLE_2D_USM_EXP: {
923+
// HIP does support sampling 2D USM sampled image data.
924+
return ReturnValue(
925+
static_cast<ur_bool_t>(hDevice->supportsHardwareImages()));
926+
}
927+
788928
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS: {
789929
return ReturnValue(ur_bool_t{false});
790930
}

source/adapters/hip/device.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <ur/ur.hpp>
1515

16+
#include <map>
17+
1618
/// UR device mapping to a hipDevice_t.
1719
/// Includes an observer pointer to the platform,
1820
/// and implements the reference counting semantics since
@@ -34,6 +36,7 @@ struct ur_device_handle_t_ {
3436
int DeviceMaxLocalMem{0};
3537
int ManagedMemSupport{0};
3638
int ConcurrentManagedAccess{0};
39+
int HardwareImageSupport{0};
3740

3841
public:
3942
ur_device_handle_t_(native_type HipDevice, hipEvent_t EvBase,
@@ -57,6 +60,10 @@ struct ur_device_handle_t_ {
5760
UR_CHECK_ERROR(hipDeviceGetAttribute(
5861
&ConcurrentManagedAccess, hipDeviceAttributeConcurrentManagedAccess,
5962
HIPDevice));
63+
// Check if texture functions are supported in the HIP host runtime.
64+
UR_CHECK_ERROR(hipDeviceGetAttribute(
65+
&HardwareImageSupport, hipDeviceAttributeImageSupport, HIPDevice));
66+
detail::ur::assertion(HardwareImageSupport >= 0);
6067
}
6168

6269
~ur_device_handle_t_() noexcept(false) {}
@@ -88,6 +95,13 @@ struct ur_device_handle_t_ {
8895
int getConcurrentManagedAccess() const noexcept {
8996
return ConcurrentManagedAccess;
9097
};
98+
99+
bool supportsHardwareImages() const noexcept {
100+
return HardwareImageSupport ? true : false;
101+
}
102+
103+
// Used for bookkeeping for mipmapped array leaks in mapping external memory.
104+
std::map<hipArray_t, hipMipmappedArray_t> ChildHipArrayFromMipmapMap;
91105
};
92106

93107
int getAttribute(ur_device_handle_t Device, hipDeviceAttribute_t Attribute);

0 commit comments

Comments
 (0)