-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor/rcublas: deduplicate test code, add setup+teardown
The setup and teardown methods should become a procmacro which avoids all the chore changes.
- Loading branch information
Showing
8 changed files
with
99 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::co::backend::{Backend, IBackend}; | ||
use crate::co::frameworks::{Cuda, Native}; | ||
use crate::co::frameworks::native::flatbox::FlatBox; | ||
use crate::co::tensor::SharedTensor; | ||
use env_logger; | ||
|
||
pub fn test_setup() { | ||
|
||
let _ = env_logger::builder().is_test(true).try_init(); | ||
} | ||
|
||
pub fn test_teardown() { | ||
|
||
} | ||
|
||
pub fn get_native_backend() -> Backend<Native> { | ||
Backend::<Native>::default().unwrap() | ||
} | ||
|
||
pub fn get_cuda_backend() -> Backend<Cuda> { | ||
Backend::<Cuda>::default().unwrap() | ||
} | ||
|
||
pub fn write_to_memory<T: Copy>(mem: &mut FlatBox, data: &[T]) { | ||
let mem_buffer = mem.as_mut_slice::<T>(); | ||
for (index, datum) in data.iter().enumerate() { | ||
mem_buffer[index] = *datum; | ||
} | ||
} | ||
|
||
pub fn filled_tensor<B: IBackend, T: Copy>(_backend: &B, n: usize, val: T) -> SharedTensor<T> { | ||
let mut x = SharedTensor::<T>::new(&vec![n]); | ||
let values: &[T] = &::std::iter::repeat(val) | ||
.take(x.capacity()) | ||
.collect::<Vec<T>>(); | ||
write_to_memory(x.write_only(get_native_backend().device()).unwrap(), values); | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ pub struct API; | |
|
||
pub mod api; | ||
pub mod error; | ||
|
||
#[cfg(test)] | ||
pub(crate) mod chore; |