Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
sweep-cache: true

- name: Run clippy lints
run: SLANG_DIR=$SLANG_DIR cargo clippy --locked --workspace --all-targets -- --deny warnings
run: SLANG_DIR=$SLANG_DIR cargo clippy --locked --workspace --all-targets --features runtime -- --deny warnings

# Check documentation.
doc:
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
sweep-cache: true

- name: Check documentation
run: SLANG_DIR=$SLANG_DIR cargo doc --locked --workspace --document-private-items --no-deps
run: SLANG_DIR=$SLANG_DIR cargo doc --locked --workspace --document-private-items --features runtime --no-deps
# Testing.
test:
needs: setup-slang # Depends on setup-slang
Expand Down Expand Up @@ -163,4 +163,4 @@ jobs:
sweep-cache: true
- name: Run Cargo Tests
run: |
SLANG_DIR=$SLANG_DIR LIBGL_ALWAYS_SOFTWARE=1 cargo test --verbose
SLANG_DIR=$SLANG_DIR LIBGL_ALWAYS_SOFTWARE=1 cargo test --verbose --features runtime
4 changes: 2 additions & 2 deletions .run/Check.run.xml → .run/Check (runtime).run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Check" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
<configuration default="false" name="Check (runtime)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="buildProfileId" value="dev" />
<option name="command" value="check" />
<option name="command" value="check --features runtime" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
Expand Down
20 changes: 15 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@ name = "stensor"
authors = ["Sébastien Crozet <sebcrozet@dimforge.com>"]
description = "Cross-platform GPU tensor library with Slang and Rust."
repository = "https://github.com/dimforge/stensor"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
license = "Apache-2.0"

[features]
comptime = [ "slang-hal/comptime" ]
runtime = [ "slang-hal/runtime" ]

webgpu = [ "slang-hal/webgpu" ]
vulkan = [ "slang-hal/vulkan" ]
metal = [ "slang-hal/metal" ]
cpu = [ "slang-hal/cpu" ]
cuda = [ "cudarc", "slang-hal/cuda" ]
cublas = [ "slang-hal/cublas" ]

[dependencies]
wgpu = "27"
encase = "0.12"
bytemuck = "1"
nalgebra = { version = "0.34", features = ["encase"] }

cudarc = { version = "0.16", optional = true }

minislang = "0.2"
slang-hal = { version = "0.2", features = ["derive"] }
slang-hal = { version = "0.3", features = ["derive"] }
include_dir = "0.7"

[dev-dependencies]
minislang = "0.3"
nalgebra = { version = "0.34", features = ["rand"] }
futures-test = "0.3"
serial_test = "3"
Expand All @@ -32,12 +38,16 @@ async-std = { version = "1", features = ["attributes"] }
plotly = "0.12.1"
indexmap = "2"
anyhow = "1"
wgpu = "27"

[build-dependencies]
minislang = "0.1"
minislang = "0.3"
slang-hal-build = "0.3"
include_dir = "0.7"

[patch.crates-io]
#shader-slang = { path = "../slang-rs" }
#minislang = { path = "../slang-hal/crates/minislang" }
#slang-hal-build = { path = "../slang-hal/crates/slang-hal-build" }
#slang-hal-derive = { path = "../slang-hal/crates/slang-hal-derive" }
#slang-hal = { path = "../slang-hal/crates/slang-hal" }
31 changes: 19 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
use minislang::{SlangCompiler, shader_slang::CompileTarget};
use std::path::PathBuf;
use std::str::FromStr;
#[cfg(feature = "comptime")]
use std::env;

#[cfg(not(feature = "comptime"))]
pub fn main() {}

#[cfg(feature = "comptime")]
pub fn main() {
let slang = SlangCompiler::new(vec![PathBuf::from_str("./shaders").unwrap()]);
use slang_hal_build::ShaderCompiler;

const SLANG_SRC_DIR: include_dir::Dir<'_> =
include_dir::include_dir!("$CARGO_MANIFEST_DIR/shaders");

let targets = [
CompileTarget::Wgsl,
#[cfg(feature = "cuda")]
CompileTarget::CudaSource,
];
let out_dir = env::var("OUT_DIR").expect("Couldn't determine output directory.");
let mut compiler = ShaderCompiler::new(vec![], &out_dir);
compiler.add_dir(SLANG_SRC_DIR);

for target in targets {
slang.compile_all(target, "../shaders", "./src/autogen", &[]);
}
// Compile all shaders from examples/shaders directory.
// Note: slang-hal-build will automatically detect which backends to compile for
// based on the cargo features enabled during the build.
compiler
.compile_shaders_dir("shaders", &[])
.expect("Failed to compile shaders");
}
4 changes: 2 additions & 2 deletions examples/gemm_bench.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use indexmap::IndexMap;
use minislang::SlangCompiler;
use nalgebra::DMatrix;
use slang_hal::Shader;
use slang_hal::backend::WebGpu;
use slang_hal::backend::{Backend, Encoder};
use slang_hal::{BufferUsages, Shader};
use stensor::linalg::{Gemm, GemmVariant};
use stensor::shapes::ViewShapeBuffers;
use stensor::tensor::GpuTensor;
use wgpu::{BufferUsages, Features, Limits};
use wgpu::{Features, Limits};

#[async_std::main]
async fn main() -> anyhow::Result<()> {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

pub use geometry::*;
pub use linalg::*;

use minislang::SlangCompiler;
use slang_hal::SlangCompiler;

pub mod geometry;
pub mod linalg;
Expand All @@ -15,7 +14,8 @@ pub mod tensor;

// pub mod utils;

const SLANG_SRC_DIR: include_dir::Dir<'_> =
/// Directory of slang shaders from `stensor`.
pub const SLANG_SRC_DIR: include_dir::Dir<'_> =
include_dir::include_dir!("$CARGO_MANIFEST_DIR/shaders");

/// Register all the shaders from this crate (and its dependencies) as modules accessible to the
Expand Down
4 changes: 2 additions & 2 deletions src/linalg/contiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ mod test {
use crate::tensor::GpuTensor;
use minislang::SlangCompiler;
use nalgebra::DMatrix;
use slang_hal::Shader;
use slang_hal::backend::WebGpu;
use slang_hal::backend::{Backend, Encoder};
use wgpu::{BufferUsages, Features, Limits};
use slang_hal::{BufferUsages, Shader};
use wgpu::{Features, Limits};

#[futures_test::test]
#[serial_test::serial]
Expand Down
4 changes: 2 additions & 2 deletions src/linalg/gemm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ mod test {
use approx::relative_eq;
use minislang::SlangCompiler;
use nalgebra::DMatrix;
use slang_hal::Shader;
use slang_hal::backend::{Backend, Encoder, WebGpu};
use wgpu::{BufferUsages, Features, Limits};
use slang_hal::{BufferUsages, Shader};
use wgpu::{Features, Limits};

#[futures_test::test]
#[serial_test::serial]
Expand Down
4 changes: 2 additions & 2 deletions src/linalg/gemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ mod test {
use approx::assert_relative_eq;
use minislang::SlangCompiler;
use nalgebra::{DMatrix, DVector};
use slang_hal::Shader;
use slang_hal::backend::WebGpu;
use slang_hal::backend::{Backend, Encoder};
use wgpu::{BufferUsages, Features, Limits};
use slang_hal::{BufferUsages, Shader};
use wgpu::{Features, Limits};

#[futures_test::test]
#[serial_test::serial]
Expand Down
2 changes: 1 addition & 1 deletion src/linalg/op_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ mod test {
use crate::tensor::GpuTensor;
use minislang::SlangCompiler;
use nalgebra::DVector;
use slang_hal::BufferUsages;
use slang_hal::backend::WebGpu;
use slang_hal::backend::{Backend, Buffer, Encoder};
use slang_hal::shader::Shader;
use wgpu::BufferUsages;

#[futures_test::test]
#[serial_test::serial]
Expand Down
3 changes: 1 addition & 2 deletions src/linalg/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ mod test {
use crate::tensor::GpuTensor;
use minislang::SlangCompiler;
use nalgebra::DVector;
use slang_hal::ShaderArgs;
use slang_hal::backend::WebGpu;
use slang_hal::backend::{Backend, Encoder};
use slang_hal::shader::Shader;
use wgpu::BufferUsages;
use slang_hal::{BufferUsages, ShaderArgs};

#[derive(ShaderArgs)]
pub struct ReduceArgs<'a, B: Backend> {
Expand Down
2 changes: 1 addition & 1 deletion src/shapes.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Tensor shape definition.

use slang_hal::BufferUsages;
use slang_hal::backend::Backend;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::sync::Mutex;
use wgpu::BufferUsages;

/// GGML dimension index mapping: converts between GGML and stensor dimension ordering.
pub const GGML_IDS: [usize; 4] = [1, 0, 2, 3];
Expand Down
3 changes: 1 addition & 2 deletions src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ use std::ops::{Bound, RangeBounds};
use std::sync::Arc;

use slang_hal::backend::WebGpu;
use wgpu::BufferUsages;

#[cfg(feature = "cuda")]
use crate::cuda::Cuda;
use slang_hal::ShaderArgs;
use slang_hal::shader::ShaderArgsError;
use slang_hal::{BufferUsages, ShaderArgs};

/// Helper struct for creating gpu storage buffers (scalars, vectors, matrices, tensors).
pub struct TensorBuilder {
Expand Down