From 0af3e428ecebb3a27a708b4228edd33ca36e13fb Mon Sep 17 00:00:00 2001 From: Doug A Date: Sat, 1 Feb 2025 18:05:52 -0400 Subject: [PATCH] fix: place `ug` dep behind `not wasm32` flag (#2760) * place `ug` behind not wasm32 attr so that wasm32 can compile * mv `ug` to conditional target dep assuming every non-wasm32 user wants this --- candle-core/Cargo.toml | 7 ++++--- candle-core/src/cuda_backend/device.rs | 1 + candle-core/src/custom_op.rs | 1 + candle-core/src/error.rs | 1 + candle-core/src/metal_backend/device.rs | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/candle-core/Cargo.toml b/candle-core/Cargo.toml index 4ffc869ff8..d5d5bde00c 100644 --- a/candle-core/Cargo.toml +++ b/candle-core/Cargo.toml @@ -14,7 +14,7 @@ accelerate-src = { workspace = true, optional = true } byteorder = { workspace = true } candle-kernels = { workspace = true, optional = true } candle-metal-kernels = { workspace = true, optional = true } -metal = { workspace = true, optional = true} +metal = { workspace = true, optional = true } cudarc = { workspace = true, optional = true } gemm = { workspace = true } half = { workspace = true } @@ -28,18 +28,19 @@ rand_distr = { workspace = true } rayon = { workspace = true } safetensors = { workspace = true } thiserror = { workspace = true } -ug = { workspace = true } ug-cuda = { workspace = true, optional = true } ug-metal = { workspace = true, optional = true } yoke = { workspace = true } zip = { workspace = true } +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +ug = { workspace = true } + [dev-dependencies] anyhow = { workspace = true } clap = { workspace = true } criterion = { workspace = true } - [features] default = [] cuda = ["cudarc", "dep:candle-kernels", "dep:ug-cuda"] diff --git a/candle-core/src/cuda_backend/device.rs b/candle-core/src/cuda_backend/device.rs index d3bd29030e..b9ab434925 100644 --- a/candle-core/src/cuda_backend/device.rs +++ b/candle-core/src/cuda_backend/device.rs @@ -51,6 +51,7 @@ impl CudaDevice { self.device.clone() } + #[cfg(not(target_arch = "wasm32"))] pub fn compile( &self, func_name: &'static str, diff --git a/candle-core/src/custom_op.rs b/candle-core/src/custom_op.rs index c0d97d670a..18d4786eae 100644 --- a/candle-core/src/custom_op.rs +++ b/candle-core/src/custom_op.rs @@ -386,6 +386,7 @@ pub struct UgIOp1 { impl UgIOp1 { #[allow(unused)] + #[cfg(not(target_arch = "wasm32"))] pub fn new( name: &'static str, kernel: ug::lang::ssa::Kernel, diff --git a/candle-core/src/error.rs b/candle-core/src/error.rs index 85a9d23018..5729013be3 100644 --- a/candle-core/src/error.rs +++ b/candle-core/src/error.rs @@ -172,6 +172,7 @@ pub enum Error { #[error("Metal error {0}")] Metal(#[from] MetalError), + #[cfg(not(target_arch = "wasm32"))] #[error(transparent)] Ug(#[from] ug::Error), diff --git a/candle-core/src/metal_backend/device.rs b/candle-core/src/metal_backend/device.rs index fab80d34ec..25523a40c6 100644 --- a/candle-core/src/metal_backend/device.rs +++ b/candle-core/src/metal_backend/device.rs @@ -138,6 +138,7 @@ impl std::ops::Deref for MetalDevice { } impl MetalDevice { + #[cfg(not(target_arch = "wasm32"))] pub fn compile( &self, func_name: &'static str,