From df2b78abd3a7c3727b7af1d7e79b2767cae0ecce Mon Sep 17 00:00:00 2001 From: Pradeep Garigipati Date: Mon, 25 Sep 2023 00:47:02 +0530 Subject: [PATCH] First set of changes to enable OneAPI backend --- examples/unified.rs | 7 +++++++ src/core/array.rs | 3 ++- src/core/backend.rs | 4 ++++ src/core/defines.rs | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/unified.rs b/examples/unified.rs index e70aa5d6d..5fa69b871 100644 --- a/examples/unified.rs +++ b/examples/unified.rs @@ -47,6 +47,13 @@ fn main() { test_backend(); } + if available.contains(&Backend::ONEAPI) { + println!("Evaluating OneAPI Backend..."); + set_backend(Backend::ONEAPI); + println!("There are {} OneAPI compute devices", device_count()); + test_backend(); + } + if available.contains(&Backend::OPENCL) { println!("Evaluating OpenCL Backend..."); set_backend(Backend::OPENCL); diff --git a/src/core/array.rs b/src/core/array.rs index 7ee6579ba..a444c0cd9 100644 --- a/src/core/array.rs +++ b/src/core/array.rs @@ -398,7 +398,8 @@ where match (err_val, ret_val) { (0, 1) => Backend::CPU, (0, 2) => Backend::CUDA, - (0, 3) => Backend::OPENCL, + (0, 4) => Backend::OPENCL, + (0, 8) => Backend::ONEAPI, _ => Backend::DEFAULT, } } diff --git a/src/core/backend.rs b/src/core/backend.rs index 2cc3749f4..eb1fbb628 100644 --- a/src/core/backend.rs +++ b/src/core/backend.rs @@ -35,6 +35,9 @@ pub fn get_available_backends() -> Vec { HANDLE_ERROR(AfError::from(err_val)); let mut b = Vec::new(); + if temp & 0b1000 == 0b1000 { + b.push(Backend::ONEAPI); + } if temp & 0b0100 == 0b0100 { b.push(Backend::OPENCL); } @@ -58,6 +61,7 @@ pub fn get_active_backend() -> Backend { (0, 1) => Backend::CPU, (0, 2) => Backend::CUDA, (0, 4) => Backend::OPENCL, + (0, 8) => Backend::ONEAPI, _ => panic!("Invalid backend retrieved, undefined behavior."), } } diff --git a/src/core/defines.rs b/src/core/defines.rs index b11662793..ffe27dc5e 100644 --- a/src/core/defines.rs +++ b/src/core/defines.rs @@ -66,11 +66,14 @@ pub enum Backend { CUDA = 2, /// OpenCL Compute Backend OPENCL = 4, + /// OneAPI Compute Backend + ONEAPI = 8, } impl Display for Backend { fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { let text = match *self { + Backend::ONEAPI => "OneAPI", Backend::OPENCL => "OpenCL", Backend::CUDA => "Cuda", Backend::CPU => "CPU",