From b794dd07aca1456fc44e6a7787dcf6f597f9f22e Mon Sep 17 00:00:00 2001 From: tapplencourt Date: Wed, 1 Apr 2026 20:47:54 +0000 Subject: [PATCH 1/5] Enum and macro --- backends/hip/gen_hip_library.rb | 10 +- backends/hip/headers.patch | 270 +------------------------------- configure.ac | 2 +- utils/gen_library_base.rb | 103 +++++++++--- 4 files changed, 93 insertions(+), 292 deletions(-) diff --git a/backends/hip/gen_hip_library.rb b/backends/hip/gen_hip_library.rb index 78858a25..ea7f1129 100644 --- a/backends/hip/gen_hip_library.rb +++ b/backends/hip/gen_hip_library.rb @@ -67,6 +67,14 @@ def print_struct(name, struct) print_struct_with_namespace(:HIP, name, struct, prepends: prepends) end +typedef_enum_names = $all_types.filter_map { |t| t.type.name if t.type.is_a?(YAMLCAst::Enum) }.to_set +$all_enums.each do |e| + next unless e.name + next if typedef_enum_names.include?(e.name) + + print_enum(e.name, e) +end + $all_types.each do |t| if t.type.is_a? YAMLCAst::Enum enum = $all_enums.find { |e| t.type.name == e.name } @@ -74,7 +82,7 @@ def print_struct(name, struct) elsif $objects.include?(t.name) print_hip_object(t.name) elsif t.type.is_a? YAMLCAst::Struct - struct = $all_structs.find { |s| t.type.name == s.name } + struct = t.type.name ? $all_structs.find { |s| t.type.name == s.name } : t.type next unless struct print_struct(t.name, struct) diff --git a/backends/hip/headers.patch b/backends/hip/headers.patch index 72709d69..0f6888e7 100644 --- a/backends/hip/headers.patch +++ b/backends/hip/headers.patch @@ -1,167 +1,6 @@ -diff -u4 -r --new-file include/hip/amd_detail/amd_hip_vector_types.h modified_include/hip/amd_detail/amd_hip_vector_types.h ---- include/hip/amd_detail/amd_hip_vector_types.h 2026-03-27 20:57:07.000000000 +0000 -+++ modified_include/hip/amd_detail/amd_hip_vector_types.h 2026-03-30 22:25:53.000000000 +0000 -@@ -1384,20 +1384,20 @@ - T w;\ - } CUDA_name##4; - #endif - --__MAKE_VECTOR_TYPE__(uchar, unsigned char); --__MAKE_VECTOR_TYPE__(char, char); --__MAKE_VECTOR_TYPE__(ushort, unsigned short); --__MAKE_VECTOR_TYPE__(short, short); --__MAKE_VECTOR_TYPE__(uint, unsigned int); --__MAKE_VECTOR_TYPE__(int, int); --__MAKE_VECTOR_TYPE__(ulong, unsigned long); --__MAKE_VECTOR_TYPE__(long, long); --__MAKE_VECTOR_TYPE__(ulonglong, unsigned long long); --__MAKE_VECTOR_TYPE__(longlong, long long); --__MAKE_VECTOR_TYPE__(float, float); --__MAKE_VECTOR_TYPE__(double, double); -+__MAKE_VECTOR_TYPE__(uchar, unsigned char) -+__MAKE_VECTOR_TYPE__(char, char) -+__MAKE_VECTOR_TYPE__(ushort, unsigned short) -+__MAKE_VECTOR_TYPE__(short, short) -+__MAKE_VECTOR_TYPE__(uint, unsigned int) -+__MAKE_VECTOR_TYPE__(int, int) -+__MAKE_VECTOR_TYPE__(ulong, unsigned long) -+__MAKE_VECTOR_TYPE__(long, long) -+__MAKE_VECTOR_TYPE__(ulonglong, unsigned long long) -+__MAKE_VECTOR_TYPE__(longlong, long long) -+__MAKE_VECTOR_TYPE__(float, float) -+__MAKE_VECTOR_TYPE__(double, double) - - #else // !defined(__has_attribute) - - #if defined(_MSC_VER) -@@ -2478,65 +2478,65 @@ - return r; \ - } - #endif - --DECLOP_MAKE_ONE_COMPONENT(unsigned char, uchar1); --DECLOP_MAKE_TWO_COMPONENT(unsigned char, uchar2); --DECLOP_MAKE_THREE_COMPONENT(unsigned char, uchar3); --DECLOP_MAKE_FOUR_COMPONENT(unsigned char, uchar4); -- --DECLOP_MAKE_ONE_COMPONENT(signed char, char1); --DECLOP_MAKE_TWO_COMPONENT(signed char, char2); --DECLOP_MAKE_THREE_COMPONENT(signed char, char3); --DECLOP_MAKE_FOUR_COMPONENT(signed char, char4); -- --DECLOP_MAKE_ONE_COMPONENT(unsigned short, ushort1); --DECLOP_MAKE_TWO_COMPONENT(unsigned short, ushort2); --DECLOP_MAKE_THREE_COMPONENT(unsigned short, ushort3); --DECLOP_MAKE_FOUR_COMPONENT(unsigned short, ushort4); -- --DECLOP_MAKE_ONE_COMPONENT(signed short, short1); --DECLOP_MAKE_TWO_COMPONENT(signed short, short2); --DECLOP_MAKE_THREE_COMPONENT(signed short, short3); --DECLOP_MAKE_FOUR_COMPONENT(signed short, short4); -- --DECLOP_MAKE_ONE_COMPONENT(unsigned int, uint1); --DECLOP_MAKE_TWO_COMPONENT(unsigned int, uint2); --DECLOP_MAKE_THREE_COMPONENT(unsigned int, uint3); --DECLOP_MAKE_FOUR_COMPONENT(unsigned int, uint4); -- --DECLOP_MAKE_ONE_COMPONENT(signed int, int1); --DECLOP_MAKE_TWO_COMPONENT(signed int, int2); --DECLOP_MAKE_THREE_COMPONENT(signed int, int3); --DECLOP_MAKE_FOUR_COMPONENT(signed int, int4); -- --DECLOP_MAKE_ONE_COMPONENT(float, float1); --DECLOP_MAKE_TWO_COMPONENT(float, float2); --DECLOP_MAKE_THREE_COMPONENT(float, float3); --DECLOP_MAKE_FOUR_COMPONENT(float, float4); -- --DECLOP_MAKE_ONE_COMPONENT(double, double1); --DECLOP_MAKE_TWO_COMPONENT(double, double2); --DECLOP_MAKE_THREE_COMPONENT(double, double3); --DECLOP_MAKE_FOUR_COMPONENT(double, double4); -- --DECLOP_MAKE_ONE_COMPONENT(unsigned long, ulong1); --DECLOP_MAKE_TWO_COMPONENT(unsigned long, ulong2); --DECLOP_MAKE_THREE_COMPONENT(unsigned long, ulong3); --DECLOP_MAKE_FOUR_COMPONENT(unsigned long, ulong4); -- --DECLOP_MAKE_ONE_COMPONENT(signed long, long1); --DECLOP_MAKE_TWO_COMPONENT(signed long, long2); --DECLOP_MAKE_THREE_COMPONENT(signed long, long3); --DECLOP_MAKE_FOUR_COMPONENT(signed long, long4); -- --DECLOP_MAKE_ONE_COMPONENT(unsigned long long, ulonglong1); --DECLOP_MAKE_TWO_COMPONENT(unsigned long long, ulonglong2); --DECLOP_MAKE_THREE_COMPONENT(unsigned long long, ulonglong3); --DECLOP_MAKE_FOUR_COMPONENT(unsigned long long, ulonglong4); -- --DECLOP_MAKE_ONE_COMPONENT(signed long long, longlong1); --DECLOP_MAKE_TWO_COMPONENT(signed long long, longlong2); --DECLOP_MAKE_THREE_COMPONENT(signed long long, longlong3); --DECLOP_MAKE_FOUR_COMPONENT(signed long long, longlong4); -+DECLOP_MAKE_ONE_COMPONENT(unsigned char, uchar1) -+DECLOP_MAKE_TWO_COMPONENT(unsigned char, uchar2) -+DECLOP_MAKE_THREE_COMPONENT(unsigned char, uchar3) -+DECLOP_MAKE_FOUR_COMPONENT(unsigned char, uchar4) -+ -+DECLOP_MAKE_ONE_COMPONENT(signed char, char1) -+DECLOP_MAKE_TWO_COMPONENT(signed char, char2) -+DECLOP_MAKE_THREE_COMPONENT(signed char, char3) -+DECLOP_MAKE_FOUR_COMPONENT(signed char, char4) -+ -+DECLOP_MAKE_ONE_COMPONENT(unsigned short, ushort1) -+DECLOP_MAKE_TWO_COMPONENT(unsigned short, ushort2) -+DECLOP_MAKE_THREE_COMPONENT(unsigned short, ushort3) -+DECLOP_MAKE_FOUR_COMPONENT(unsigned short, ushort4) -+ -+DECLOP_MAKE_ONE_COMPONENT(signed short, short1) -+DECLOP_MAKE_TWO_COMPONENT(signed short, short2) -+DECLOP_MAKE_THREE_COMPONENT(signed short, short3) -+DECLOP_MAKE_FOUR_COMPONENT(signed short, short4) -+ -+DECLOP_MAKE_ONE_COMPONENT(unsigned int, uint1) -+DECLOP_MAKE_TWO_COMPONENT(unsigned int, uint2) -+DECLOP_MAKE_THREE_COMPONENT(unsigned int, uint3) -+DECLOP_MAKE_FOUR_COMPONENT(unsigned int, uint4) -+ -+DECLOP_MAKE_ONE_COMPONENT(signed int, int1) -+DECLOP_MAKE_TWO_COMPONENT(signed int, int2) -+DECLOP_MAKE_THREE_COMPONENT(signed int, int3) -+DECLOP_MAKE_FOUR_COMPONENT(signed int, int4) -+ -+DECLOP_MAKE_ONE_COMPONENT(float, float1) -+DECLOP_MAKE_TWO_COMPONENT(float, float2) -+DECLOP_MAKE_THREE_COMPONENT(float, float3) -+DECLOP_MAKE_FOUR_COMPONENT(float, float4) -+ -+DECLOP_MAKE_ONE_COMPONENT(double, double1) -+DECLOP_MAKE_TWO_COMPONENT(double, double2) -+DECLOP_MAKE_THREE_COMPONENT(double, double3) -+DECLOP_MAKE_FOUR_COMPONENT(double, double4) -+ -+DECLOP_MAKE_ONE_COMPONENT(unsigned long, ulong1) -+DECLOP_MAKE_TWO_COMPONENT(unsigned long, ulong2) -+DECLOP_MAKE_THREE_COMPONENT(unsigned long, ulong3) -+DECLOP_MAKE_FOUR_COMPONENT(unsigned long, ulong4) -+ -+DECLOP_MAKE_ONE_COMPONENT(signed long, long1) -+DECLOP_MAKE_TWO_COMPONENT(signed long, long2) -+DECLOP_MAKE_THREE_COMPONENT(signed long, long3) -+DECLOP_MAKE_FOUR_COMPONENT(signed long, long4) -+ -+DECLOP_MAKE_ONE_COMPONENT(unsigned long long, ulonglong1) -+DECLOP_MAKE_TWO_COMPONENT(unsigned long long, ulonglong2) -+DECLOP_MAKE_THREE_COMPONENT(unsigned long long, ulonglong3) -+DECLOP_MAKE_FOUR_COMPONENT(unsigned long long, ulonglong4) -+ -+DECLOP_MAKE_ONE_COMPONENT(signed long long, longlong1) -+DECLOP_MAKE_TWO_COMPONENT(signed long long, longlong2) -+DECLOP_MAKE_THREE_COMPONENT(signed long long, longlong3) -+DECLOP_MAKE_FOUR_COMPONENT(signed long long, longlong4) - - #endif diff -u4 -r --new-file include/hip/hip_ext.h modified_include/hip/hip_ext.h --- include/hip/hip_ext.h 2026-03-27 20:57:07.000000000 +0000 -+++ modified_include/hip/hip_ext.h 2026-03-30 22:25:53.000000000 +0000 ++++ modified_include/hip/hip_ext.h 2026-03-31 22:37:08.000000000 +0000 @@ -21,9 +21,11 @@ */ @@ -204,7 +43,7 @@ diff -u4 -r --new-file include/hip/hip_ext.h modified_include/hip/hip_ext.h diff -u4 -r --new-file include/hip/hip_runtime_api.h modified_include/hip/hip_runtime_api.h --- include/hip/hip_runtime_api.h 2026-03-27 20:57:07.000000000 +0000 -+++ modified_include/hip/hip_runtime_api.h 2026-03-30 22:25:53.000000000 +0000 ++++ modified_include/hip/hip_runtime_api.h 2026-03-31 22:37:08.000000000 +0000 @@ -29,9 +29,8 @@ #ifndef HIP_INCLUDE_HIP_HIP_RUNTIME_API_H @@ -215,76 +54,7 @@ diff -u4 -r --new-file include/hip/hip_runtime_api.h modified_include/hip/hip_ru #include #include -@@ -41,37 +40,39 @@ - HIP_ERROR_NOT_INITIALIZED, - HIP_ERROR_LAUNCH_OUT_OF_RESOURCES - }; - --typedef struct { -- // 32-bit Atomics -- unsigned hasGlobalInt32Atomics : 1; ///< 32-bit integer atomics for global memory. -- unsigned hasGlobalFloatAtomicExch : 1; ///< 32-bit float atomic exch for global memory. -- unsigned hasSharedInt32Atomics : 1; ///< 32-bit integer atomics for shared memory. -- unsigned hasSharedFloatAtomicExch : 1; ///< 32-bit float atomic exch for shared memory. -- unsigned hasFloatAtomicAdd : 1; ///< 32-bit float atomic add in global and shared memory. -- -- // 64-bit Atomics -- unsigned hasGlobalInt64Atomics : 1; ///< 64-bit integer atomics for global memory. -- unsigned hasSharedInt64Atomics : 1; ///< 64-bit integer atomics for shared memory. -- -- // Doubles -- unsigned hasDoubles : 1; ///< Double-precision floating point. -- -- // Warp cross-lane operations -- unsigned hasWarpVote : 1; ///< Warp vote instructions (__any, __all). -- unsigned hasWarpBallot : 1; ///< Warp ballot instructions (__ballot). -- unsigned hasWarpShuffle : 1; ///< Warp shuffle operations. (__shfl_*). -- unsigned hasFunnelShift : 1; ///< Funnel two words into one with shift&mask caps. -- -- // Sync -- unsigned hasThreadFenceSystem : 1; ///< __threadfence_system. -- unsigned hasSyncThreadsExt : 1; ///< __syncthreads_count, syncthreads_and, syncthreads_or. -- -- // Misc -- unsigned hasSurfaceFuncs : 1; ///< Surface functions. -- unsigned has3dGrid : 1; ///< Grid and group dims are 3D (rather than 2D). -- unsigned hasDynamicParallelism : 1; ///< Dynamic parallelism. -+typedef struct hipDeviceArch_t { -+// Bitfields are not portable -+ unsigned flags; -+// // 32-bit Atomics -+// unsigned hasGlobalInt32Atomics : 1; ///< 32-bit integer atomics for global memory. -+// unsigned hasGlobalFloatAtomicExch : 1; ///< 32-bit float atomic exch for global memory. -+// unsigned hasSharedInt32Atomics : 1; ///< 32-bit integer atomics for shared memory. -+// unsigned hasSharedFloatAtomicExch : 1; ///< 32-bit float atomic exch for shared memory. -+// unsigned hasFloatAtomicAdd : 1; ///< 32-bit float atomic add in global and shared memory. -+// -+// // 64-bit Atomics -+// unsigned hasGlobalInt64Atomics : 1; ///< 64-bit integer atomics for global memory. -+// unsigned hasSharedInt64Atomics : 1; ///< 64-bit integer atomics for shared memory. -+// -+// // Doubles -+// unsigned hasDoubles : 1; ///< Double-precision floating point. -+// -+// // Warp cross-lane operations -+// unsigned hasWarpVote : 1; ///< Warp vote instructions (__any, __all). -+// unsigned hasWarpBallot : 1; ///< Warp ballot instructions (__ballot). -+// unsigned hasWarpShuffle : 1; ///< Warp shuffle operations. (__shfl_*). -+// unsigned hasFunnelShift : 1; ///< Funnel two words into one with shift&mask caps. -+// -+// // Sync -+// unsigned hasThreadFenceSystem : 1; ///< __threadfence_system. -+// unsigned hasSyncThreadsExt : 1; ///< __syncthreads_count, syncthreads_and, syncthreads_or. -+// -+// // Misc -+// unsigned hasSurfaceFuncs : 1; ///< Surface functions. -+// unsigned has3dGrid : 1; ///< Grid and group dims are 3D (rather than 2D). -+// unsigned hasDynamicParallelism : 1; ///< Dynamic parallelism. - } hipDeviceArch_t; - - typedef struct hipUUID_t { - char bytes[16]; -@@ -520,9 +521,11 @@ +@@ -520,9 +519,11 @@ hipDevP2PAttrHipArrayAccessSupported } hipDeviceP2PAttr; typedef struct ihipStream_t* hipStream_t; @@ -298,7 +68,7 @@ diff -u4 -r --new-file include/hip/hip_runtime_api.h modified_include/hip/hip_ru typedef struct hipIpcEventHandle_st { diff -u4 -r --new-file include/hip/hip_runtime_load_api.h modified_include/hip/hip_runtime_load_api.h --- include/hip/hip_runtime_load_api.h 1970-01-01 00:00:00.000000000 +0000 -+++ modified_include/hip/hip_runtime_load_api.h 2026-03-30 22:25:53.000000000 +0000 ++++ modified_include/hip/hip_runtime_load_api.h 2026-03-31 22:37:08.000000000 +0000 @@ -0,0 +1,95 @@ +#ifndef HIP_RUNTIME_LOAD_API_ +#define HIP_RUNTIME_LOAD_API_ @@ -395,35 +165,3 @@ diff -u4 -r --new-file include/hip/hip_runtime_load_api.h modified_include/hip/h +#endif /* __cplusplus */ + +#endif -diff -u4 -r --new-file include/hip/texture_types.h modified_include/hip/texture_types.h ---- include/hip/texture_types.h 2026-03-27 20:57:07.000000000 +0000 -+++ modified_include/hip/texture_types.h 2026-03-30 22:25:53.000000000 +0000 -@@ -64,24 +64,24 @@ - - /** - * hip texture address modes - */ --enum hipTextureAddressMode { -+typedef enum hipTextureAddressMode { - hipAddressModeWrap = 0, - hipAddressModeClamp = 1, - hipAddressModeMirror = 2, - hipAddressModeBorder = 3 --}; -+} hipTextureAddressMode; - - /** - * hip texture filter modes - */ --enum hipTextureFilterMode { hipFilterModePoint = 0, hipFilterModeLinear = 1 }; -+typedef enum hipTextureFilterMode { hipFilterModePoint = 0, hipFilterModeLinear = 1 } hipTextureFilterMode; - - /** - * hip texture read modes - */ --enum hipTextureReadMode { hipReadModeElementType = 0, hipReadModeNormalizedFloat = 1 }; -+typedef enum hipTextureReadMode { hipReadModeElementType = 0, hipReadModeNormalizedFloat = 1 } hipTextureReadMode; - - /** - * hip texture reference - */ diff --git a/configure.ac b/configure.ac index 57149036..089c4bee 100644 --- a/configure.ac +++ b/configure.ac @@ -81,7 +81,7 @@ AM_CONDITIONAL([FOUND_MPI], [test "x$enable_sync_daemon_mpi" != "xno"]) AC_CHECK_PROG(H2YAML, [h2yaml], [h2yaml], [no]) test "x$H2YAML" = "xno" && AC_MSG_ERROR([Required program 'h2yaml' not found.]) -H2YAML_MIN_VERSION=0.4.2 +H2YAML_MIN_VERSION=0.4.3 AC_MSG_CHECKING([for h2yaml >= $H2YAML_MIN_VERSION]) H2YAML_VERSION=`$H2YAML --version | cut -d' ' -f2` AX_COMPARE_VERSION([$H2YAML_VERSION], [ge], [$H2YAML_MIN_VERSION], diff --git a/utils/gen_library_base.rb b/utils/gen_library_base.rb index 5b96413b..4add9176 100644 --- a/utils/gen_library_base.rb +++ b/utils/gen_library_base.rb @@ -10,10 +10,18 @@ def to_ffi_name(name, default = true) return ':anonymous' when 'unsigned int' return ':uint' + when 'short', 'short int' + return ':short' when 'unsigned short', 'unsigned short int' return ':ushort' when 'unsigned char' return ':uchar' + when 'long', 'long int' + return ':long' + when 'unsigned long', 'unsigned long int' + return ':ulong' + when 'long long', 'long long int' + return ':int64' when 'unsigned long long', 'unsigned long long int' return ':uint64' when 'size_t' @@ -340,41 +348,88 @@ module YAMLCAst module Composite def to_ffi unamed_count = 0 - members.map do |m| - mt = case m.type - when Array - m.type.to_ffi - when Pointer - ':pointer' - when Struct - if m.type.name && has_typedef?(m.type.name) - to_ffi_name(m.type.name) - else - s = m.type.name ? $all_structs.find { |st| st.name == m.type.name } : m.type - "(Class::new(#{FFI_STRUCT}) { layout #{gen_layout(s.to_ffi)} }.by_value)" - end - when Union - if m.type.name && has_typedef?(m.type.name) - to_ffi_name(m.type.name) - else - u = m.type.name ? $all_unions&.find { |un| un.name == m.type.name } : m.type - "(Class::new(#{FFI_UNION}) { layout #{gen_layout(u.to_ffi)} }.by_value)" - end - else - m.type.name ? to_ffi_name(m.type.name) : raise("unknown type: #{m.type}") - end - [m.name ? m.name.to_sym.inspect : ":_unamed_#{unamed_count += 1}", mt] + result = [] + bitfields = BitfieldAccumulator.new + members.each do |m| + if m.num_bits + bitfields.add(m) + else + bitfields.flush_to_result(result) + result << [m.name ? m.name.to_sym.inspect : ":_unamed_#{unamed_count += 1}", member_to_ffi(m.type)] + end end + bitfields.flush_to_result(result) + result end private + def member_to_ffi(type) + case type + when Array + type.to_ffi + when Pointer + ':pointer' + when Struct + if type.name && has_typedef?(type.name) + to_ffi_name(type.name) + else + s = type.name ? $all_structs.find { |st| st.name == type.name } : type + "(Class::new(#{FFI_STRUCT}) { layout #{gen_layout(s.to_ffi)} }.by_value)" + end + when Union + if type.name && has_typedef?(type.name) + to_ffi_name(type.name) + else + u = type.name ? $all_unions&.find { |un| un.name == type.name } : type + "(Class::new(#{FFI_UNION}) { layout #{gen_layout(u.to_ffi)} }.by_value)" + end + else + type.name ? to_ffi_name(type.name) : raise("unknown type: #{type}") + end + end + def gen_layout(membs) membs.map do |a, b| s = "#{a}, " s << (b.is_a?(::Array) ? "[ #{b[0]}, #{b[1]} ]" : b) end.join(', ') end + + # TODO: FFI doesn't support bitfields. Consecutive bitfield members are + # collapsed into a single integer field named `_aggregated_bitfields_N`, + # using the declared type of the first bitfield as the storage type. + # For now Will crash if differnce storage type are used + # Individual bit flags are not accessible; to_s prints the raw integer value. + # + # Example: struct { unsigned a:1; unsigned b:1; int x; unsigned c:3; } + # becomes: layout :_aggregated_bitfields_1, :uint, # a + b + # :x, :int, + # :_aggregated_bitfields_2, :uint # c + class BitfieldAccumulator + def initialize + @count = 0 + @group = 0 + @type = nil + end + + def add(member) + if @type && @type != member.type.name + raise "Mixed bitfield types (#{@type} vs #{member.type.name}) not supported" + end + @type ||= member.type.name + @count += member.num_bits + end + + def flush_to_result(result) + return if @count == 0 + + @group += 1 + result << [":_aggregated_bitfields_#{@group}", to_ffi_name(@type)] + @count = 0 + @type = nil + end + end end class Struct From 4012db5a8d54c07c504e0b0e57b0fdfaaf935171 Mon Sep 17 00:00:00 2001 From: tapplencourt Date: Wed, 1 Apr 2026 22:17:07 +0000 Subject: [PATCH 2/5] Simplify a lot hip --- backends/hip/README.md | 11 +++ backends/hip/extract/hip_api.h | 3 - backends/hip/headers.patch | 142 +------------------------------- backends/hip/hip.h.include | 2 +- backends/hip/hip_missing_apis.h | 87 ++++++++++++++++++- 5 files changed, 99 insertions(+), 146 deletions(-) create mode 100644 backends/hip/README.md diff --git a/backends/hip/README.md b/backends/hip/README.md new file mode 100644 index 00000000..c58fb7d1 --- /dev/null +++ b/backends/hip/README.md @@ -0,0 +1,11 @@ +# HIP Backend + +## `hip_missing_apis.h` + +`hip_missing_apis.h` is not part of the official header. + +Declarations for functions and types exported by `libamdhip64.so` but not declared in any public HIP header: + +- `hipGraphDebugDotPrint`: Exports a `hipGraph_t` as a DOT file. The `hipGraphDebugDotFlags` enum (used by the `flag` parameter) is declared in `hip_runtime_api.h`, but the function itself is not. +- Runtime registration functions: `__hipRegisterFatBinary`, `__hipRegisterFunction`, `__hipRegisterVar`, etc. +- `hipGetCmdName`, `activity_domain_t`, `hipRegisterTracerCallback` diff --git a/backends/hip/extract/hip_api.h b/backends/hip/extract/hip_api.h index 8967b97a..fca796e9 100644 --- a/backends/hip/extract/hip_api.h +++ b/backends/hip/extract/hip_api.h @@ -1,12 +1,9 @@ #define __HIP_PLATFORM_AMD__ -#define THAPI_NO_INCLUDE #include #include -#include - #include #include "hip_cpp_symbols.h" diff --git a/backends/hip/headers.patch b/backends/hip/headers.patch index 0f6888e7..c1641f8e 100644 --- a/backends/hip/headers.patch +++ b/backends/hip/headers.patch @@ -1,19 +1,7 @@ diff -u4 -r --new-file include/hip/hip_ext.h modified_include/hip/hip_ext.h --- include/hip/hip_ext.h 2026-03-27 20:57:07.000000000 +0000 -+++ modified_include/hip/hip_ext.h 2026-03-31 22:37:08.000000000 +0000 -@@ -21,9 +21,11 @@ - */ - - #ifndef HIP_INCLUDE_HIP_HIP_EXT_H - #define HIP_INCLUDE_HIP_HIP_EXT_H -+#ifndef THAPI_NO_INCLUDE - #include "hip/hip_runtime.h" -+#endif - #if defined(__cplusplus) - #include - #include - #endif -@@ -69,11 +71,11 @@ ++++ modified_include/hip/hip_ext.h 2026-04-01 22:11:28.000000000 +0000 +@@ -69,11 +69,11 @@ uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ, uint32_t localWorkSizeX, uint32_t localWorkSizeY, uint32_t localWorkSizeZ, size_t sharedMemBytes, @@ -28,7 +16,7 @@ diff -u4 -r --new-file include/hip/hip_ext.h modified_include/hip/hip_ext.h * @brief This HIP API is deprecated, please use hipExtModuleLaunchKernel() instead. * */ -@@ -82,10 +84,10 @@ +@@ -82,10 +82,10 @@ uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ, uint32_t localWorkSizeX, uint32_t localWorkSizeY, uint32_t localWorkSizeZ, size_t sharedMemBytes, @@ -41,127 +29,3 @@ diff -u4 -r --new-file include/hip/hip_ext.h modified_include/hip/hip_ext.h #if defined(__cplusplus) -diff -u4 -r --new-file include/hip/hip_runtime_api.h modified_include/hip/hip_runtime_api.h ---- include/hip/hip_runtime_api.h 2026-03-27 20:57:07.000000000 +0000 -+++ modified_include/hip/hip_runtime_api.h 2026-03-31 22:37:08.000000000 +0000 -@@ -29,9 +29,8 @@ - - #ifndef HIP_INCLUDE_HIP_HIP_RUNTIME_API_H - #define HIP_INCLUDE_HIP_HIP_RUNTIME_API_H - -- - #include // for getDeviceProp - #include - #include - -@@ -520,9 +519,11 @@ - hipDevP2PAttrHipArrayAccessSupported - } hipDeviceP2PAttr; - typedef struct ihipStream_t* hipStream_t; - #define hipIpcMemLazyEnablePeerAccess 0 -+#ifndef HIP_IPC_HANDLE_SIZE - #define HIP_IPC_HANDLE_SIZE 64 -+#endif - typedef struct hipIpcMemHandle_st { - char reserved[HIP_IPC_HANDLE_SIZE]; - } hipIpcMemHandle_t; - typedef struct hipIpcEventHandle_st { -diff -u4 -r --new-file include/hip/hip_runtime_load_api.h modified_include/hip/hip_runtime_load_api.h ---- include/hip/hip_runtime_load_api.h 1970-01-01 00:00:00.000000000 +0000 -+++ modified_include/hip/hip_runtime_load_api.h 2026-03-31 22:37:08.000000000 +0000 -@@ -0,0 +1,95 @@ -+#ifndef HIP_RUNTIME_LOAD_API_ -+#define HIP_RUNTIME_LOAD_API_ -+ -+#ifdef __cplusplus -+extern "C" { -+#endif /* __cplusplus */ -+ -+extern void **__hipRegisterFatBinary( -+ const void *data); -+ -+ -+extern void __hipRegisterFunction( -+ void **modules, -+ const void *hostFunction, -+ char *deviceFunction, -+ const char *deviceName, -+ unsigned int threadLimit, -+ uint3 *tid, -+ uint3 *bid, -+ dim3 *blockDim, -+ dim3 *gridDim, -+ int *wSize); -+ -+extern void __hipRegisterManagedVar( -+ void **modules, // Pointer to hip module returned from __hipRegisterFatbinary -+ void **pointer, // Pointer to a chunk of managed memory with size \p size and alignment \p -+ // align HIP runtime allocates such managed memory and assign it to \p pointer -+ void *init_value, // Initial value to be copied into \p pointer -+ const char *name, // Name of the variable in code object -+ size_t size, -+ unsigned align); -+ -+extern void __hipRegisterSurface( -+ void **modules, // The device modules containing code object -+ void *var, // The shadow variable in host code -+ char *hostVar, // Variable name in host code -+ char *deviceVar, // Variable name in device code -+ int type, -+ int ext); -+ -+ -+extern void __hipRegisterTexture( -+ void **modules, // The device modules containing code object -+ void *var, // The shadow variable in host code -+ char *hostVar, // Variable name in host code -+ char *deviceVar, // Variable name in device code -+ int type, -+ int norm, -+ int ext); -+ -+extern void __hipRegisterVar( -+ void **modules, // The device modules containing code object -+ void *var, // The shadow variable in host code -+ char *hostVar, // Variable name in host code -+ char *deviceVar, // Variable name in device code -+ int ext, // Whether this variable is external -+ size_t size, // Size of the variable -+ int constant, // Whether this variable is constant -+ int global); // Unknown, always 0 -+ -+extern void __hipUnregisterFatBinary( -+ void** modules); -+ -+extern const char* hipGetCmdName( -+ uint32_t id); -+ -+typedef enum activity_domain_t { -+ ACTIVITY_DOMAIN_HSA_API = 0, /* HSA API domain */ -+ ACTIVITY_DOMAIN_HSA_OPS = 1, /* HSA async activity domain */ -+ ACTIVITY_DOMAIN_HIP_OPS = 2, /* HIP async activity domain */ -+ ACTIVITY_DOMAIN_HCC_OPS = -+ ACTIVITY_DOMAIN_HIP_OPS, /* HCC async activity domain */ -+ ACTIVITY_DOMAIN_HIP_VDI = -+ ACTIVITY_DOMAIN_HIP_OPS, /* HIP VDI async activity domain */ -+ ACTIVITY_DOMAIN_HIP_API = 3, /* HIP API domain */ -+ ACTIVITY_DOMAIN_KFD_API = 4, /* KFD API domain */ -+ ACTIVITY_DOMAIN_EXT_API = 5, /* External ID domain */ -+ ACTIVITY_DOMAIN_ROCTX = 6, /* ROCTX domain */ -+ ACTIVITY_DOMAIN_HSA_EVT = 7, /* HSA events */ -+ ACTIVITY_DOMAIN_NUMBER -+} activity_domain_t; -+ -+typedef int hipRegisterTracerCallback_callback_t( -+ activity_domain_t domain, -+ uint32_t operation_id, -+ void* data); -+ -+extern void hipRegisterTracerCallback( -+ hipRegisterTracerCallback_callback_t *function); -+ -+#ifdef __cplusplus -+} -+#endif /* __cplusplus */ -+ -+#endif diff --git a/backends/hip/hip.h.include b/backends/hip/hip.h.include index 5f467a7c..0bf37dd4 100644 --- a/backends/hip/hip.h.include +++ b/backends/hip/hip.h.include @@ -1,4 +1,4 @@ #define __HIP_PLATFORM_AMD__ #include #include -#include "modified_include/hip/hip_runtime_load_api.h" +#include "hip_missing_apis.h" diff --git a/backends/hip/hip_missing_apis.h b/backends/hip/hip_missing_apis.h index 62310879..689ea7f4 100644 --- a/backends/hip/hip_missing_apis.h +++ b/backends/hip/hip_missing_apis.h @@ -1,5 +1,86 @@ +#ifndef HIP_MISSING_APIS_H +#define HIP_MISSING_APIS_H + hipError_t hipGraphDebugDotPrint(hipGraph_t graph, const char *fName, unsigned int flag); -const char *amd_dbgapi_get_build_name(); -const char *amd_dbgapi_get_git_hash(); -size_t amd_dbgapi_get_build_id(); +extern void **__hipRegisterFatBinary( + const void *data); + +extern void __hipRegisterFunction( + void **modules, + const void *hostFunction, + char *deviceFunction, + const char *deviceName, + unsigned int threadLimit, + uint3 *tid, + uint3 *bid, + dim3 *blockDim, + dim3 *gridDim, + int *wSize); + +extern void __hipRegisterManagedVar( + void **modules, + void **pointer, + void *init_value, + const char *name, + size_t size, + unsigned align); + +extern void __hipRegisterSurface( + void **modules, + void *var, + char *hostVar, + char *deviceVar, + int type, + int ext); + +extern void __hipRegisterTexture( + void **modules, + void *var, + char *hostVar, + char *deviceVar, + int type, + int norm, + int ext); + +extern void __hipRegisterVar( + void **modules, + void *var, + char *hostVar, + char *deviceVar, + int ext, + size_t size, + int constant, + int global); + +extern void __hipUnregisterFatBinary( + void** modules); + +extern const char* hipGetCmdName( + uint32_t id); + +typedef enum activity_domain_t { + ACTIVITY_DOMAIN_HSA_API = 0, + ACTIVITY_DOMAIN_HSA_OPS = 1, + ACTIVITY_DOMAIN_HIP_OPS = 2, + ACTIVITY_DOMAIN_HCC_OPS = + ACTIVITY_DOMAIN_HIP_OPS, + ACTIVITY_DOMAIN_HIP_VDI = + ACTIVITY_DOMAIN_HIP_OPS, + ACTIVITY_DOMAIN_HIP_API = 3, + ACTIVITY_DOMAIN_KFD_API = 4, + ACTIVITY_DOMAIN_EXT_API = 5, + ACTIVITY_DOMAIN_ROCTX = 6, + ACTIVITY_DOMAIN_HSA_EVT = 7, + ACTIVITY_DOMAIN_NUMBER +} activity_domain_t; + +typedef int hipRegisterTracerCallback_callback_t( + activity_domain_t domain, + uint32_t operation_id, + void* data); + +extern void hipRegisterTracerCallback( + hipRegisterTracerCallback_callback_t *function); + +#endif From 533d417fe228c2bb71c12c5a0bf6f8b95789cda6 Mon Sep 17 00:00:00 2001 From: tapplencourt Date: Thu, 2 Apr 2026 19:22:47 +0000 Subject: [PATCH 3/5] update h2yaml --- .github/actions/setup-thapi/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-thapi/action.yml b/.github/actions/setup-thapi/action.yml index 2e3a75f5..6cecc17f 100644 --- a/.github/actions/setup-thapi/action.yml +++ b/.github/actions/setup-thapi/action.yml @@ -95,7 +95,7 @@ runs: make install - name: Install H2yaml shell: bash - run: pip install git+https://github.com/TApplencourt/h2yaml@v0.4.2 + run: pip install git+https://github.com/TApplencourt/h2yaml@v0.4.3 - name: Set Efficios environment variables shell: bash run: | From ef6dd60f2b938618a96e644f4833a004a17cf7f7 Mon Sep 17 00:00:00 2001 From: tapplencourt Date: Thu, 2 Apr 2026 19:23:45 +0000 Subject: [PATCH 4/5] Add missing api formating --- backends/hip/hip_missing_apis.h | 92 +++++++++++++-------------------- 1 file changed, 35 insertions(+), 57 deletions(-) diff --git a/backends/hip/hip_missing_apis.h b/backends/hip/hip_missing_apis.h index 689ea7f4..98e9c0dd 100644 --- a/backends/hip/hip_missing_apis.h +++ b/backends/hip/hip_missing_apis.h @@ -3,70 +3,51 @@ hipError_t hipGraphDebugDotPrint(hipGraph_t graph, const char *fName, unsigned int flag); -extern void **__hipRegisterFatBinary( - const void *data); +extern void **__hipRegisterFatBinary(const void *data); -extern void __hipRegisterFunction( - void **modules, - const void *hostFunction, - char *deviceFunction, - const char *deviceName, - unsigned int threadLimit, - uint3 *tid, - uint3 *bid, - dim3 *blockDim, - dim3 *gridDim, - int *wSize); +extern void __hipRegisterFunction(void **modules, + const void *hostFunction, + char *deviceFunction, + const char *deviceName, + unsigned int threadLimit, + uint3 *tid, + uint3 *bid, + dim3 *blockDim, + dim3 *gridDim, + int *wSize); -extern void __hipRegisterManagedVar( - void **modules, - void **pointer, - void *init_value, - const char *name, - size_t size, - unsigned align); +extern void __hipRegisterManagedVar(void **modules, + void **pointer, + void *init_value, + const char *name, + size_t size, + unsigned align); -extern void __hipRegisterSurface( - void **modules, - void *var, - char *hostVar, - char *deviceVar, - int type, - int ext); +extern void +__hipRegisterSurface(void **modules, void *var, char *hostVar, char *deviceVar, int type, int ext); extern void __hipRegisterTexture( - void **modules, - void *var, - char *hostVar, - char *deviceVar, - int type, - int norm, - int ext); + void **modules, void *var, char *hostVar, char *deviceVar, int type, int norm, int ext); -extern void __hipRegisterVar( - void **modules, - void *var, - char *hostVar, - char *deviceVar, - int ext, - size_t size, - int constant, - int global); +extern void __hipRegisterVar(void **modules, + void *var, + char *hostVar, + char *deviceVar, + int ext, + size_t size, + int constant, + int global); -extern void __hipUnregisterFatBinary( - void** modules); +extern void __hipUnregisterFatBinary(void **modules); -extern const char* hipGetCmdName( - uint32_t id); +extern const char *hipGetCmdName(uint32_t id); typedef enum activity_domain_t { ACTIVITY_DOMAIN_HSA_API = 0, ACTIVITY_DOMAIN_HSA_OPS = 1, ACTIVITY_DOMAIN_HIP_OPS = 2, - ACTIVITY_DOMAIN_HCC_OPS = - ACTIVITY_DOMAIN_HIP_OPS, - ACTIVITY_DOMAIN_HIP_VDI = - ACTIVITY_DOMAIN_HIP_OPS, + ACTIVITY_DOMAIN_HCC_OPS = ACTIVITY_DOMAIN_HIP_OPS, + ACTIVITY_DOMAIN_HIP_VDI = ACTIVITY_DOMAIN_HIP_OPS, ACTIVITY_DOMAIN_HIP_API = 3, ACTIVITY_DOMAIN_KFD_API = 4, ACTIVITY_DOMAIN_EXT_API = 5, @@ -75,12 +56,9 @@ typedef enum activity_domain_t { ACTIVITY_DOMAIN_NUMBER } activity_domain_t; -typedef int hipRegisterTracerCallback_callback_t( - activity_domain_t domain, - uint32_t operation_id, - void* data); +typedef int +hipRegisterTracerCallback_callback_t(activity_domain_t domain, uint32_t operation_id, void *data); -extern void hipRegisterTracerCallback( - hipRegisterTracerCallback_callback_t *function); +extern void hipRegisterTracerCallback(hipRegisterTracerCallback_callback_t *function); #endif From 38527bce91aabc660295ae9e3e18d6422c5fe998 Mon Sep 17 00:00:00 2001 From: tapplencourt Date: Thu, 2 Apr 2026 19:33:23 +0000 Subject: [PATCH 5/5] fix emply line --- utils/gen_library_base.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/gen_library_base.rb b/utils/gen_library_base.rb index 4add9176..7c5b26b6 100644 --- a/utils/gen_library_base.rb +++ b/utils/gen_library_base.rb @@ -417,6 +417,7 @@ def add(member) if @type && @type != member.type.name raise "Mixed bitfield types (#{@type} vs #{member.type.name}) not supported" end + @type ||= member.type.name @count += member.num_bits end