Skip to content

Commit

Permalink
Merge pull request #136 from JuliaGPU/vc/features
Browse files Browse the repository at this point in the history
Add support for features
  • Loading branch information
jpsamaroo authored May 20, 2021
2 parents aae609b + abc775e commit 360c030
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
16 changes: 2 additions & 14 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AMDGPU"
uuid = "21141c5a-9bdb-4563-92ae-f87d6854732e"
authors = ["Julian P Samaroo <[email protected]>"]
version = "0.2.6"
version = "0.2.7"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand All @@ -27,23 +27,11 @@ Adapt = "3.0"
BinaryProvider = "0.5"
CEnum = "0.2, 0.3, 0.4"
GPUArrays = "6"
GPUCompiler = "0.10, 0.11"
GPUCompiler = "0.11.5"
LLVM = "3"
MacroTools = "0.5"
Requires = "1"
Setfield = "0.5, 0.6, 0.7"
hsa_rocr_jll = "3.7"
hsakmt_roct_jll = "3.7"
julia = "1.6"

[extras]
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["FFTW", "FillArrays", "ForwardDiff", "InteractiveUtils", "Pkg", "SpecialFunctions", "Test"]
36 changes: 31 additions & 5 deletions src/agent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,41 @@ function isas(agent::HSAAgent)
HSA.agent_iterate_isas(agent.agent, func, isas) |> check
isas[]
end
function get_first_isa_string(agent::HSAAgent)
isa = first(isas(agent))

# TODO: PCRE regexes are not thread-safe
const isa_regex = r"([a-z]*)-([a-z]*)-([a-z]*)--([a-z0-9]*)([a-zA-Z0-9+\-:]*)"
function parse_isa(isa::HSA.ISA)
len = Ref{Cuint}(0)
getinfo(isa, HSA.ISA_INFO_NAME_LENGTH, len) |> check
name = repeat(" ", len[])
name = Vector{UInt8}(undef, len[])
getinfo(isa, HSA.ISA_INFO_NAME, name) |> check
isa_name = string(rstrip(last(split(name, "-")), '\0'))
return isa_name
name = String(name)
m = match(isa_regex, name)
@assert m !== nothing "Failed to match ISA name pattern: $name"
m
end

function llvm_arch_features(isa::HSA.ISA)
m = parse_isa(isa)
arch = m.captures[4]
features = join(map(x->x[1:end-1],
filter(x->!isempty(x) && (x[end]=='+'),
split(m.captures[5], ':'))),
",+")
if !isempty(features)
features = '+'*features
end
if Base.libllvm_version < v"12"
features = replace(features, "sramecc"=>"sram-ecc")
end
return (arch, features)
end
architecture(isa::HSA.ISA) = llvm_arch_features(isa)[1]
features(isa::HSA.ISA) = llvm_arch_features(isa)[2]

get_first_isa_string(agent::HSAAgent) = architecture(first(isas(agent)))
get_first_feature_string(agent::HSAAgent) = features(first(isas(agent)))

function max_group_size(isa::HSA.ISA)
size = Ref{UInt32}(0)
getinfo(isa, HSA.ISA_INFO_WORKGROUP_MAX_SIZE, size)
Expand Down
6 changes: 5 additions & 1 deletion src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ function definitions change, or when different types or keyword arguments are pr
function rocfunction(f::Core.Function, tt::Type=Tuple{}; name=nothing, device=default_device(), global_hooks=NamedTuple(), kwargs...)
source = FunctionSpec(f, tt, true, name)
cache = get!(()->Dict{UInt,Any}(), rocfunction_cache, device)
target = GCNCompilerTarget(; dev_isa=default_isa(device))
agent = device.device
isa = default_isa(device)
arch = architecture(isa)
feat = features(isa)
target = GCNCompilerTarget(; dev_isa=arch, features=feat)
params = ROCCompilerParams(device, global_hooks)
job = CompilerJob(target, source, params)
GPUCompiler.cached_compilation(cache, job, rocfunction_compile, rocfunction_link)::HostKernel{f,tt}
Expand Down
5 changes: 4 additions & 1 deletion src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ for method in (:code_typed, :code_warntype, :code_llvm, :code_native)
function $method(io::IO, @nospecialize(func), @nospecialize(types);
kernel::Bool=false, device=default_device(), kwargs...)
source = FunctionSpec(func, Base.to_tuple_type(types), kernel)
target = GCNCompilerTarget(; dev_isa=default_isa(device))
isa = default_isa(device)
arch = architecture(isa)
feat = features(isa)
target = GCNCompilerTarget(; dev_isa=arch,features=feat)
params = ROCCompilerParams(device, NamedTuple())
job = CompilerJob(target, source, params)
GPUCompiler.$method($(args...); kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ default_queue(::typeof(HSA_rt), device::RuntimeDevice) =
get_device(queue::RuntimeQueue{HSAQueue}) = RuntimeDevice(queue.queue.agent)

default_isa(device::RuntimeDevice{HSAAgent}) =
get_first_isa_string(device.device)
first(isas(device.device))

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

2 comments on commit 360c030

@jpsamaroo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/37143

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.7 -m "<description of version>" 360c0304c24e24a84b40f3f86a4e418515adbd10
git push origin v0.2.7

Please sign in to comment.