Skip to content

Commit

Permalink
refs #27: Add unit test stubs for CUDA
Browse files Browse the repository at this point in the history
 * I've found alignment issues in complex/nested structs in CUDA;
   we need some thorough tests for them!
  • Loading branch information
achimnol committed Feb 23, 2016
1 parent f48ff79 commit eb8bcef
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/nba/engines/cuda/test.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace nba {
extern void* get_test_kernel_noop();
}

// vim: ts=8 sts=4 sw=4 et
1 change: 0 additions & 1 deletion include/nba/framework/datablock_shared.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <cstdint>
#include <nba/core/shiftedint.hh>
#include <nba/framework/config.hh>

struct datablock_batch_info {
void *buffer_bases_in;
Expand Down
16 changes: 16 additions & 0 deletions src/engines/cuda/test.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <nba/engines/cuda/test.hh>

using namespace std;
using namespace nba;

__global__ void noop()
{
__syncthreads();
}

void *nba::get_test_kernel_noop()
{
return reinterpret_cast<void *> (noop);
}

// vim: ts=8 sts=4 sw=4 et
37 changes: 37 additions & 0 deletions tests/test_cuda.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <cstdint>
#include <cuda_runtime.h>
#include <nba/core/shiftedint.hh>
#include <nba/framework/datablock_shared.hh>
#include <gtest/gtest.h>
#include <nba/engines/cuda/test.hh>
#if 0
#require <engines/cuda/test.o>
#endif

using namespace std;
using namespace nba;

#ifdef USE_CUDA

TEST(CUDADeviceTest, Initialization) {
EXPECT_EQ(cudaSuccess, cudaSetDevice(0));
EXPECT_EQ(cudaSuccess, cudaDeviceReset());
}

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

#else

TEST(CUDATest, Noop) {
EXPECT_TRUE(1);
}

#endif

// vim: ts=8 sts=4 sw=4 et

0 comments on commit eb8bcef

Please sign in to comment.