Skip to content

Commit 5539bc2

Browse files
committed
wip
1 parent a11030c commit 5539bc2

3 files changed

Lines changed: 44 additions & 22 deletions

File tree

src/compiler/codegen.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@ GPUCompiler.@unlocked function GPUCompiler.mcgen(
6565
output = tempname(cleanup=false) * (filetype == "asm" ? ".s" : ".o")
6666
write(input, mod)
6767

68-
cmd = `$clang_path -x ir $input -mcpu=$(target.dev_isa) --target=$(GPUCompiler.llvm_triple(target)) -nogpulib $(filetype == "asm" ? "-S" : "-c") -o $output`
68+
wavefrontsize64 = if hasproperty(job.config.params, :wavefrontsize64)
69+
job.config.params.wavefrontsize64
70+
else
71+
true # Default fallback
72+
end
73+
74+
devlib_paths = get_device_libs_paths(target; wavefrontsize64)
75+
devlib_flags = String[]
76+
for path in devlib_paths
77+
push!(devlib_flags, "-Xclang", "-mlink-builtin-bitcode", "-Xclang", path)
78+
end
79+
80+
cmd = `$clang_path -x ir $input -mcpu=$(target.dev_isa) --target=$(GPUCompiler.llvm_triple(target)) -nogpulib $devlib_flags $(filetype == "asm" ? "-S" : "-c") -o $output`
6981

7082
try
7183
run(cmd)
@@ -180,7 +192,7 @@ function compiler_config(dev::HIP.HIPDevice;
180192

181193
target = GCNCompilerTarget(; dev_isa, features)
182194
params = HIPCompilerParams(wavefrontsize64, unsafe_fp_atomics)
183-
CompilerConfig(target, params; kernel, name, always_inline=true)
195+
CompilerConfig(target, params; kernel, name, always_inline=true, validate=false)
184196
end
185197

186198
const hipfunction_lock = ReentrantLock()

src/compiler/device_libs.jl

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,28 @@ end
2323

2424
const DEVICE_LIBS::Dict{String, DevLib} = Dict{String, DevLib}()
2525

26-
function link_device_libs!(
27-
target::GCNCompilerTarget, mod::LLVM.Module;
26+
function get_device_libs_paths(
27+
target::GCNCompilerTarget;
2828
wavefrontsize64::Bool,
2929
)
30-
isnothing(libdevice_libs) && return
31-
if !isempty(AMDGPU.ROCmDiscovery.clang_path)
32-
return
33-
end
30+
paths = String[]
31+
isnothing(libdevice_libs) && return paths
3432

3533
# 1. Load other libraries.
3634
lib_names = ("hc", "hip", "irif", "ockl", "opencl", "ocml")
3735
for lib_name in lib_names
38-
devlib = get!(DEVICE_LIBS, lib_name) do
39-
DevLib(lib_name, locate_lib(lib_name))
40-
end
41-
load_and_link!(devlib, mod)
36+
path = locate_lib(lib_name)
37+
!isnothing(path) && push!(paths, path)
4238
end
4339

4440
# 2. Load OCLC library.
45-
devlib = get!(DEVICE_LIBS, "oclc") do
46-
isa_short = replace(target.dev_isa, "gfx"=>"")
47-
DevLib("oclc", locate_lib("oclc_isa_version_$isa_short"))
48-
end
49-
load_and_link!(devlib, mod)
41+
isa_short = replace(target.dev_isa, "gfx"=>"")
42+
path = locate_lib("oclc_isa_version_$isa_short")
43+
!isnothing(path) && push!(paths, path)
5044

5145
# 3. Load OCLC ABI library.
52-
devlib = get!(DEVICE_LIBS, "oclc_abi") do
53-
DevLib("oclc_abi", locate_lib("oclc_abi_version_500"))
54-
end
55-
load_and_link!(devlib, mod)
46+
path = locate_lib("oclc_abi_version_500")
47+
!isnothing(path) && push!(paths, path)
5648

5749
# 4. Load options libraries.
5850
options = (
@@ -65,8 +57,25 @@ function link_device_libs!(
6557
for (option, value) in options
6658
toggle = value ? "on" : "off"
6759
name = "oclc_$(option)_$(toggle)"
60+
path = locate_lib(name)
61+
!isnothing(path) && push!(paths, path)
62+
end
63+
return paths
64+
end
65+
66+
function link_device_libs!(
67+
target::GCNCompilerTarget, mod::LLVM.Module;
68+
wavefrontsize64::Bool,
69+
)
70+
isnothing(libdevice_libs) && return
71+
if !isempty(AMDGPU.ROCmDiscovery.clang_path)
72+
return
73+
end
74+
75+
for path in get_device_libs_paths(target; wavefrontsize64)
76+
name = basename(path)
6877
devlib = get!(DEVICE_LIBS, name) do
69-
DevLib(name, locate_lib(name))
78+
DevLib(name, path)
7079
end
7180
load_and_link!(devlib, mod)
7281
end

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
33
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
4+
AMDGPU = "0c46a032-3f7e-4b1d-8c5a-2e9f6b1d0f3e"
45
BFloat16s = "ab4f0b2a-ad5b-11e8-123f-65d77653426b"
56
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
67
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"

0 commit comments

Comments
 (0)