arrayfire / arrayfire-rust

Rust wrapper for ArrayFire
BSD 3-Clause "New" or "Revised" License
810 stars 58 forks source link

Feature Request: Double Precision on M1 #317

Closed alvarozamora closed 2 years ago

alvarozamora commented 2 years ago

Description

I tried using these rust bindings for arrayfire for 3D FFTs on M1. They are blazing fast, but currently only support Complex<f32>'s. Are there plans for Complex<f64>'s? Would love to use double precision.

Currently, I get

ArrayFire v3.7.2 (OpenCL, 64-bit Mac OSX, build 218dd2c99)
[0] APPLE: Apple M1, 10922 MB
(0, 0, 0, 0)
thread 'main' panicked at 'Error message: This device does not support double
Last error: In function void opencl::(anonymous namespace)::verifyTypeSupport()
In file src/backend/opencl/Array.cpp:66
Double precision not supported
 0# void opencl::(anonymous namespace)::verifyTypeSupport<cl_double2>() in /opt/arrayfire/lib/libafopencl.3.7.2.dylib
 1# opencl::Array<cl_double2> opencl::createHostDataArray<cl_double2>(af::dim4 const&, cl_double2 const*) in /opt/arrayfire/lib/libafopencl.3.7.2.dylib
 2# af_create_array in /opt/arrayfire/lib/libafopencl.3.7.2.dylib
 3# fft::main::hef05f9d92e3c9e1e in /Users/alvarozamora/Rust/projects/MSM/rust/tests/arrayfire-rust/target/release/fft
 4# std::sys_common::backtrace::__rust_begin_short_backtrace::h74b2d801dab15ffa in /Users/alvarozamora/Rust/projects/MSM/rust/tests/arrayfire-rust/target/release/fft
 5# std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h935c212161ca3661 in /Users/alvarozamora/Rust/projects/MSM/rust/tests/arrayfire-rust/target/release/fft
 6# std::rt::lang_start_internal::hb851dbed3d6fc79c in /Users/alvarozamora/Rust/projects/MSM/rust/tests/a', src/core/error.rs:37:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
(base) alvarozamora@Alvaros-MacBook-Pro arrayfire-rust % RUST_BACKTRACE=full cargo +nightly run --bin fft --release
warning: unused variable: `dims`
  --> src/bin/fft.rs:12:9
   |
12 |     let dims = Dim4::new(&[FFT_SIZE, 1, 1, 1]);
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_dims`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `arrayfire` (bin "fft") generated 1 warning
    Finished release [optimized] target(s) in 0.05s
     Running `target/release/fft`
ArrayFire v3.7.2 (OpenCL, 64-bit Mac OSX, build 218dd2c99)
[0] APPLE: Apple M1, 10922 MB
(0, 0, 0, 0)
thread 'main' panicked at 'Error message: This device does not support double
Last error: In function void opencl::(anonymous namespace)::verifyTypeSupport()
In file src/backend/opencl/Array.cpp:66
Double precision not supported
 0# void opencl::(anonymous namespace)::verifyTypeSupport<cl_double2>() in /opt/arrayfire/lib/libafopencl.3.7.2.dylib
 1# opencl::Array<cl_double2> opencl::createHostDataArray<cl_double2>(af::dim4 const&, cl_double2 const*) in /opt/arrayfire/lib/libafopencl.3.7.2.dylib
 2# af_create_array in /opt/arrayfire/lib/libafopencl.3.7.2.dylib
 3# fft::main::hef05f9d92e3c9e1e in /Users/alvarozamora/Rust/projects/MSM/rust/tests/arrayfire-rust/target/release/fft
 4# std::sys_common::backtrace::__rust_begin_short_backtrace::h74b2d801dab15ffa in /Users/alvarozamora/Rust/projects/MSM/rust/tests/arrayfire-rust/target/release/fft
 5# std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h935c212161ca3661 in /Users/alvarozamora/Rust/projects/MSM/rust/tests/arrayfire-rust/target/release/fft
 6# std::rt::lang_start_internal::hb851dbed3d6fc79c in /Users/alvarozamora/Rust/projects/MSM/rust/tests/a', src/core/error.rs:37:14
stack backtrace:
   0:        0x1003568d4 - std::backtrace_rs::backtrace::libunwind::trace::h4b9e7930ab493dd8
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x1003568d4 - std::backtrace_rs::backtrace::trace_unsynchronized::h90f7f2bef1f15295
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1003568d4 - std::sys_common::backtrace::_print_fmt::hd51643cce1d46b17
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/sys_common/backtrace.rs:66:5
   3:        0x1003568d4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h24210be00fe9c21b
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/sys_common/backtrace.rs:45:22
   4:        0x10036abeb - core::fmt::write::h1b02938ff5d56460
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/core/src/fmt/mod.rs:1190:17
   5:        0x100354998 - std::io::Write::write_fmt::hc6d42312cf268fd7
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/io/mod.rs:1655:15
   6:        0x10035802d - std::sys_common::backtrace::_print::ha2397536ad6a5f85
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/sys_common/backtrace.rs:48:5
   7:        0x10035802d - std::sys_common::backtrace::print::h9ff493021523224d
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/sys_common/backtrace.rs:35:9
   8:        0x10035802d - std::panicking::default_hook::{{closure}}::h0955af7cf9fb52d4
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:295:22
   9:        0x100357d11 - std::panicking::default_hook::h837b2f55b5a2e9b7
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:314:9
  10:        0x1003585ae - std::panicking::rust_panic_with_hook::h39d92eb91249a487
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:698:17
  11:        0x1003584a3 - std::panicking::begin_panic_handler::{{closure}}::h2e1055c816783fe8
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:588:13
  12:        0x100356d57 - std::sys_common::backtrace::__rust_end_short_backtrace::hf66ecb9a5eb8606d
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/sys_common/backtrace.rs:138:18
  13:        0x10035817a - rust_begin_unwind
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:584:5
  14:        0x1003713b3 - core::panicking::panic_fmt::h3c0028abb198fc69
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/core/src/panicking.rs:143:14
  15:        0x100338e50 - arrayfire::core::error::handle_error_general::h6816b1bfd0eb3c28
  16:        0x100338f02 - arrayfire::core::error::HANDLE_ERROR::hfe70d51561fd68f8
  17:        0x100338637 - fft::main::hef05f9d92e3c9e1e
  18:        0x1003388c6 - std::sys_common::backtrace::__rust_begin_short_backtrace::h74b2d801dab15ffa
  19:        0x1003389dc - std::rt::lang_start::{{closure}}::h935c212161ca3661
  20:        0x10035194a - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h07b3be02e56028f7
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/core/src/ops/function.rs:259:13
  21:        0x10035194a - std::panicking::try::do_call::hf3171d5aeb47a646
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:492:40
  22:        0x10035194a - std::panicking::try::h73cafb2a4a0eff5f
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:456:19
  23:        0x10035194a - std::panic::catch_unwind::h5753cff1059cf95a
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panic.rs:137:14
  24:        0x10035194a - std::rt::lang_start_internal::{{closure}}::h5913c275a45751ec
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/rt.rs:128:48
  25:        0x10035194a - std::panicking::try::do_call::h2619f2152bc356b6
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:492:40
  26:        0x10035194a - std::panicking::try::h6ef704193cb493fb
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panicking.rs:456:19
  27:        0x10035194a - std::panic::catch_unwind::h7d676f77e46fcea9
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/panic.rs:137:14
  28:        0x10035194a - std::rt::lang_start_internal::hb851dbed3d6fc79c
                               at /rustc/f103b2969b0088953873dc1ac92eb3387c753596/library/std/src/rt.rs:128:20
  29:        0x1003388b9 - _main
9prady9 commented 2 years ago

@alvarozamora Unfortunately, I don't think this is even possible. The error stems from the root cause that the OpenCL device itself doesn't have double support as reported by the OpenCL driver for that device. Unless, this changes there is no way double values data can be used on M1.

Just reiterating in another way, this is by no way a restriction on ArrayFire, it is just that Apple's M1 OpenCL driver isn't reporting double support - whether it has one or not is something I am not aware of it. Given that Apple stopped OpenCL support, this won't change in future too.

Another note: Any feature requests are better raised in the upstream project since this is just bindings project for arrayfire.

I am closing this one since this isn't possible in even in a remote future.