Skip to content

Commit 9045916

Browse files
authored
Continue h2yaml migration, cuda no more patch (#486)
* Simplify futher more cuda path * Support anonymous union and enum * No more cuda header! * Add vdpau.h stub * Add README.md * Fix anonymous enum who have a typedef * Refactoring arguably cleaner
1 parent 5956c13 commit 9045916

File tree

8 files changed

+47
-139
lines changed

8 files changed

+47
-139
lines changed

backends/cuda/Makefile.am

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,15 @@ CLEANFILES = \
6666
$(BTX_CUDA_GENERATED) &: $(top_srcdir)/xprof/btx_interval_model.yaml btx_cudamatching_model.yaml btx_cuda_model.yaml
6767
$(METABABEL) -u btx_cuda_model.yaml -d $(top_srcdir)/xprof/btx_interval_model.yaml -t FILTER -o btx_filter_cuda -p cudainterval -c interval --matching $(srcdir)/btx_cudamatching_model.yaml -i cuda.h.include
6868

69-
$(MODIFIED_CUDA_HDR) &: $(CUDA_HDR) $(srcdir)/headers.patch
69+
$(MODIFIED_CUDA_HDR) &: $(CUDA_HDR)
7070
$(RM) -r modified_include/
7171
cp -r $(srcdir)/include/ modified_include/
7272
chmod -R u+w modified_include/
73-
cat $(srcdir)/headers.patch | patch -i - -d modified_include/ -s -p1
7473

7574
clean-local:
7675
$(RM) -r modified_include
7776

78-
EXTRA_DIST += $(srcdir)/include headers.patch
77+
EXTRA_DIST += $(srcdir)/include
7978

8079
CUDA_EXTRACT_H = $(srcdir)/extract/cuda_api.h $(srcdir)/extract/cudart_api.h
8180
EXTRA_DIST += $(CUDA_EXTRACT_H)

backends/cuda/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CUDA Backend
2+
3+
## VDPAU Stub
4+
5+
The CUDA SDK includes interop headers (`cudaVDPAU.h`, `cuda_vdpau_interop.h`) that reference VDPAU types (`VdpDevice`, `VdpGetProcAddress`, etc.) from `<vdpau/vdpau.h>`. This system header is not always available.
6+
7+
A stub is provided in `include/vdpau/vdpau.h` that defines the necessary VDPAU types so that the CUDA tracer can compiled.

backends/cuda/extract/cuda_api.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
#define __CUDA_API_VERSION_INTERNAL = 1
2-
#define THAPI_NO_INCLUDE
32

43
#include <stdint.h>
54

65
#include <cuda.h>
76

8-
typedef int32_t VdpStatus;
9-
typedef uint32_t VdpFuncId;
10-
typedef uint32_t VdpDevice;
11-
typedef VdpStatus
12-
VdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_pointer);
13-
typedef uint32_t VdpVideoSurface;
14-
typedef uint32_t VdpOutputSurface;
7+
#include <vdpau/vdpau.h>
158

169
#include <cudaVDPAU.h>
1710

backends/cuda/extract/cudart_api.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
#define __CUDA_API_VERSION_INTERNAL = 1
2-
#define THAPI_NO_INCLUDE
32

43
#include <stdint.h>
54

65
#include <cuda_runtime_api.h>
76

87
#include <__cudart.h>
98

10-
typedef int32_t VdpStatus;
11-
typedef uint32_t VdpFuncId;
12-
typedef uint32_t VdpDevice;
13-
typedef VdpStatus
14-
VdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_pointer);
15-
typedef uint32_t VdpVideoSurface;
16-
typedef uint32_t VdpOutputSurface;
17-
189
#include <cuda_vdpau_interop.h>
1910

2011
#include <cuda_profiler_api.h>

backends/cuda/gen_cuda_exports_extract.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
puts <<~EOF
77
#define __CUDA_API_VERSION_INTERNAL=1
8-
#define THAPI_NO_INCLUDE
98
#include <cuda.h>
109
EOF
1110

backends/cuda/headers.patch

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Stub for VDPAU types used by CUDA interop headers. */
2+
#ifndef THAPI_VDPAU_STUB_H
3+
#define THAPI_VDPAU_STUB_H
4+
5+
#include <stdint.h>
6+
7+
typedef int32_t VdpStatus;
8+
typedef uint32_t VdpFuncId;
9+
typedef uint32_t VdpDevice;
10+
typedef VdpStatus VdpGetProcAddress(VdpDevice device, VdpFuncId function_id,
11+
void **function_pointer);
12+
typedef uint32_t VdpVideoSurface;
13+
typedef uint32_t VdpOutputSurface;
14+
15+
#endif

utils/gen_library_base.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
require_relative 'yaml_ast'
22

3+
def has_typedef?(name)
4+
$all_types.any? { |t| t.type.respond_to?(:name) && t.type.name == name }
5+
end
6+
37
def to_ffi_name(name, default = true)
48
case name
59
when nil
@@ -337,18 +341,27 @@ module Composite
337341
def to_ffi
338342
unamed_count = 0
339343
members.map do |m|
340-
mt = if m.type.is_a?(Array)
344+
mt = case m.type
345+
when Array
341346
m.type.to_ffi
342-
elsif m.type.is_a?(Pointer)
347+
when Pointer
343348
':pointer'
344-
elsif m.type.name
345-
to_ffi_name(m.type.name)
346-
elsif m.type.is_a?(Struct)
347-
"(Class::new(#{FFI_STRUCT}) { layout #{gen_layout(m.type.to_ffi)} }.by_value)"
348-
elsif m.type.is_a?(Union)
349-
"(Class::new(#{FFI_UNION}) { layout #{gen_layout(m.type.to_ffi)} }.by_value)"
349+
when Struct
350+
if m.type.name && has_typedef?(m.type.name)
351+
to_ffi_name(m.type.name)
352+
else
353+
s = m.type.name ? $all_structs.find { |st| st.name == m.type.name } : m.type
354+
"(Class::new(#{FFI_STRUCT}) { layout #{gen_layout(s.to_ffi)} }.by_value)"
355+
end
356+
when Union
357+
if m.type.name && has_typedef?(m.type.name)
358+
to_ffi_name(m.type.name)
359+
else
360+
u = m.type.name ? $all_unions&.find { |un| un.name == m.type.name } : m.type
361+
"(Class::new(#{FFI_UNION}) { layout #{gen_layout(u.to_ffi)} }.by_value)"
362+
end
350363
else
351-
raise "unknown type: #{m.type}"
364+
m.type.name ? to_ffi_name(m.type.name) : raise("unknown type: #{m.type}")
352365
end
353366
[m.name ? m.name.to_sym.inspect : ":_unamed_#{unamed_count += 1}", mt]
354367
end

0 commit comments

Comments
 (0)