Skip to content

Commit

Permalink
refs #27: Let CUDA test cases to run over all CUDA devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Feb 24, 2016
1 parent a6a8d62 commit 2fa4e84
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tests/test_cuda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,43 @@ using namespace nba;

#ifdef USE_CUDA

TEST(CUDADeviceTest, Initialization) {
ASSERT_EQ(cudaSuccess, cudaSetDevice(0));
static int getNumCUDADevices() {
int count;
cudaGetDeviceCount(&count);
return count;
}

class CUDADeviceTest : public ::testing::TestWithParam<int> {
};

TEST_P(CUDADeviceTest, Initialization) {
ASSERT_EQ(cudaSuccess, cudaSetDevice(GetParam()));
ASSERT_EQ(cudaSuccess, cudaDeviceReset());
}

TEST(CUDADeviceTest, NoopKernel) {
ASSERT_EQ(cudaSuccess, cudaSetDevice(0));
TEST_P(CUDADeviceTest, NoopKernel) {
ASSERT_EQ(cudaSuccess, cudaSetDevice(GetParam()));
void *k = get_test_kernel_noop();
EXPECT_EQ(cudaSuccess, cudaLaunchKernel(k, dim3(1), dim3(1), nullptr, 0, 0));
EXPECT_EQ(cudaSuccess, cudaDeviceSynchronize());
ASSERT_EQ(cudaSuccess, cudaDeviceReset());
}

class CUDAStructTest : public ::testing::Test {
INSTANTIATE_TEST_CASE_P(PerDeviceDeviceTests, CUDADeviceTest, ::testing::Values(0, getNumCUDADevices() - 1));


class CUDAStructTest : public ::testing::TestWithParam<int> {
protected:
virtual void SetUp() {
cudaSetDevice(0);
cudaSetDevice(GetParam());
}

virtual void TearDown() {
cudaDeviceReset();
}
};

TEST(CUDAStructTest, ShfitedIntSizeCheck) {
TEST_P(CUDAStructTest, ShfitedIntSizeCheck) {
void *k = get_test_kernel_shiftedint_size_check();
void *output_d;
ASSERT_EQ(cudaSuccess, cudaMalloc(&output_d, sizeof(size_t)));
Expand All @@ -52,7 +64,7 @@ TEST(CUDAStructTest, ShfitedIntSizeCheck) {
ASSERT_EQ(cudaSuccess, cudaDeviceSynchronize());
}

TEST(CUDAStructTest, ShfitedIntValueCheck) {
TEST_P(CUDAStructTest, ShfitedIntValueCheck) {
void *k = get_test_kernel_shiftedint_value_check();
void *input_d;
void *output_d;
Expand All @@ -73,7 +85,7 @@ TEST(CUDAStructTest, ShfitedIntValueCheck) {
ASSERT_EQ(cudaSuccess, cudaDeviceSynchronize());
}

TEST(CUDAStructTest, DatablockArgSizeAlignCheck) {
TEST_P(CUDAStructTest, DatablockArgSizeAlignCheck) {
void *k = get_test_kernel_dbarg_size_check();
void *output_sizes_d;
void *output_offsets_d;
Expand All @@ -96,6 +108,7 @@ TEST(CUDAStructTest, DatablockArgSizeAlignCheck) {
ASSERT_EQ(cudaSuccess, cudaDeviceSynchronize());
}

INSTANTIATE_TEST_CASE_P(PerDeviceStructTests, CUDAStructTest, ::testing::Values(0, getNumCUDADevices() - 1));

#else

Expand Down

0 comments on commit 2fa4e84

Please sign in to comment.