Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gen/hip/hip-generator.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[general]
library_name = "libhip"
output_file_path = "./libhip.jl"
output_file_path = "../src/hip/libhip.jl"
output_ignorelist = [
"__HOST_DEVICE__"
"__HOST_DEVICE__",
"HIP_DEPRECATED_MSG",
]

[codegen]
Expand Down
46 changes: 44 additions & 2 deletions gen/miopen/generator.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")
include_dir = normpath(joinpath(ENV["ROCM_PATH"], "include"))
miopen_dir = joinpath(include_dir, "miopen")
options = load_options("miopen/miopen-generator.toml")

Expand All @@ -15,7 +15,49 @@ headers = [
]

ctx = create_context(headers, args, options)
build!(ctx)

# build without printing so we can do custom rewriting
build!(ctx, BUILDSTAGE_NO_PRINTING)

const no_prepare_state = Set([
:miopenGetErrorString,
:miopenGetVersion,
])

# custom rewriter
function rewrite!(e::Expr)
(e.head === :function && Meta.isexpr(e.args[1], :call)) || return e
f = e.args[1].args[1]
if !(f isa Symbol)
@assert f in (:(Base.getproperty), :(Base.setproperty!), :(Base.propertynames))
return e
end
stmts = e.args[2].args
map!(stmts, stmts) do ex
Meta.isexpr(ex, :macrocall) || return ex
ex.args[1] === Symbol("@ccall") || return ex
# TODO: should this be `@gcsafe_ccall`?
# ex.args[1] = Symbol("@gcsafe_ccall")
Expr(:macrocall, Symbol("@check"), nothing, ex)
end
if !(f in no_prepare_state)
pushfirst!(stmts, :(AMDGPU.prepare_state()))
end
return e
end

function rewrite!(dag::ExprDAG)
for node in get_nodes(dag)
for expr in get_exprs(node)
rewrite!(expr)
end
end
end

rewrite!(ctx.dag)

# print
build!(ctx, BUILDSTAGE_PRINTING_ONLY)

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
14 changes: 11 additions & 3 deletions gen/miopen/miopen-generator.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[general]
module_name = "libMIOpen"
library_name = "libMIOpen_path"
output_file_path = "./libMIOpen.jl"
jll_pkg_name = "MIOpen_jll"
output_file_path = "../src/dnn/libMIOpen.jl"
export_symbol_prefixes = []
output_ignorelist = [
"miopenAcceleratorQueue_t",
"MIOPEN_DEPRECATED_EXPORT",
"MIOPEN_DEPRECATED_NO_EXPORT",
"MIOPEN_INTERNALS_DEPRECATED_EXPORT",
"MIOPEN_INTERNALS_DEPRECATED_NO_EXPORT",
"MIOPEN_VERSION_TWEAK",
"MIOPEN_USE_GEMM",
"MIOPEN_INSTALLABLE",
]

[codegen]
use_ccall_macro = true
39 changes: 37 additions & 2 deletions gen/rocblas/generator.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")
include_dir = normpath(joinpath(ENV["ROCM_PATH"], "include"))
rocblas_dir = joinpath(include_dir, "rocblas")
options = load_options("rocblas/rocblas-generator.toml")

Expand All @@ -15,7 +15,42 @@ headers = [
]

ctx = create_context(headers, args, options)
build!(ctx)

# build without printing so we can do custom rewriting
build!(ctx, BUILDSTAGE_NO_PRINTING)

# custom rewriter
function rewrite!(e::Expr)
(e.head === :function && Meta.isexpr(e.args[1], :call)) || return e
f = e.args[1].args[1]
if !(f isa Symbol)
@assert f in (:(Base.getproperty), :(Base.setproperty!), :(Base.propertynames))
return e
end
stmts = e.args[2].args
map!(stmts, stmts) do ex
Meta.isexpr(ex, :macrocall) || return ex
ex.args[1] === Symbol("@ccall") || return ex
# TODO: should this be `@gcsafe_ccall`?
# ex.args[1] = Symbol("@gcsafe_ccall")
Expr(:macrocall, Symbol("@check"), nothing, ex)
end
pushfirst!(stmts, :(AMDGPU.prepare_state()))
return e
end

function rewrite!(dag::ExprDAG)
for node in get_nodes(dag)
for expr in get_exprs(node)
rewrite!(expr)
end
end
end

rewrite!(ctx.dag)

# print
build!(ctx, BUILDSTAGE_PRINTING_ONLY)

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
15 changes: 14 additions & 1 deletion gen/rocblas/rocblas-generator.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
[general]
library_name = "librocblas"
output_file_path = "./librocblas.jl"
output_file_path = "../src/blas/librocblas.jl"
export_symbol_prefixes = []
print_using_CEnum = false
output_ignorelist = [
"hipEvent_t",
"ihipEvent_t",
"hipStream_t",
"ihipStream_t",
"rocblas_half",
"rocblas_float_complex",
"rocblas_double_complex",
"ROCBLAS_DEPRECATED_EXPORT",
"ROCBLAS_DEPRECATED_NO_EXPORT",
"ROCBLAS_INTERNAL_EXPORT",
"ROCBLAS_VERSION_TWEAK",
]

[codegen]
use_ccall_macro = true
56 changes: 52 additions & 4 deletions gen/rocfft/generator.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,69 @@
using Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")
include_dir = normpath(joinpath(ENV["ROCM_PATH"], "include"))
rocfft_dir = joinpath(include_dir, "rocfft")
options = load_options("rocfft/rocfft-generator.toml")

args = get_default_args()
push!(args, "-I$include_dir")

# copy rocfft headers to temp dir and prepend `#include <stddef.h>`
rocfft_tempdir = mktempdir()
cp(rocfft_dir, rocfft_tempdir; force=true)

headers = [
joinpath(rocfft_dir, header)
for header in readdir(rocfft_dir)
joinpath(rocfft_tempdir, header)
for header in readdir(rocfft_tempdir)
if endswith(header, ".h")
]

for header in headers
filepath = joinpath(rocfft_tempdir, basename(header))
open(filepath, "r+") do io
content = read(io, String)
seekstart(io)
write(io, "#include <stddef.h>\n" * content)
end
end

ctx = create_context(headers, args, options)
build!(ctx)

# build without printing so we can do custom rewriting
build!(ctx, BUILDSTAGE_NO_PRINTING)

# custom rewriter
function rewrite!(e::Expr)
(e.head === :function && Meta.isexpr(e.args[1], :call)) || return e
f = e.args[1].args[1]
if !(f isa Symbol)
@assert f in (:(Base.getproperty), :(Base.setproperty!), :(Base.propertynames))
return e
end
stmts = e.args[2].args
map!(stmts, stmts) do ex
Meta.isexpr(ex, :macrocall) || return ex
ex.args[1] === Symbol("@ccall") || return ex
# TODO: should this be `@gcsafe_ccall`?
# ex.args[1] = Symbol("@gcsafe_ccall")
Expr(:macrocall, Symbol("@check"), nothing, ex)
end
pushfirst!(stmts, :(AMDGPU.prepare_state()))
return e
end

function rewrite!(dag::ExprDAG)
for node in get_nodes(dag)
for expr in get_exprs(node)
rewrite!(expr)
end
end
end

rewrite!(ctx.dag)

# print
build!(ctx, BUILDSTAGE_PRINTING_ONLY)

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
7 changes: 6 additions & 1 deletion gen/rocfft/rocfft-generator.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
[general]
library_name = "librocfft"
output_file_path = "./librocfft.jl"
output_file_path = "../src/fft/librocfft.jl"
export_symbol_prefixes = []
print_using_CEnum = false
output_ignorelist = [
"ROCFFT_DEPRECATED_EXPORT",
"ROCFFT_DEPRECATED_NO_EXPORT",
"rocfft_version_tweak",
]

[codegen]
use_ccall_macro = true
36 changes: 33 additions & 3 deletions gen/rocsolver/generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using Clang, Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")
rocblas_dir = joinpath(include_dir, "rocblas", "internal")
include_dir = normpath(joinpath(ENV["ROCM_PATH"], "include"))
rocblas_dir = joinpath(include_dir, "rocblas")#, "internal")
rocsolver_dir = joinpath(include_dir, "rocsolver")
options = load_options("rocsolver/rocsolver-generator.toml")

args = get_default_args()
push!(args, "-I$rocsolver_dir", "-I$rocblas_dir", "-DROCSOLVER_EXPORT")
push!(args, "-I$include_dir", "-DROCSOLVER_EXPORT=")

headers_rocsolver = [
joinpath(rocsolver_dir, header)
Expand Down Expand Up @@ -40,6 +40,36 @@ replace!(get_nodes(ctx.dag)) do node
return node
end

# custom rewriter
function rewrite!(e::Expr)
(e.head === :function && Meta.isexpr(e.args[1], :call)) || return e
f = e.args[1].args[1]
if !(f isa Symbol)
@assert f in (:(Base.getproperty), :(Base.setproperty!), :(Base.propertynames))
return e
end
stmts = e.args[2].args
map!(stmts, stmts) do ex
Meta.isexpr(ex, :macrocall) || return ex
ex.args[1] === Symbol("@ccall") || return ex
# TODO: should this be `@gcsafe_ccall`?
# ex.args[1] = Symbol("@gcsafe_ccall")
Expr(:macrocall, Symbol("@check"), nothing, ex)
end
pushfirst!(stmts, :(AMDGPU.prepare_state()))
return e
end

function rewrite!(dag::ExprDAG)
for node in get_nodes(dag)
for expr in get_exprs(node)
rewrite!(expr)
end
end
end

rewrite!(ctx.dag)

build!(ctx, BUILDSTAGE_PRINTING_ONLY)

path = options["general"]["output_file_path"]
Expand Down
7 changes: 6 additions & 1 deletion gen/rocsolver/rocsolver-generator.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
[general]
library_name = "librocsolver"
output_file_path = "./librocsolver.jl"
output_file_path = "../src/solver/librocsolver.jl"
export_symbol_prefixes = []
print_using_CEnum = false
output_ignorelist = [
"ROCSOLVER_DEPRECATED_EXPORT",
"ROCSOLVER_DEPRECATED_NO_EXPORT",
"ROCSOLVER_VERSION_TWEAK",
]

[codegen]
use_ccall_macro = true
39 changes: 37 additions & 2 deletions gen/rocsparse/generator.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")
include_dir = normpath(joinpath(ENV["ROCM_PATH"], "include"))
rocsparse_dir = joinpath(include_dir, "rocsparse")
options = load_options("rocsparse/rocsparse-generator.toml")

Expand All @@ -15,7 +15,42 @@ headers = [
]

ctx = create_context(headers, args, options)
build!(ctx)

# build without printing so we can do custom rewriting
build!(ctx, BUILDSTAGE_NO_PRINTING)

# custom rewriter
function rewrite!(e::Expr)
(e.head === :function && Meta.isexpr(e.args[1], :call)) || return e
f = e.args[1].args[1]
if !(f isa Symbol)
@assert f in (:(Base.getproperty), :(Base.setproperty!), :(Base.propertynames))
return e
end
stmts = e.args[2].args
map!(stmts, stmts) do ex
Meta.isexpr(ex, :macrocall) || return ex
ex.args[1] === Symbol("@ccall") || return ex
# TODO: should this be `@gcsafe_ccall`?
# ex.args[1] = Symbol("@gcsafe_ccall")
Expr(:macrocall, Symbol("@check"), nothing, ex)
end
pushfirst!(stmts, :(AMDGPU.prepare_state()))
return e
end

function rewrite!(dag::ExprDAG)
for node in get_nodes(dag)
for expr in get_exprs(node)
rewrite!(expr)
end
end
end

rewrite!(ctx.dag)

# print
build!(ctx, BUILDSTAGE_PRINTING_ONLY)

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
11 changes: 10 additions & 1 deletion gen/rocsparse/rocsparse-generator.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
[general]
library_name = "librocsparse"
output_file_path = "./librocsparse.jl"
output_file_path = "../src/sparse/librocsparse.jl"
export_symbol_prefixes = []
print_using_CEnum = false
output_ignorelist = [
"hipStream_t",
"ihipStream_t",
"rocsparse_status_",
"rocsparse_status",
"ROCSPARSE_DEPRECATED_EXPORT",
"ROCSPARSE_DEPRECATED_NO_EXPORT",
"ROCSPARSE_VERSION_TWEAK",
]

[codegen]
use_ccall_macro = true
Loading