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

Update the generator of Julia wrappers #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.logamgx
/Manifest.toml
/docs/build/
/gen/Manifest.toml
8 changes: 8 additions & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
AMGX_jll = "656d14af-56e4-5275-8e68-4e861d7b5043"
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"

[compat]
AMGX_jll = "2.4"
julia = "1.10"
15 changes: 15 additions & 0 deletions gen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wrapping headers

This directory contains a script `wrapper.jl` that can be used to automatically
generate wrappers from C headers of NVIDIA AMGX.
This is done using Clang.jl.

In AMGX.jl, the wrappers need to know whether pointers passed into the
library point to CPU or GPU memory (i.e. `Ptr` or `CuPtr`). This information is
not available from the headers, and instead should be provided by the developer.
The specific information is embedded in the TOML file `amgx.toml`.

# Usage

Either run `julia wrapper.jl` directly, or include it and call the `main()` function.
Be sure to activate the project environment in this folder (`julia --project`), which will install `Clang.jl` and `JuliaFormatter.jl`.
9 changes: 9 additions & 0 deletions gen/amgx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[general]
library_name = "libAMGX"
print_using_CEnum = false
output_file_path = "../lib/libamgx.jl"

[codegen]
use_julia_bool = true
use_ccall_macro = true
always_NUL_terminated_string = true
32 changes: 32 additions & 0 deletions gen/wrapper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# generate AMGX wrappers
using Clang
using Clang.Generators

using JuliaFormatter
using AMGX_jll


function main()
amgx = joinpath(AMGX_jll.artifact_dir, "include")
@assert AMGX_jll.is_available()

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

options = load_options(joinpath(@__DIR__, "amgx.toml"))

# create context
headers = ["$amgx/amgx_config.h", "$amgx/amgx_c.h"]
targets = headers

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

output_file = options["general"]["output_file_path"]
format_file(output_file, YASStyle())
return nothing
end

if abspath(PROGRAM_FILE) == @__FILE__
main()
end
286 changes: 0 additions & 286 deletions lib/libAMGX.jl

This file was deleted.

195 changes: 0 additions & 195 deletions lib/libAMGX_common.jl

This file was deleted.

Loading