Skip to content

Commit 50e9820

Browse files
authored
Merge pull request #2496 from GeorgeWeb/georgi/bindless-hip
[UR][Bindless] Initial implementation of bindless images for HIP
2 parents 77b85c0 + 9b99015 commit 50e9820

File tree

7 files changed

+1533
-122
lines changed

7 files changed

+1533
-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: 139 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,144 @@ 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 supports 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+
return ReturnValue(ur_bool_t{false});
890+
}
891+
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_USM_EXP: {
892+
// HIP supports 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 supports 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 supports 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 supports 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 supports sampling 2D USM sampled image data.
924+
return ReturnValue(
925+
static_cast<ur_bool_t>(hDevice->supportsHardwareImages()));
926+
}
927+
789928
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS: {
790929
return ReturnValue(ur_bool_t{false});
791930
}

source/adapters/hip/device.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct ur_device_handle_t_ {
3434
int DeviceMaxLocalMem{0};
3535
int ManagedMemSupport{0};
3636
int ConcurrentManagedAccess{0};
37+
bool HardwareImageSupport{false};
3738

3839
public:
3940
ur_device_handle_t_(native_type HipDevice, hipEvent_t EvBase,
@@ -57,6 +58,12 @@ struct ur_device_handle_t_ {
5758
UR_CHECK_ERROR(hipDeviceGetAttribute(
5859
&ConcurrentManagedAccess, hipDeviceAttributeConcurrentManagedAccess,
5960
HIPDevice));
61+
// Check if texture functions are supported in the HIP host runtime.
62+
int Ret{};
63+
UR_CHECK_ERROR(
64+
hipDeviceGetAttribute(&Ret, hipDeviceAttributeImageSupport, HIPDevice));
65+
detail::ur::assertion(Ret == 0 || Ret == 1);
66+
HardwareImageSupport = Ret == 1;
6067
}
6168

6269
~ur_device_handle_t_() noexcept(false) {}
@@ -88,6 +95,8 @@ struct ur_device_handle_t_ {
8895
int getConcurrentManagedAccess() const noexcept {
8996
return ConcurrentManagedAccess;
9097
};
98+
99+
bool supportsHardwareImages() const noexcept { return HardwareImageSupport; }
91100
};
92101

93102
int getAttribute(ur_device_handle_t Device, hipDeviceAttribute_t Attribute);

0 commit comments

Comments
 (0)