Skip to content

Commit

Permalink
Kernels added
Browse files Browse the repository at this point in the history
  • Loading branch information
adityauj committed Sep 11, 2024
1 parent cbaf6c5 commit 305eb8e
Show file tree
Hide file tree
Showing 17 changed files with 666 additions and 4 deletions.
305 changes: 305 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.13", features = ["derive"] }
num_cpus = "1.16.0"
rayon = "1.10.0"

[[bin]]
name = "bench"
path = "src/main.rs"
path = "src/main.rs"

[profile.release]
debug = false
lto = true
# codegen-units = 1
incremental = false
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GIT_HASH := $(shell git rev-parse --short HEAD || echo 'development')
CURRENT_TIME = $(shell date +"%Y-%m-%d:T%H:%M:%S")
LD_FLAGS = '-s -X main.date=${CURRENT_TIME} -X main.version=${VERSION} -X main.commit=${GIT_HASH}'

.PHONY: clean test check $(TARGET)
.PHONY: clean test check install asm $(TARGET)

.NOTPARALLEL:

Expand All @@ -17,12 +17,18 @@ $(TARGET):
# $(info ===> GENERATE swagger)
# @go run github.com/swaggo/swag/cmd/swag init -d ./internal/api,./internal/util -g api.go -o ./api
# @mv ./api/docs.go ./internal/api/docs.go
install:
$(info ===> INSTALL)
@cargo install cargo-asm

asm:
$(info ===> ASM)
@cargo rustc --release -- --emit asm

clean:
$(info ===> CLEAN)
@cargo clean
@rm -f $(TARGET)
@rm perf.data perf.data.old flamegraph.svg

test:
$(info ===> TESTING)
Expand Down
Binary file modified bench
Binary file not shown.
12 changes: 12 additions & 0 deletions src/kernels/copy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::time::Instant;

#[allow(clippy::ptr_arg)]
pub fn copy(c: &mut Vec<f64>, a: &Vec<f64>, n: usize) -> f64 {
let s = Instant::now();

for i in 0..n {
c[i] = a[i];
}

s.elapsed().as_secs_f64()
}
12 changes: 12 additions & 0 deletions src/kernels/daxpy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::time::Instant;

#[allow(clippy::ptr_arg)]
pub fn daxpy(a: &mut Vec<f64>, b: &mut Vec<f64>, scalar: f64, n: usize) -> f64 {
let s = Instant::now();

for i in 0..n {
a[i] += scalar * b[i];
}

s.elapsed().as_secs_f64()
}
12 changes: 12 additions & 0 deletions src/kernels/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::time::Instant;

#[allow(clippy::ptr_arg)]
pub fn init(b: &mut Vec<f64>, scalar: f64, n: usize) -> f64 {
let s = Instant::now();

for i in b.iter_mut().take(n) {
*i = scalar;
}

s.elapsed().as_secs_f64()
}
Loading

0 comments on commit 305eb8e

Please sign in to comment.