tilework-hip 0.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/ext/tilework/hip/bridge.cpp +1067 -0
- data/ext/tilework/hip/extconf.rb +66 -0
- data/ext/tilework/hip/gpu_bridge.c +840 -0
- data/lib/tilework/backend/hip.rb +21 -0
- metadata +65 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# HIPRTC is a separate ROCm library. Test the headers and both shared
|
|
4
|
+
# libraries, rather than treating the presence of hipcc as sufficient.
|
|
5
|
+
require "rbconfig"
|
|
6
|
+
|
|
7
|
+
hdrdir = RbConfig::CONFIG["rubyhdrdir"]
|
|
8
|
+
archhdrdir = RbConfig::CONFIG["rubyarchhdrdir"]
|
|
9
|
+
dlext = RbConfig::CONFIG["DLEXT"]
|
|
10
|
+
cc = RbConfig::CONFIG["CC"]
|
|
11
|
+
cxx = RbConfig::CONFIG["CXX"] || "c++"
|
|
12
|
+
srcdir = File.expand_path(__dir__)
|
|
13
|
+
rocm_home = ENV["ROCM_HOME"] || "/opt/rocm"
|
|
14
|
+
include_dir = "#{rocm_home}/include"
|
|
15
|
+
lib_dirs = ["#{rocm_home}/lib", "#{rocm_home}/lib64"].select { |d| Dir.exist?(d) }
|
|
16
|
+
have_headers = File.file?("#{include_dir}/hip/hip_runtime_api.h") && File.file?("#{include_dir}/hip/hiprtc.h")
|
|
17
|
+
have_runtime = lib_dirs.any? { |d| File.exist?("#{d}/libamdhip64.so") }
|
|
18
|
+
have_hiprtc = lib_dirs.any? { |d| File.exist?("#{d}/libhiprtc.so") }
|
|
19
|
+
have_hipblas = File.file?("#{include_dir}/hipblas/hipblas.h") &&
|
|
20
|
+
lib_dirs.any? { |d| File.exist?("#{d}/libhipblas.so") }
|
|
21
|
+
have_hiprand = File.file?("#{include_dir}/hiprand/hiprand.h") &&
|
|
22
|
+
lib_dirs.any? { |d| File.exist?("#{d}/libhiprand.so") }
|
|
23
|
+
have_hipfft = File.file?("#{include_dir}/hipfft/hipfft.h") &&
|
|
24
|
+
lib_dirs.any? { |d| File.exist?("#{d}/libhipfft.so") }
|
|
25
|
+
have_miopen = File.file?("#{include_dir}/miopen/miopen.h") &&
|
|
26
|
+
lib_dirs.any? { |d| File.exist?("#{d}/libMIOpen.so") }
|
|
27
|
+
have_ruby_headers = File.file?("#{hdrdir}/ruby.h") && File.file?("#{archhdrdir}/ruby/config.h")
|
|
28
|
+
|
|
29
|
+
if have_headers && have_runtime && have_hiprtc && have_ruby_headers
|
|
30
|
+
ldflags = lib_dirs.map { |d| "-L#{d}" }.join(" ")
|
|
31
|
+
hipblas_cxxflags = have_hipblas ? " -DTILEWORK_HAS_HIPBLAS" : ""
|
|
32
|
+
hipblas_ldlibs = have_hipblas ? " -lhipblas" : ""
|
|
33
|
+
hiprand_cxxflags = have_hiprand ? " -DTILEWORK_HAS_HIPRAND" : ""
|
|
34
|
+
hiprand_ldlibs = have_hiprand ? " -lhiprand" : ""
|
|
35
|
+
hipfft_cxxflags = have_hipfft ? " -DTILEWORK_HAS_HIPFFT" : ""
|
|
36
|
+
hipfft_ldlibs = have_hipfft ? " -lhipfft" : ""
|
|
37
|
+
miopen_cxxflags = have_miopen ? " -DTILEWORK_HAS_MIOPEN" : ""
|
|
38
|
+
miopen_ldlibs = have_miopen ? " -lMIOpen" : ""
|
|
39
|
+
File.write("Makefile", <<~MAKEFILE)
|
|
40
|
+
TARGET = bridge.#{dlext}
|
|
41
|
+
CC = #{cc}
|
|
42
|
+
CXX = #{cxx}
|
|
43
|
+
CFLAGS = -O2 -Wall -fPIC -DTILEWORK_BRIDGE_MODULE=\\\"HIPBridge\\\" -I#{hdrdir} -I#{archhdrdir}
|
|
44
|
+
CXXFLAGS = -O2 -Wall -Wextra -fPIC -std=c++17 -D__HIP_PLATFORM_AMD__#{hipblas_cxxflags}#{hiprand_cxxflags}#{hipfft_cxxflags}#{miopen_cxxflags} -I#{include_dir}
|
|
45
|
+
LDLIBS = #{ldflags} -lamdhip64 -lhiprtc#{hipblas_ldlibs}#{hiprand_ldlibs}#{hipfft_ldlibs}#{miopen_ldlibs} -pthread
|
|
46
|
+
SRCDIR = #{srcdir}
|
|
47
|
+
all: $(TARGET)
|
|
48
|
+
gpu_bridge.o: $(SRCDIR)/gpu_bridge.c
|
|
49
|
+
\t$(CC) $(CFLAGS) -c $(SRCDIR)/gpu_bridge.c -o $@
|
|
50
|
+
bridge_hip.o: $(SRCDIR)/bridge.cpp
|
|
51
|
+
\t$(CXX) $(CXXFLAGS) -c $(SRCDIR)/bridge.cpp -o $@
|
|
52
|
+
$(TARGET): gpu_bridge.o bridge_hip.o
|
|
53
|
+
\t$(CXX) -shared gpu_bridge.o bridge_hip.o $(LDLIBS) -o $@
|
|
54
|
+
clean:
|
|
55
|
+
\trm -f $(TARGET) gpu_bridge.o bridge_hip.o
|
|
56
|
+
sitearchdir = .
|
|
57
|
+
install: $(TARGET)
|
|
58
|
+
\tmkdir -p $(sitearchdir)/tilework/hip
|
|
59
|
+
\tcp $(TARGET) $(sitearchdir)/tilework/hip/$(TARGET)
|
|
60
|
+
.PHONY: all clean install
|
|
61
|
+
MAKEFILE
|
|
62
|
+
puts "created Makefile (HIP backend, #{rocm_home}; hipBLAS #{have_hipblas ? "enabled" : "not found"}, hipRAND #{have_hiprand ? "enabled" : "not found"}, hipFFT #{have_hipfft ? "enabled" : "not found"}, MIOpen #{have_miopen ? "enabled" : "not found"})"
|
|
63
|
+
else
|
|
64
|
+
File.write("Makefile", "all:\ninstall:\nclean:\n.PHONY: all install clean\n")
|
|
65
|
+
puts "skipping tilework/hip build (missing Ruby development headers or HIP Runtime/HIPRTC under #{rocm_home}; set ROCM_HOME)"
|
|
66
|
+
end
|