Skip to content

Commit fa865c4

Browse files
GeorgeWebProGTX
andcommitted
[UR][Bindless] Initial implementation of bindless images for HIP
This PR implements the entry points in the HIP adapter for the Bindless Images extension. Some features, while implemented, only partially pass the End-to-end tests for them in DPC++ (the PR that enables the support and testing in DPC++: #16439). This is because the HIP runtime doesn't support, for example, some parameter combinations with some image memory types. The not-fully supported features are marked with TODOs in the device info queries for further work. Signed-off-by: Georgi Mirazchiyski <[email protected]> Co-authored-by: Peter Žužek <[email protected]>
1 parent 5f938ad commit fa865c4

File tree

7 files changed

+1539
-122
lines changed

7 files changed

+1539
-122
lines changed

source/adapters/hip/common.cpp

Lines changed: 4 additions & 0 deletions
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

Lines changed: 140 additions & 0 deletions
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) {
@@ -786,6 +787,145 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
786787
return ReturnValue(int32_t{1});
787788
}
788789

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

source/adapters/hip/device.hpp

Lines changed: 14 additions & 0 deletions
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)