From 8387459debee35ea620934748052bdd1efb84e82 Mon Sep 17 00:00:00 2001 From: Florian Gilcher Date: Tue, 1 Dec 2015 12:09:57 +0100 Subject: [PATCH 1/5] refactor/features: remove associated_consts Replace associated ID consts by a static function. This allows removal of the associated_consts feature flag. --- src/framework.rs | 3 ++- src/frameworks/cuda/mod.rs | 3 ++- src/frameworks/native/mod.rs | 2 +- src/frameworks/opencl/mod.rs | 3 ++- src/lib.rs | 1 - 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/framework.rs b/src/framework.rs index d4676438..ab1391b2 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -38,7 +38,8 @@ pub trait IFramework { /// /// For convention, let the ID be uppercase.
/// EXAMPLE: OPENCL - const ID: &'static str; + #[allow(non_snake_case)] + fn ID() -> &'static str; /// Initializes a new Framework. /// diff --git a/src/frameworks/cuda/mod.rs b/src/frameworks/cuda/mod.rs index 5945c7a3..ea0ce7ae 100644 --- a/src/frameworks/cuda/mod.rs +++ b/src/frameworks/cuda/mod.rs @@ -36,7 +36,8 @@ impl IFramework for Cuda { type H = Device; type D = Context; type B = Module; - const ID: &'static str = "CUDA"; + + fn ID() -> &'static str { "CUDA" } fn new() -> Cuda { match Cuda::load_hardwares() { diff --git a/src/frameworks/native/mod.rs b/src/frameworks/native/mod.rs index c726fb99..73d4e491 100644 --- a/src/frameworks/native/mod.rs +++ b/src/frameworks/native/mod.rs @@ -40,7 +40,7 @@ impl IFramework for Native { type D = Cpu; type B = Binary; - const ID: &'static str = "NATIVE"; + fn ID() -> &'static str { "NATIVE" } fn new() -> Native { match Native::load_hardwares() { diff --git a/src/frameworks/opencl/mod.rs b/src/frameworks/opencl/mod.rs index 450c6f8c..f09f3c1e 100644 --- a/src/frameworks/opencl/mod.rs +++ b/src/frameworks/opencl/mod.rs @@ -50,7 +50,8 @@ impl IFramework for OpenCL { type H = Device; type D = Context; type B = Program; - const ID: &'static str = "OPENCL"; + + fn ID() -> &'static str { "OPENCL" } fn new() -> OpenCL { match OpenCL::load_hardwares() { diff --git a/src/lib.rs b/src/lib.rs index c4b004fa..44b8c7a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,6 @@ #![cfg_attr(lint, feature(plugin))] #![cfg_attr(lint, plugin(clippy))] #![allow(dead_code)] -#![feature(associated_consts)] #![feature(associated_type_defaults)] #![feature(unboxed_closures)] #![feature(static_mutex)] From 0af16772066f04699263edb3b3f3dd7961a0d03d Mon Sep 17 00:00:00 2001 From: Florian Gilcher Date: Tue, 1 Dec 2015 12:14:23 +0100 Subject: [PATCH 2/5] refactor/features: remove associated_type_defaults This feature is unused and can be removed --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 44b8c7a2..47966812 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,6 @@ #![cfg_attr(lint, feature(plugin))] #![cfg_attr(lint, plugin(clippy))] #![allow(dead_code)] -#![feature(associated_type_defaults)] #![feature(unboxed_closures)] #![feature(static_mutex)] #![deny(missing_docs, From 872125a06ce29c027f2a91746c45b23f5c69384b Mon Sep 17 00:00:00 2001 From: Florian Gilcher Date: Tue, 1 Dec 2015 12:15:10 +0100 Subject: [PATCH 3/5] refactor/features: remove unboxed closures This feature is unused. --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 47966812..afc8b1a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,6 @@ #![cfg_attr(lint, feature(plugin))] #![cfg_attr(lint, plugin(clippy))] #![allow(dead_code)] -#![feature(unboxed_closures)] #![feature(static_mutex)] #![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, From 65569343c4cfe56d749b9f97cb6f858f45edd7c5 Mon Sep 17 00:00:00 2001 From: Florian Gilcher Date: Tue, 1 Dec 2015 12:22:11 +0100 Subject: [PATCH 4/5] refactor/features: replace StaticMutex Replace StaticMutex by the stable `lazy_static!` --- Cargo.toml | 1 + src/frameworks/opencl/api/platform.rs | 6 ++++-- src/lib.rs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 109ef84d..1428428b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ rblas = "0.0.10" enum_primitive = "0.1.0" byteorder = "0.4" num = "0.1" +lazy_static = "0.1.15" clippy = { version = "0.0.27", optional = true } diff --git a/src/frameworks/opencl/api/platform.rs b/src/frameworks/opencl/api/platform.rs index 71dc4331..c7d9acfe 100644 --- a/src/frameworks/opencl/api/platform.rs +++ b/src/frameworks/opencl/api/platform.rs @@ -6,7 +6,7 @@ use super::types as cl; use super::ffi::*; use std::ptr; use std::iter::repeat; -use std::sync::{StaticMutex, MUTEX_INIT}; +use std::sync::Mutex; impl API { /// Returns a list of available platforms. @@ -22,7 +22,9 @@ impl API { // This mutex is used to work around weak OpenCL implementations. // On some implementations concurrent calls to clGetPlatformIDs // will cause the implantation to return invalid status. - static mut platforms_mutex: StaticMutex = MUTEX_INIT; + lazy_static! { + static ref platforms_mutex: Mutex<()> = Mutex::new(()); + } let guard = unsafe {platforms_mutex.lock()}; try!(unsafe {API::ffi_get_platform_ids(0, ptr::null_mut(), (&mut num_platforms))}); diff --git a/src/lib.rs b/src/lib.rs index afc8b1a5..a643914f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,6 @@ #![cfg_attr(lint, feature(plugin))] #![cfg_attr(lint, plugin(clippy))] #![allow(dead_code)] -#![feature(static_mutex)] #![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts, trivial_numeric_casts, @@ -145,6 +144,8 @@ extern crate libc; extern crate bitflags; #[macro_use] extern crate enum_primitive; +#[macro_use] +extern crate lazy_static; extern crate num; extern crate byteorder; extern crate rblas as blas; From f14c1fc1bf3a481b0cebe85fdc1eebb964139476 Mon Sep 17 00:00:00 2001 From: Florian Gilcher Date: Wed, 2 Dec 2015 16:49:46 +0100 Subject: [PATCH 5/5] chore/dependencies: bump to rblas 0.0.11 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1428428b..b8a7441b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ license = "MIT" [dependencies] libc = "0.2" bitflags = "0.3" -rblas = "0.0.10" +rblas = "0.0.11" enum_primitive = "0.1.0" byteorder = "0.4" num = "0.1"