Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate librocsolver.jl with Clang.jl #617

Merged
merged 4 commits into from
Sep 30, 2024
Merged
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
1 change: 1 addition & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
4 changes: 4 additions & 0 deletions gen/hip/generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# #if defined(__HIP_PLATFORM_AMD__) && !defined(__HIP_PLATFORM_NVIDIA__)

using Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")
hip_dir = joinpath(include_dir, "hip")
Expand All @@ -22,3 +23,6 @@ headers = [

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

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
4 changes: 4 additions & 0 deletions gen/miopen/generator.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")
miopen_dir = joinpath(include_dir, "miopen")
Expand All @@ -15,3 +16,6 @@ headers = [

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

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
3 changes: 3 additions & 0 deletions gen/miopen/miopen-generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ library_name = "libMIOpen_path"
output_file_path = "./libMIOpen.jl"
jll_pkg_name = "MIOpen_jll"
export_symbol_prefixes = []

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

include_dir = normpath("/opt/rocm/include")
rocblas_dir = joinpath(include_dir, "rocblas")
Expand All @@ -15,3 +16,6 @@ headers = [

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

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
3 changes: 3 additions & 0 deletions gen/rocblas/rocblas-generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
library_name = "librocblas"
output_file_path = "./librocblas.jl"
export_symbol_prefixes = []

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

include_dir = normpath("/opt/rocm/include")
rocfft_dir = joinpath(include_dir, "rocfft")
Expand All @@ -15,3 +16,6 @@ headers = [

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

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
3 changes: 3 additions & 0 deletions gen/rocfft/rocfft-generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
library_name = "librocfft"
output_file_path = "./librocfft.jl"
export_symbol_prefixes = []

[codegen]
use_ccall_macro = true
25 changes: 23 additions & 2 deletions gen/rocsolver/generator.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Clang.Generators
# NOTE: for this to work, in opt/rocm/include/rocsolver/rocsolver-functions.h
# replace all occurrences of "ROCSOLVER_EXPORT " by "".

using Clang, Clang.Generators
using JuliaFormatter

include_dir = normpath("/opt/rocm/include")

Expand All @@ -15,4 +19,21 @@ headers = [
]

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

# Only keep the wrapped headers because the dependencies are already wrapped with other headers.
replace!(get_nodes(ctx.dag)) do node
path = Clang.get_filename(node.cursor)
should_wrap = any(headers) do header
occursin(header, path)
end
if !should_wrap
return ExprNode(node.id, Generators.Skip(), node.cursor, Expr[], node.adj)
end
return node
end

build!(ctx, BUILDSTAGE_PRINTING_ONLY)

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
3 changes: 3 additions & 0 deletions gen/rocsolver/rocsolver-generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
library_name = "librocsolver"
output_file_path = "./librocsolver.jl"
export_symbol_prefixes = []

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

include_dir = normpath("/opt/rocm/include")
rocsparse_dir = joinpath(include_dir, "rocsparse")
Expand All @@ -15,3 +16,6 @@ headers = [

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

path = options["general"]["output_file_path"]
format_file(path, YASStyle())
3 changes: 3 additions & 0 deletions gen/rocsparse/rocsparse-generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
library_name = "librocsparse"
output_file_path = "./librocsparse.jl"
export_symbol_prefixes = []

[codegen]
use_ccall_macro = true
Loading