Skip to content

Commit a59e890

Browse files
committed
Merge pull request #11 from arrayfire/backend_choice
added option to build conf file to choose arrayfire backend
2 parents 56ee9fe + 195bcb9 commit a59e890

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

build.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
2+
"use_backend": "cuda",
3+
24
"use_lib": false,
35
"lib_dir": "/usr/local/lib",
46
"inc_dir": "/usr/local/include",
57

68
"build_type": "Release",
79
"build_threads": "4",
8-
"build_cuda": "OFF",
10+
"build_cuda": "ON",
911
"build_opencl": "ON",
1012
"build_cpu": "ON",
1113
"build_examples": "OFF",

build.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ use std::path::PathBuf;
1010
use std::process::Command;
1111
use std::convert::AsRef;
1212

13+
#[allow(dead_code)]
1314
#[derive(RustcDecodable)]
1415
struct Config {
16+
// below variable dictates which
17+
// backend library is used by rust wrapper
18+
use_backend: String,
19+
1520
// Use the existing lib if it exists
1621
use_lib: bool,
1722
lib_dir: String,
@@ -81,13 +86,15 @@ fn read_file(file_name: &std::path::PathBuf) -> String {
8186
.open(&file_path);
8287

8388
let mut file = match options {
84-
Ok(file) => file,
89+
Ok(file)=> file,
8590
Err(..) => panic!("error reading file"),
8691
};
8792

8893
let mut s = String::new();
89-
file.read_to_string(&mut s);
90-
return s.to_string()
94+
match file.read_to_string(&mut s) {
95+
Ok(_) => s,
96+
Err(..) => panic!("Error reading file to a string"),
97+
}
9198
}
9299

93100
fn read_conf(conf_file: &std::path::PathBuf) -> Config {
@@ -332,7 +339,9 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
332339
backend_dirs.push(build_dir.join("package/lib").to_str().to_owned().unwrap().to_string());
333340
}
334341

335-
if conf.build_cuda == "ON" {
342+
if conf.use_backend == "cpu" {
343+
backends.push("afcpu".to_string());
344+
} else if conf.use_backend == "cuda" {
336345
backends.push("afcuda".to_string());
337346
backends.push("nvvm".to_string());
338347
if cfg!(windows) {
@@ -342,13 +351,7 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
342351
backend_dirs.push(format!("{}/lib64", conf.cuda_sdk));
343352
backend_dirs.push(format!("{}/nvvm/lib64", conf.cuda_sdk));
344353
}
345-
}
346-
347-
if conf.build_cpu == "ON" {
348-
backends.push("afcpu".to_string());
349-
}
350-
351-
if conf.build_opencl == "ON" {
354+
} else if conf.use_backend == "opencl" {
352355
backends.push(("afopencl".to_string()));
353356
backends.push("OpenCL".to_string());
354357
if cfg!(windows) {

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use libc::c_longlong;
1010
use std::ops::Index;
1111
use std::ops::Add;
1212

13-
#[link(name="afcpu")]
1413
extern {
1514
fn af_set_device(device: c_int) -> c_int;
1615

0 commit comments

Comments
 (0)