Compare commits

..

17 Commits

Author SHA1 Message Date
David Mak ad1f0abb55 standalone: Add math tests for non-number arguments 2023-10-16 16:06:01 +08:00
David Mak c780cf849b core: Rework gamma/gammaln to match SciPy behavior
Matches behavior for infinities and NaNs.
2023-10-16 16:06:01 +08:00
David Mak 82453c78e8 core: Replace TopLevelDef comments with documentation 2023-10-16 16:06:01 +08:00
David Mak d111ed8104 core: Implement numpy and scipy functions 2023-10-16 16:06:01 +08:00
David Mak 33e40db0f0 core: Implement and expose {isinf,isnan} 2023-10-16 16:06:01 +08:00
David Mak d76709e092 flake: Add scipy 2023-10-16 16:06:01 +08:00
David Mak 3ed60d8518 core: Add create_fn_by_* functions
Used for abstracting the creation of function from different sources.
2023-10-16 16:06:01 +08:00
David Mak 1897c175c4 core: Do not cast floor/ceil result to int
NumPy explicitly states that the return type of the floor/ceil is float.
2023-10-16 16:06:01 +08:00
David Mak a13686d4b3 core: Remove {ceil64,floor64,round,round64}
These are not present in NumPy or Artiq.
2023-10-16 16:06:01 +08:00
David Mak e9295b9d1a standalone: Do not output sign if float is NaN
Matches behavior in Python.
2023-10-16 16:06:01 +08:00
David Mak 73500c9081 core: Remove lazy_static from dependencies 2023-10-16 15:55:10 +08:00
David Mak 9ca34c714e flake: Enable thread-safe mode for LLVM
This is required as we use the LLVM APIs from multiple threads.
2023-10-16 15:55:10 +08:00
David Mak 7fc2a30c14 Force single-threaded compilation if LLVM is not thread-safe 2023-10-16 15:55:10 +08:00
David Mak 950f431483 standalone: Update help text for `--emit-llvm` 2023-10-16 15:52:51 +08:00
David Mak a50c690428 standalone: Fix run_demo script
- Link main and module*.bc together if using multiple threads
- Fix temporary files not being deleted
2023-10-16 15:52:48 +08:00
David Mak 48eb64403f standalone: Treat -T0 as using all available threads 2023-10-13 14:57:16 +08:00
David Mak 2c44b58bb8 standalone: Require use of `-T` for specifying thread count 2023-10-13 14:36:34 +08:00
7 changed files with 32 additions and 13 deletions

1
Cargo.lock generated
View File

@ -673,7 +673,6 @@ dependencies = [
"inkwell",
"insta",
"itertools 0.11.0",
"lazy_static",
"nac3parser",
"parking_lot",
"rayon",

View File

@ -9,6 +9,7 @@ use inkwell::{
memory_buffer::MemoryBuffer,
module::{Linkage, Module},
passes::PassBuilderOptions,
support::is_multithreaded,
targets::*,
OptimizationLevel,
};
@ -582,7 +583,8 @@ impl Nac3 {
membuffer.lock().push(buffer);
})));
let size_t = if self.isa == Isa::Host { 64 } else { 32 };
let thread_names: Vec<String> = (0..4).map(|_| "main".to_string()).collect();
let num_threads = if is_multithreaded() { 4 } else { 1 };
let thread_names: Vec<String> = (0..num_threads).map(|_| "main".to_string()).collect();
let threads: Vec<_> = thread_names
.iter()
.map(|s| Box::new(ArtiqCodeGenerator::new(s.to_string(), size_t, self.time_fns)))

View File

@ -10,7 +10,6 @@ crossbeam = "0.8"
parking_lot = "0.12"
rayon = "1.5"
nac3parser = { path = "../nac3parser" }
lazy_static = "1.4"
[dependencies.inkwell]
version = "0.2"

View File

@ -31,9 +31,8 @@ else
nac3standalone=../../target/x86_64-unknown-linux-gnu/release/nac3standalone
fi
rm -f ./*.o ./*.bc demo
if [ -z "$use_lli" ]; then
rm -f "*.o" demo
$nac3standalone "${nac3args[@]}"
clang -c -std=gnu11 -Wall -Wextra -O3 -o demo.o demo.c
@ -45,15 +44,17 @@ if [ -z "$use_lli" ]; then
./demo > "$outfile"
fi
else
rm -f "*.o" "*.bc" demo
$nac3standalone --emit-llvm "${nac3args[@]}"
clang -c -std=gnu11 -Wall -Wextra -O3 -emit-llvm -o demo.bc demo.c
shopt -s nullglob
llvm-link -o nac3out.bc module*.bc main.bc
shopt -u nullglob
if [ -z "$outfile" ]; then
lli --extra-module demo.bc --extra-module irrt.bc main.bc
lli --extra-module demo.bc --extra-module irrt.bc nac3out.bc
else
lli --extra-module demo.bc --extra-module irrt.bc main.bc > "$outfile"
lli --extra-module demo.bc --extra-module irrt.bc nac3out.bc > "$outfile"
fi
fi

View File

@ -2,6 +2,7 @@ use clap::Parser;
use inkwell::{
memory_buffer::MemoryBuffer,
passes::PassBuilderOptions,
support::is_multithreaded,
targets::*,
OptimizationLevel,
};
@ -38,8 +39,9 @@ struct CommandLineArgs {
/// The name of the input file.
file_name: String,
/// The number of threads allocated to processing the source file.
#[arg(default_value_t = 1)]
/// The number of threads allocated to processing the source file. If 0 is passed to this
/// parameter, all available threads will be used for compilation.
#[arg(short = 'T', default_value_t = 1)]
threads: u32,
/// The level to optimize the LLVM IR.
@ -47,6 +49,8 @@ struct CommandLineArgs {
opt_level: u32,
/// Whether to emit LLVM IR at the end of every module.
///
/// If multithreaded compilation is also enabled, each thread will emit its own module.
#[arg(long, default_value_t = false)]
emit_llvm: bool,
@ -207,6 +211,20 @@ fn main() {
.map(|arg| if arg == "native" { host_target_machine.cpu.clone() } else { arg })
.unwrap_or_default();
let target_features = target_features.unwrap_or_default();
let threads = if is_multithreaded() {
if threads == 0 {
std::thread::available_parallelism()
.map(|threads| threads.get() as u32)
.unwrap_or(1u32)
} else {
threads
}
} else {
if threads != 1 {
println!("Warning: Number of threads specified in command-line but multithreading is disabled in LLVM at build time! Defaulting to single-threaded compilation")
}
1
};
let opt_level = match opt_level {
0 => OptimizationLevel::None,
1 => OptimizationLevel::Less,

View File

@ -112,7 +112,7 @@ in stdenv.mkDerivation (rec {
"-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_ENABLE_UNWIND_TABLES=OFF"
"-DLLVM_ENABLE_THREADS=OFF"
"-DLLVM_ENABLE_THREADS=ON"
"-DLLVM_INCLUDE_BENCHMARKS=OFF"
"-DLLVM_BUILD_TOOLS=OFF"
"-DLLVM_TARGETS_TO_BUILD=X86;ARM;RISCV"

View File

@ -65,7 +65,7 @@ in rec {
${silenceFontconfig}
mkdir build
cd build
wine64 cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_THREADS=OFF -DLLVM_TARGETS_TO_BUILD=X86\;ARM\;RISCV -DLLVM_LINK_LLVM_DYLIB=OFF -DLLVM_ENABLE_FFI=OFF -DFFI_INCLUDE_DIR=fck-cmake -DFFI_LIBRARY_DIR=fck-cmake -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_INSTALL_PREFIX=Z:$out
wine64 cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_THREADS=ON -DLLVM_TARGETS_TO_BUILD=X86\;ARM\;RISCV -DLLVM_LINK_LLVM_DYLIB=OFF -DLLVM_ENABLE_FFI=OFF -DFFI_INCLUDE_DIR=fck-cmake -DFFI_LIBRARY_DIR=fck-cmake -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_INSTALL_PREFIX=Z:$out
'';
buildPhase =
''