diff --git a/test/blas.cpp b/test/blas.cpp index af73359318..507cc6dc7b 100644 --- a/test/blas.cpp +++ b/test/blas.cpp @@ -209,34 +209,39 @@ TYPED_TEST(MatrixMultiply, RectangleVector_CPP) cppMatMulCheck(TEST_DIR"/blas/RectangleVector.test"); } +#define DEVICE_ITERATE(func) do { \ + const char* ENV = getenv("AF_MULTI_GPU_TESTS"); \ + if(ENV && ENV[0] == '0') { \ + func; \ + } else { \ + int oldDevice = af::getDevice(); \ + for(int i = 0; i < af::getDeviceCount(); i++) { \ + af::setDevice(i); \ + func; \ + } \ + af::setDevice(oldDevice); \ + } \ +} while(0); + + TYPED_TEST(MatrixMultiply, MultiGPUSquare_CPP) { - for(int i = 0; i < af::getDeviceCount(); i++) { - af::setDevice(i); - cppMatMulCheck(TEST_DIR"/blas/Basic.test"); - } + DEVICE_ITERATE((cppMatMulCheck(TEST_DIR"/blas/Basic.test"))); } TYPED_TEST(MatrixMultiply, MultiGPUNonSquare_CPP) { - for(int i = 0; i < af::getDeviceCount(); i++) { - af::setDevice(i); - cppMatMulCheck(TEST_DIR"/blas/NonSquare.test"); - } + DEVICE_ITERATE((cppMatMulCheck(TEST_DIR"/blas/NonSquare.test"))); } TYPED_TEST(MatrixMultiply, MultiGPUSquareVector_CPP) { - for(int i = 0; i < af::getDeviceCount(); i++) { - af::setDevice(i); - cppMatMulCheck(TEST_DIR"/blas/SquareVector.test"); - } + DEVICE_ITERATE((cppMatMulCheck(TEST_DIR"/blas/SquareVector.test"))); } TYPED_TEST(MatrixMultiply, MultiGPURectangleVector_CPP) { - for(int i = 0; i < af::getDeviceCount(); i++) { - af::setDevice(i); - cppMatMulCheck(TEST_DIR"/blas/RectangleVector.test"); - } + DEVICE_ITERATE((cppMatMulCheck(TEST_DIR"/blas/RectangleVector.test"))); } + +#undef DEVICE_ITERATE diff --git a/test/info.cpp b/test/info.cpp index bd70a66b9e..ff2cea6e89 100644 --- a/test/info.cpp +++ b/test/info.cpp @@ -36,23 +36,35 @@ typedef ::testing::Types TestTypes; TYPED_TEST_CASE(Info, TestTypes); template -void infoTest() +void testFunction() { - if (noDoubleTests()) return; + af::info(); - int nDevices = 0; - ASSERT_EQ(AF_SUCCESS, af_get_device_count(&nDevices)); + af_array outArray = 0; + af::dim4 dims(32, 32, 1, 1); + ASSERT_EQ(AF_SUCCESS, af_randu(&outArray, dims.ndims(), dims.get(), (af_dtype) af::dtype_traits::af_type)); + // cleanup + if(outArray != 0) ASSERT_EQ(AF_SUCCESS, af_release_array(outArray)); +} - for(int d = 0; d < nDevices; d++) { +template +void infoTest() +{ + if (noDoubleTests()) return; - af::setDevice(d); - af::info(); + const char* ENV = getenv("AF_MULTI_GPU_TESTS"); + if(ENV && ENV[0] == '0') { + testFunction(); + } else { + int nDevices = 0; + ASSERT_EQ(AF_SUCCESS, af_get_device_count(&nDevices)); - af_array outArray = 0; - af::dim4 dims(32, 32, 1, 1); - ASSERT_EQ(AF_SUCCESS, af_randu(&outArray, dims.ndims(), dims.get(), (af_dtype) af::dtype_traits::af_type)); - // cleanup - if(outArray != 0) ASSERT_EQ(AF_SUCCESS, af_release_array(outArray)); + int oldDevice = af::getDevice(); + for(int d = 0; d < nDevices; d++) { + af::setDevice(d); + testFunction(); + } + af::setDevice(oldDevice); } } diff --git a/test/median.cpp b/test/median.cpp index 86dee96942..9f176dcaf2 100644 --- a/test/median.cpp +++ b/test/median.cpp @@ -16,6 +16,27 @@ using namespace af; using std::vector; +template +af::array generateArray(int nx, int ny, int nz, int nw) +{ + array a = randu(nx, ny, nz, nw, (af::dtype)dtype_traits::af_type); + return a; +} + +template<> +af::array generateArray(int nx, int ny, int nz, int nw) +{ + array a = (randu(nx, ny, nz, nw, (af::dtype)dtype_traits::af_type) * 1e6).as(s32); + return a; +} + +template<> +af::array generateArray(int nx, int ny, int nz, int nw) +{ + array a = (randu(nx, ny, nz, nw, (af::dtype)dtype_traits::af_type) * 1e6).as(u32); + return a; +} + template void median0(int nx, int ny=1, int nz=1, int nw=1) { @@ -49,7 +70,7 @@ void median0(int nx, int ny=1, int nz=1, int nw=1) To left = h_sa[id + off * nx - 1]; To right = h_sa[id + off * nx]; - ASSERT_NEAR((left + right) / 2, h_b[off], 1e-8); + ASSERT_NEAR((left + right) / 2, h_b[off], 1e-5); } } } diff --git a/test/reduce.cpp b/test/reduce.cpp index 45c09774fb..eef711db94 100644 --- a/test/reduce.cpp +++ b/test/reduce.cpp @@ -256,7 +256,7 @@ TEST(Reduce, Test_Product_Global) gold *= h_a[i]; } - ASSERT_EQ(gold, res); + ASSERT_NEAR(gold, res, 1e-3); delete[] h_a; }