Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests #116

Merged
merged 4 commits into from
Aug 8, 2018
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
3 changes: 0 additions & 3 deletions HeterogeneousCore/CUDAServices/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
<bin file="testCUDAService.cpp test_main.cpp" name="testCUDAService">
<use name="catch2"/>
</bin>
<bin file="testCUDAServiceDrv.cpp">
<use name="HeterogeneousCore/CUDAUtilities"/>
</bin>
22 changes: 16 additions & 6 deletions HeterogeneousCore/CUDAServices/test/testCUDAService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@
#include "catch.hpp"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "HeterogeneousCore/CUDAServices/interface/CUDAService.h"

namespace {
CUDAService makeCUDAService(edm::ParameterSet ps, edm::ActivityRegistry& ar) {
auto desc = edm::ConfigurationDescriptions("Service", "CUDAService");
CUDAService::fillDescriptions(desc);
desc.validate(ps, "CUDAService");
return CUDAService(ps, ar);
}
}

TEST_CASE("Tests of CUDAService", "[CUDAService]") {
edm::ActivityRegistry ar;

Expand All @@ -32,7 +42,7 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") {
ps.addUntrackedParameter("enabled", true);
ps.addUntrackedParameter("numberOfStreamsPerDevice", 0U);
SECTION("Enabled only if there are CUDA capable GPUs") {
CUDAService cs(ps, ar);
auto cs = makeCUDAService(ps, ar);
if(deviceCount <= 0) {
REQUIRE(cs.enabled() == false);
WARN("CUDAService is disabled as there are no CUDA GPU devices");
Expand All @@ -47,7 +57,7 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") {
return;
}

CUDAService cs(ps, ar);
auto cs = makeCUDAService(ps, ar);

SECTION("CUDA Queries") {
int driverVersion = 0, runtimeVersion = 0;
Expand Down Expand Up @@ -119,7 +129,7 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") {
edm::ParameterSet ps;
ps.addUntrackedParameter("enabled", false);
ps.addUntrackedParameter("numberOfStreamsPerDevice", 0U);
CUDAService cs(ps, ar);
auto cs = makeCUDAService(ps, ar);
REQUIRE(cs.enabled() == false);
REQUIRE(cs.numberOfDevices() == 0);
}
Expand All @@ -129,7 +139,7 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") {
ps.addUntrackedParameter("enabled", true);
SECTION("Unlimited") {
ps.addUntrackedParameter("numberOfStreamsPerDevice", 0U);
CUDAService cs(ps, ar);
auto cs = makeCUDAService(ps, ar);
REQUIRE(cs.enabled() == true);
REQUIRE(cs.enabled(0) == true);
REQUIRE(cs.enabled(100) == true);
Expand All @@ -139,7 +149,7 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") {

SECTION("Limit to 1") {
ps.addUntrackedParameter("numberOfStreamsPerDevice", 1U);
CUDAService cs(ps, ar);
auto cs = makeCUDAService(ps, ar);
REQUIRE(cs.enabled() == true);
REQUIRE(cs.enabled(0) == true);
REQUIRE(cs.enabled(1*deviceCount-1) == true);
Expand All @@ -149,7 +159,7 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") {

SECTION("Limit to 2") {
ps.addUntrackedParameter("numberOfStreamsPerDevice", 2U);
CUDAService cs(ps, ar);
auto cs = makeCUDAService(ps, ar);
REQUIRE(cs.enabled() == true);
REQUIRE(cs.enabled(0) == true);
REQUIRE(cs.enabled(1*deviceCount) == true);
Expand Down
152 changes: 0 additions & 152 deletions HeterogeneousCore/CUDAServices/test/testCUDAServiceDrv.cpp

This file was deleted.

49 changes: 23 additions & 26 deletions HeterogeneousCore/CUDAUtilities/test/test_GPUSimpleVector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cuda_runtime.h>

#include "HeterogeneousCore/CUDAUtilities/interface/GPUSimpleVector.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"

__global__ void vector_pushback(GPU::SimpleVector<int> *foo) {
auto index = threadIdx.x + blockIdx.x * blockDim.x;
Expand All @@ -31,60 +32,56 @@ int main() {
int *data_ptr = nullptr;
int *d_data_ptr = nullptr;

bool success =
cudaMallocHost(&obj_ptr, sizeof(GPU::SimpleVector<int>)) == cudaSuccess &&
cudaMallocHost(&data_ptr, maxN * sizeof(int)) == cudaSuccess &&
cudaMalloc(&d_data_ptr, maxN * sizeof(int)) == cudaSuccess;
cudaCheck(cudaMallocHost(&obj_ptr, sizeof(GPU::SimpleVector<int>)));
cudaCheck(cudaMallocHost(&data_ptr, maxN * sizeof(int)));
cudaCheck(cudaMalloc(&d_data_ptr, maxN * sizeof(int)));

auto v = new (obj_ptr) GPU::SimpleVector<int>(maxN, data_ptr);

cudaMallocHost(&tmp_obj_ptr, sizeof(GPU::SimpleVector<int>));
cudaCheck(cudaMallocHost(&tmp_obj_ptr, sizeof(GPU::SimpleVector<int>)));
new (tmp_obj_ptr) GPU::SimpleVector<int>(maxN, d_data_ptr);
assert(tmp_obj_ptr->size() == 0);
assert(tmp_obj_ptr->capacity() == static_cast<int>(maxN));

success =
success &&
cudaMalloc(&d_obj_ptr, sizeof(GPU::SimpleVector<int>)) == cudaSuccess
// ... and copy the object to the device.
&& cudaMemcpy(d_obj_ptr, tmp_obj_ptr, sizeof(GPU::SimpleVector<int>),
cudaMemcpyDefault) == cudaSuccess;
cudaCheck(cudaMalloc(&d_obj_ptr, sizeof(GPU::SimpleVector<int>)));
// ... and copy the object to the device.
cudaCheck(cudaMemcpy(d_obj_ptr, tmp_obj_ptr, sizeof(GPU::SimpleVector<int>), cudaMemcpyDefault));

int numBlocks = 5;
int numThreadsPerBlock = 256;
assert(success);
vector_pushback<<<numBlocks, numThreadsPerBlock>>>(d_obj_ptr);
success = success && cudaGetLastError();
cudaCheck(cudaGetLastError());
cudaCheck(cudaDeviceSynchronize());

cudaMemcpy(obj_ptr, d_obj_ptr, sizeof(GPU::SimpleVector<int>), cudaMemcpyDefault);
cudaCheck(cudaMemcpy(obj_ptr, d_obj_ptr, sizeof(GPU::SimpleVector<int>), cudaMemcpyDefault));

assert(obj_ptr->size() == (numBlocks * numThreadsPerBlock < maxN
? numBlocks * numThreadsPerBlock
: maxN));
vector_reset<<<numBlocks, numThreadsPerBlock>>>(d_obj_ptr);
success = success && cudaGetLastError();
cudaCheck(cudaGetLastError());
cudaCheck(cudaDeviceSynchronize());

cudaMemcpy(obj_ptr, d_obj_ptr, sizeof(GPU::SimpleVector<int>), cudaMemcpyDefault);
cudaCheck(cudaMemcpy(obj_ptr, d_obj_ptr, sizeof(GPU::SimpleVector<int>), cudaMemcpyDefault));

assert(obj_ptr->size() == 0);

vector_emplace_back<<<numBlocks, numThreadsPerBlock>>>(d_obj_ptr);
success = success && cudaGetLastError();
cudaCheck(cudaGetLastError());
cudaCheck(cudaDeviceSynchronize());

cudaMemcpy(obj_ptr, d_obj_ptr, sizeof(GPU::SimpleVector<int>), cudaMemcpyDefault);
cudaCheck(cudaMemcpy(obj_ptr, d_obj_ptr, sizeof(GPU::SimpleVector<int>), cudaMemcpyDefault));

assert(obj_ptr->size() == (numBlocks * numThreadsPerBlock < maxN
? numBlocks * numThreadsPerBlock
: maxN));

success = success and
cudaMemcpy(data_ptr, d_data_ptr, obj_ptr->size() * sizeof(int), cudaMemcpyDefault) == cudaSuccess and
cudaFreeHost(obj_ptr) == cudaSuccess and
cudaFreeHost(data_ptr) == cudaSuccess and
cudaFreeHost(tmp_obj_ptr) == cudaSuccess and
cudaFree(d_data_ptr) == cudaSuccess and
cudaFree(d_obj_ptr) == cudaSuccess;
assert(success);
cudaCheck(cudaMemcpy(data_ptr, d_data_ptr, obj_ptr->size() * sizeof(int), cudaMemcpyDefault));
cudaCheck(cudaFreeHost(obj_ptr));
cudaCheck(cudaFreeHost(data_ptr));
cudaCheck(cudaFreeHost(tmp_obj_ptr));
cudaCheck(cudaFree(d_data_ptr));
cudaCheck(cudaFree(d_obj_ptr));
std::cout << "TEST PASSED" << std::endl;
return 0;
}