Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions test/blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,34 +209,39 @@ TYPED_TEST(MatrixMultiply, RectangleVector_CPP)
cppMatMulCheck<TypeParam, true>(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<TypeParam, false>(TEST_DIR"/blas/Basic.test");
}
DEVICE_ITERATE((cppMatMulCheck<TypeParam, false>(TEST_DIR"/blas/Basic.test")));
}

TYPED_TEST(MatrixMultiply, MultiGPUNonSquare_CPP)
{
for(int i = 0; i < af::getDeviceCount(); i++) {
af::setDevice(i);
cppMatMulCheck<TypeParam, false>(TEST_DIR"/blas/NonSquare.test");
}
DEVICE_ITERATE((cppMatMulCheck<TypeParam, false>(TEST_DIR"/blas/NonSquare.test")));
}

TYPED_TEST(MatrixMultiply, MultiGPUSquareVector_CPP)
{
for(int i = 0; i < af::getDeviceCount(); i++) {
af::setDevice(i);
cppMatMulCheck<TypeParam, true>(TEST_DIR"/blas/SquareVector.test");
}
DEVICE_ITERATE((cppMatMulCheck<TypeParam, true>(TEST_DIR"/blas/SquareVector.test")));
}

TYPED_TEST(MatrixMultiply, MultiGPURectangleVector_CPP)
{
for(int i = 0; i < af::getDeviceCount(); i++) {
af::setDevice(i);
cppMatMulCheck<TypeParam, true>(TEST_DIR"/blas/RectangleVector.test");
}
DEVICE_ITERATE((cppMatMulCheck<TypeParam, true>(TEST_DIR"/blas/RectangleVector.test")));
}

#undef DEVICE_ITERATE
36 changes: 24 additions & 12 deletions test/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,35 @@ typedef ::testing::Types<float> TestTypes;
TYPED_TEST_CASE(Info, TestTypes);

template<typename T>
void infoTest()
void testFunction()
{
if (noDoubleTests<T>()) 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<T>::af_type));
// cleanup
if(outArray != 0) ASSERT_EQ(AF_SUCCESS, af_release_array(outArray));
}

for(int d = 0; d < nDevices; d++) {
template<typename T>
void infoTest()
{
if (noDoubleTests<T>()) return;

af::setDevice(d);
af::info();
const char* ENV = getenv("AF_MULTI_GPU_TESTS");
if(ENV && ENV[0] == '0') {
testFunction<T>();
} 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<T>::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<T>();
}
af::setDevice(oldDevice);
}
}

Expand Down
23 changes: 22 additions & 1 deletion test/median.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@
using namespace af;
using std::vector;

template<typename Ti>
af::array generateArray(int nx, int ny, int nz, int nw)
{
array a = randu(nx, ny, nz, nw, (af::dtype)dtype_traits<Ti>::af_type);
return a;
}

template<>
af::array generateArray<int>(int nx, int ny, int nz, int nw)
{
array a = (randu(nx, ny, nz, nw, (af::dtype)dtype_traits<float>::af_type) * 1e6).as(s32);
return a;
}

template<>
af::array generateArray<unsigned int>(int nx, int ny, int nz, int nw)
{
array a = (randu(nx, ny, nz, nw, (af::dtype)dtype_traits<float>::af_type) * 1e6).as(u32);
return a;
}

template<typename To, typename Ti, bool flat>
void median0(int nx, int ny=1, int nz=1, int nw=1)
{
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down