add nalgebra::linalg methods #478

Merged
sb10q merged 1 commits from support_nalgebra into master 2024-08-17 17:37:21 +08:00
3 changed files with 67 additions and 23 deletions
Showing only changes of commit 669c6aca6b - Show all commits

View File

@ -6,6 +6,7 @@
outputs = { self, nixpkgs }: outputs = { self, nixpkgs }:
let let
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };
pkgs32 = import nixpkgs { system = "i686-linux"; };
in rec { in rec {
packages.x86_64-linux = rec { packages.x86_64-linux = rec {
llvm-nac3 = pkgs.callPackage ./nix/llvm {}; llvm-nac3 = pkgs.callPackage ./nix/llvm {};
@ -15,6 +16,22 @@
ln -s ${pkgs.llvmPackages_14.clang-unwrapped}/bin/clang $out/bin/clang-irrt ln -s ${pkgs.llvmPackages_14.clang-unwrapped}/bin/clang $out/bin/clang-irrt
ln -s ${pkgs.llvmPackages_14.llvm.out}/bin/llvm-as $out/bin/llvm-as-irrt ln -s ${pkgs.llvmPackages_14.llvm.out}/bin/llvm-as $out/bin/llvm-as-irrt
''; '';
demo-linalg-stub = pkgs.rustPlatform.buildRustPackage {
name = "demo-linalg-stub";
src = ./nac3standalone/demo/linalg;
cargoLock = {
lockFile = ./nac3standalone/demo/linalg/Cargo.lock;
};
doCheck = false;
};
demo-linalg-stub32 = pkgs32.rustPlatform.buildRustPackage {
name = "demo-linalg-stub32";
src = ./nac3standalone/demo/linalg;
cargoLock = {
lockFile = ./nac3standalone/demo/linalg/Cargo.lock;
};
doCheck = false;
};
nac3artiq = pkgs.python3Packages.toPythonModule ( nac3artiq = pkgs.python3Packages.toPythonModule (
pkgs.rustPlatform.buildRustPackage rec { pkgs.rustPlatform.buildRustPackage rec {
name = "nac3artiq"; name = "nac3artiq";
@ -32,7 +49,9 @@
echo "Checking nac3standalone demos..." echo "Checking nac3standalone demos..."
pushd nac3standalone/demo pushd nac3standalone/demo
patchShebangs . patchShebangs .
./check_demos.sh export DEMO_LINALG_STUB=${demo-linalg-stub}/lib/liblinalg.a
export DEMO_LINALG_STUB32=${demo-linalg-stub32}/lib/liblinalg.a
./check_demos.sh -i686
popd popd
echo "Running Cargo tests..." echo "Running Cargo tests..."
cargoCheckHook cargoCheckHook
@ -162,6 +181,11 @@
pre-commit pre-commit
rustfmt rustfmt
]; ];
shellHook =
''
export DEMO_LINALG_STUB=${packages.x86_64-linux.demo-linalg-stub}/lib/liblinalg.a
export DEMO_LINALG_STUB32=${packages.x86_64-linux.demo-linalg-stub32}/lib/liblinalg.a
'';
}; };
devShells.x86_64-linux.msys2 = pkgs.mkShell { devShells.x86_64-linux.msys2 = pkgs.mkShell {
name = "nac3-dev-shell-msys2"; name = "nac3-dev-shell-msys2";

View File

@ -3,26 +3,49 @@
set -e set -e
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "Requires at least one argument" echo "No argument supplied"
exit 1 exit 1
fi fi
declare -a nac3args declare -a nac3args
while [ $# -ge 2 ]; do
case "$1" in
--help)
echo "Usage: check_demo.sh [-i686] -- demo [NAC3ARGS...]"
exit
;;
-i686)
i686=1
;;
--)
shift
break
;;
*)
break
;;
esac
shift
done
demo="$1"
shift
while [ $# -gt 1 ]; do while [ $# -gt 1 ]; do
nac3args+=("$1") nac3args+=("$1")
shift shift
done done
demo="$1"
echo "### Checking $demo..." echo "### Checking $demo..."
# Get reference output
echo ">>>>>> Running $demo with the Python interpreter" echo ">>>>>> Running $demo with the Python interpreter"
Outdated
Review

Removing LLI should (1) be done more thoroughly, we don't want to drag dead code along (2) be a separate PR.

Removing LLI should (1) be done more thoroughly, we don't want to drag dead code along (2) be a separate PR.

Since we can't really link a static library with lli it won't be able to run the new functions and the tests will fail. Generating DSO and linking using that should work though.

Since we can't really link a static library with `lli` it won't be able to run the new functions and the tests will fail. Generating DSO and linking using that should work though.
Outdated
Review

Yes, let's just remove the LLI tests entirely.

Yes, let's just remove the LLI tests entirely.
./interpret_demo.py "$demo" > interpreted.log ./interpret_demo.py "$demo" > interpreted.log
echo "...... Trying NAC3's 32-bit code generator output" if [ -n "$i686" ]; then
./run_demo.sh -i386 --out run_32.log "${nac3args[@]}" "$demo" echo "...... Trying NAC3's 32-bit code generator output"
diff -Nau interpreted.log run_32.log ./run_demo.sh -i686 --out run_32.log "${nac3args[@]}" "$demo"
diff -Nau interpreted.log run_32.log
fi
echo "...... Trying NAC3's 64-bit code generator output" echo "...... Trying NAC3's 64-bit code generator output"
./run_demo.sh --out run_64.log "${nac3args[@]}" "$demo" ./run_demo.sh --out run_64.log "${nac3args[@]}" "$demo"
@ -31,4 +54,4 @@ diff -Nau interpreted.log run_64.log
echo "...... OK" echo "...... OK"
rm -f interpreted.log \ rm -f interpreted.log \
run_32.log run_64.log run_32.log run_64.log

View File

@ -2,6 +2,9 @@
set -e set -e
: "${DEMO_LINALG_STUB:=linalg/target/release/liblinalg.a}"
: "${DEMO_LINALG_STUB32:=linalg/target/i686-unknown-linux-gnu/release/liblinalg.a}"
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "No argument supplied" echo "No argument supplied"
exit 1 exit 1
@ -11,7 +14,7 @@ declare -a nac3args
while [ $# -ge 1 ]; do while [ $# -ge 1 ]; do
case "$1" in case "$1" in
--help) --help)
echo "Usage: run_demo.sh [--help] [--out OUTFILE] [--debug] [-i386] -- [NAC3ARGS...]" echo "Usage: run_demo.sh [--help] [--out OUTFILE] [--debug] [-i686] -- [NAC3ARGS...]"
exit exit
;; ;;
--out) --out)
@ -21,8 +24,8 @@ while [ $# -ge 1 ]; do
--debug) --debug)
debug=1 debug=1
;; ;;
-i386) -i686)
i386=1 i686=1
;; ;;
--) --)
shift shift
@ -51,20 +54,14 @@ fi
rm -f ./*.o ./*.bc demo rm -f ./*.o ./*.bc demo
if [ -z "$i386" ]; then if [ -z "$i686" ]; then
$nac3standalone "${nac3args[@]}" $nac3standalone "${nac3args[@]}"
cd linalg && cargo build --release --target x86_64-unknown-linux-gnu -q && cd ..
clang -c -std=gnu11 -Wall -Wextra -O3 -o demo.o demo.c clang -c -std=gnu11 -Wall -Wextra -O3 -o demo.o demo.c
clang -lm -Wl,--no-warn-search-mismatch -o demo module.o demo.o linalg/target/x86_64-unknown-linux-gnu/release/liblinalg.a clang -o demo module.o demo.o $DEMO_LINALG_STUB -lm -Wl,--no-warn-search-mismatch
Outdated
Review

Can you really pass a DSO to clang and get it linked in?

Can you really pass a DSO to clang and get it linked in?
Outdated
Review

Anyway I would just make it a static lib.

Anyway I would just make it a static lib.
else else
# Enable SSE2 to avoid rounding errors with X87's 80-bit fp precision computations $nac3standalone --triple i686-unknown-linux-gnu "${nac3args[@]}"
clang -m32 -c -std=gnu11 -Wall -Wextra -O3 -msse2 -o demo.o demo.c
$nac3standalone --triple i386-pc-linux-gnu --target-features +sse2 "${nac3args[@]}" clang -m32 -o demo module.o demo.o $DEMO_LINALG_STUB32 -lm -Wl,--no-warn-search-mismatch
cd linalg && cargo build --release --target i686-unknown-linux-gnu -q && cd ..
clang -m32 -c -std=gnu11 -Wall -Wextra -O3 -msse2 -o demo.o demo.c
clang -m32 -lm -Wl,--no-warn-search-mismatch -o demo module.o demo.o linalg/target/i686-unknown-linux-gnu/release/liblinalg.a
fi fi
Outdated
Review

indentation

indentation
Outdated
Review

But nevermind I'll fix it

But nevermind I'll fix it
if [ -z "$outfile" ]; then if [ -z "$outfile" ]; then