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

Get lib example working, create build script #55104

Merged
merged 1 commit into from
Jul 15, 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
69 changes: 0 additions & 69 deletions juliac/lib_examples/liblinsolve.jl

This file was deleted.

9 changes: 9 additions & 0 deletions juliac/lib_examples/linsolve/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
OpenBLAS_jll = "4536629a-c528-5b80-bd46-f80d51c5b363"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"
12 changes: 12 additions & 0 deletions juliac/lib_examples/linsolve/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash
if [ ! -f Manifest.toml ]; then
echo "Instantiating package environment..."
../../../julia --project -e 'using Pkg; Pkg.instantiate()'
echo "done"
fi
echo "Building library..."
../../../julia --project ../../juliac.jl --output-lib liblinsolve --compile-ccallable --static-call-graph liblinsolve.jl
echo "done"
echo "Linking C main..."
gcc -o linsolve10 -L. -Wl,-rpath,\$ORIGIN ../../test/test.c -llinsolve
echo "done"
13 changes: 13 additions & 0 deletions juliac/lib_examples/linsolve/liblinsolve.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Lib

using LinearAlgebra

Base.@ccallable function linsolve10(A_ptr::Ptr{Float64}, b_ptr::Ptr{Float64}, N::Csize_t)::Ptr{Float64}
A = unsafe_wrap(Array, A_ptr, (N,N))
b = unsafe_wrap(Array, b_ptr, N)
F = lu!(A)
ldiv!(F, b)
return b_ptr
end

end
5 changes: 3 additions & 2 deletions juliac/test/test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>

double* linsolve10(double *A, double *b);
double* linsolve10(double * A, double * b, size_t N);

int main() {
// Declare a 10x10 matrix
double A[10][10] = {
Expand All @@ -27,7 +28,7 @@ int main() {
-10.107200370651855,
0.8478731362967014};

linsolve10(A, b);
linsolve10((double*)A, (double*)b, 10);
for (int i = 0; i < 10; i++) {
printf("%f\n", b[i]);
}
Expand Down