Skip to content

Commit

Permalink
test/tensor: add specific test for new sync/access API [SKIP_CHANGELOG]
Browse files Browse the repository at this point in the history
REFERENCE: autumnai#37
  • Loading branch information
alexandermorozov committed Apr 18, 2016
1 parent 9c4918b commit f76ced4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum DeviceType {
Cuda(CudaContext),
}

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines a generic set of Memory Errors.
pub enum Error {
/// Failures related to the Native framework implementation.
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/cuda/api/driver/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fmt, error};

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines OpenCL errors.
pub enum Error {
/// Failure with provided value.
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/native/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fmt, error};

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines the Native Error.
pub enum Error {
/// Failure related to allocation, syncing memory
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/opencl/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fmt, error};

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// Defines OpenCL errors.
pub enum Error {
/// Failure with provided platform.
Expand Down
2 changes: 1 addition & 1 deletion src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl<T> SharedTensor<T> {
}

/// Errors than can occur when synchronizing memory.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Error {
/// No copy on source device.
MissingSource(&'static str),
Expand Down
19 changes: 19 additions & 0 deletions tests/shared_memory_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate libc;
#[cfg(test)]
mod shared_memory_spec {
use co::prelude::*;
use co::tensor::Error;

fn write_to_memory<T: Copy>(mem: &mut MemoryType, data: &[T]) {
match mem {
Expand Down Expand Up @@ -59,6 +60,24 @@ mod shared_memory_spec {
}
}

#[test]
#[cfg(feature = "native")]
fn it_fails_on_initialized_memory_read() {
let ntv = Native::new();
let cpu = ntv.new_device(ntv.hardwares()).unwrap();
let shared_data = &mut SharedTensor::<f32>::new(&10).unwrap();
assert_eq!(shared_data.read(&cpu).unwrap_err(),
Error::UninitializedMemory);
assert_eq!(shared_data.read_write(&cpu).unwrap_err(),
Error::UninitializedMemory);

shared_data.write_only(&cpu).unwrap();
shared_data.drop_device(&cpu).unwrap();

assert_eq!(shared_data.read(&cpu).unwrap_err(),
Error::UninitializedMemory);
}

#[test]
#[cfg(feature = "cuda")]
fn it_syncs_from_native_to_cuda_and_back() {
Expand Down

0 comments on commit f76ced4

Please sign in to comment.