Skip to content

Commit 360c030

Browse files
authored
Merge pull request #136 from JuliaGPU/vc/features
Add support for features
2 parents aae609b + abc775e commit 360c030

File tree

6 files changed

+58
-22
lines changed

6 files changed

+58
-22
lines changed

Project.toml

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AMDGPU"
22
uuid = "21141c5a-9bdb-4563-92ae-f87d6854732e"
33
authors = ["Julian P Samaroo <jpsamaroo@jpsamaroo.me>"]
4-
version = "0.2.6"
4+
version = "0.2.7"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -27,23 +27,11 @@ Adapt = "3.0"
2727
BinaryProvider = "0.5"
2828
CEnum = "0.2, 0.3, 0.4"
2929
GPUArrays = "6"
30-
GPUCompiler = "0.10, 0.11"
30+
GPUCompiler = "0.11.5"
3131
LLVM = "3"
3232
MacroTools = "0.5"
3333
Requires = "1"
3434
Setfield = "0.5, 0.6, 0.7"
3535
hsa_rocr_jll = "3.7"
3636
hsakmt_roct_jll = "3.7"
3737
julia = "1.6"
38-
39-
[extras]
40-
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
41-
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
42-
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
43-
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
44-
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
45-
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
46-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
47-
48-
[targets]
49-
test = ["FFTW", "FillArrays", "ForwardDiff", "InteractiveUtils", "Pkg", "SpecialFunctions", "Test"]

src/agent.jl

+31-5
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,41 @@ function isas(agent::HSAAgent)
189189
HSA.agent_iterate_isas(agent.agent, func, isas) |> check
190190
isas[]
191191
end
192-
function get_first_isa_string(agent::HSAAgent)
193-
isa = first(isas(agent))
192+
193+
# TODO: PCRE regexes are not thread-safe
194+
const isa_regex = r"([a-z]*)-([a-z]*)-([a-z]*)--([a-z0-9]*)([a-zA-Z0-9+\-:]*)"
195+
function parse_isa(isa::HSA.ISA)
194196
len = Ref{Cuint}(0)
195197
getinfo(isa, HSA.ISA_INFO_NAME_LENGTH, len) |> check
196-
name = repeat(" ", len[])
198+
name = Vector{UInt8}(undef, len[])
197199
getinfo(isa, HSA.ISA_INFO_NAME, name) |> check
198-
isa_name = string(rstrip(last(split(name, "-")), '\0'))
199-
return isa_name
200+
name = String(name)
201+
m = match(isa_regex, name)
202+
@assert m !== nothing "Failed to match ISA name pattern: $name"
203+
m
200204
end
205+
206+
function llvm_arch_features(isa::HSA.ISA)
207+
m = parse_isa(isa)
208+
arch = m.captures[4]
209+
features = join(map(x->x[1:end-1],
210+
filter(x->!isempty(x) && (x[end]=='+'),
211+
split(m.captures[5], ':'))),
212+
",+")
213+
if !isempty(features)
214+
features = '+'*features
215+
end
216+
if Base.libllvm_version < v"12"
217+
features = replace(features, "sramecc"=>"sram-ecc")
218+
end
219+
return (arch, features)
220+
end
221+
architecture(isa::HSA.ISA) = llvm_arch_features(isa)[1]
222+
features(isa::HSA.ISA) = llvm_arch_features(isa)[2]
223+
224+
get_first_isa_string(agent::HSAAgent) = architecture(first(isas(agent)))
225+
get_first_feature_string(agent::HSAAgent) = features(first(isas(agent)))
226+
201227
function max_group_size(isa::HSA.ISA)
202228
size = Ref{UInt32}(0)
203229
getinfo(isa, HSA.ISA_INFO_WORKGROUP_MAX_SIZE, size)

src/execution.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ function definitions change, or when different types or keyword arguments are pr
298298
function rocfunction(f::Core.Function, tt::Type=Tuple{}; name=nothing, device=default_device(), global_hooks=NamedTuple(), kwargs...)
299299
source = FunctionSpec(f, tt, true, name)
300300
cache = get!(()->Dict{UInt,Any}(), rocfunction_cache, device)
301-
target = GCNCompilerTarget(; dev_isa=default_isa(device))
301+
agent = device.device
302+
isa = default_isa(device)
303+
arch = architecture(isa)
304+
feat = features(isa)
305+
target = GCNCompilerTarget(; dev_isa=arch, features=feat)
302306
params = ROCCompilerParams(device, global_hooks)
303307
job = CompilerJob(target, source, params)
304308
GPUCompiler.cached_compilation(cache, job, rocfunction_compile, rocfunction_link)::HostKernel{f,tt}

src/reflection.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ for method in (:code_typed, :code_warntype, :code_llvm, :code_native)
1414
function $method(io::IO, @nospecialize(func), @nospecialize(types);
1515
kernel::Bool=false, device=default_device(), kwargs...)
1616
source = FunctionSpec(func, Base.to_tuple_type(types), kernel)
17-
target = GCNCompilerTarget(; dev_isa=default_isa(device))
17+
isa = default_isa(device)
18+
arch = architecture(isa)
19+
feat = features(isa)
20+
target = GCNCompilerTarget(; dev_isa=arch,features=feat)
1821
params = ROCCompilerParams(device, NamedTuple())
1922
job = CompilerJob(target, source, params)
2023
GPUCompiler.$method($(args...); kwargs...)

src/runtime.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ default_queue(::typeof(HSA_rt), device::RuntimeDevice) =
1414
get_device(queue::RuntimeQueue{HSAQueue}) = RuntimeDevice(queue.queue.agent)
1515

1616
default_isa(device::RuntimeDevice{HSAAgent}) =
17-
get_first_isa_string(device.device)
17+
first(isas(device.device))
1818

1919
struct RuntimeEvent{E}
2020
event::E

test/Project.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[deps]
2+
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
3+
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
4+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
5+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
6+
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
7+
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
8+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
9+
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
10+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
11+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
12+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
13+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
14+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
15+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

0 commit comments

Comments
 (0)