Remove cudaDeviceReset calls from tests

This commit is contained in:
2024-04-21 22:47:12 +02:00
parent bdbb3f978e
commit 58af95eb25
11 changed files with 18 additions and 28 deletions

View File

@@ -12,13 +12,11 @@ using namespace CUDANet::Layers;
Activation::Activation(ActivationType activation, const int length)
: activationType(activation), length(length) {
if (activationType == SOFTMAX) {
d_max = nullptr;
CUDA_CHECK(cudaMalloc((void**)&d_max, sizeof(float) * length));
d_softmax_sum = nullptr;
CUDA_CHECK(cudaMalloc((void**)&d_softmax_sum, sizeof(float) * length));
std::cout << "Activation: Softmax " << length << std::endl;
d_max = nullptr;
CUDA_CHECK(cudaMalloc((void**)&d_max, sizeof(float) * length));
}
gridSize = (length + BLOCK_SIZE - 1) / BLOCK_SIZE;
@@ -26,8 +24,8 @@ Activation::Activation(ActivationType activation, const int length)
Activation::~Activation() {
if (activationType == SOFTMAX) {
cudaFree(d_softmax_sum);
cudaFree(d_max);
CUDA_CHECK(cudaFree(d_softmax_sum));
CUDA_CHECK(cudaFree(d_max));
}
}
@@ -63,7 +61,7 @@ void Activation::activate(float* d_input) {
d_input, d_input, length
);
CUDA_CHECK(cudaGetLastError());
// Find sum
Utils::sum(d_input, d_softmax_sum, length);
@@ -71,7 +69,6 @@ void Activation::activate(float* d_input) {
d_input, d_input, d_softmax_sum, length
);
CUDA_CHECK(cudaGetLastError());
break;
default:

View File

@@ -45,5 +45,5 @@ TEST(ActivationFunctionsTest, SigmoidSanityCheck) {
cudaFree(d_input);
cudaFree(d_output);
cudaDeviceReset();
}

View File

@@ -68,7 +68,7 @@ TEST(MatMulTest, MatVecMulTest) {
cudaFree(d_vector);
cudaFree(d_output);
cudaDeviceReset();
}
TEST(MatMulTest, MaxReduceTest) {
@@ -113,7 +113,7 @@ TEST(MatMulTest, MaxReduceTest) {
cudaFree(d_input);
cudaFree(d_output);
cudaDeviceReset();
}
TEST(MatMulTest, VecExpTest) {
@@ -157,7 +157,7 @@ TEST(MatMulTest, VecExpTest) {
cudaFree(d_input);
cudaFree(d_output);
cudaDeviceReset();
}
TEST(MatMulTest, SumReduceTest) {
@@ -210,5 +210,5 @@ TEST(MatMulTest, SumReduceTest) {
cudaFree(d_input);
cudaFree(d_sum);
cudaDeviceReset();
}

View File

@@ -38,10 +38,7 @@ TEST(ActivationTest, SoftmaxTest1) {
EXPECT_NEAR(sum, 1.0f, 1e-5f);
cudaFree(d_input);
cudaDeviceReset();
cudaStatus = cudaGetLastError();
cudaStatus = cudaFree(d_input);
EXPECT_EQ(cudaStatus, cudaSuccess);
}
@@ -82,6 +79,6 @@ TEST(ActivationTest, SoftmaxTest2) {
EXPECT_NEAR(sum, 1.0f, 1e-5f);
// Cleanup
cudaFree(d_input);
cudaDeviceReset();
cudaStatus = cudaFree(d_input);
EXPECT_EQ(cudaStatus, cudaSuccess);
}

View File

@@ -67,6 +67,4 @@ TEST(AvgPoolingLayerTest, AvgPoolForwardTest) {
cudaFree(d_input);
cudaFree(d_output);
cudaDeviceReset();
}

View File

@@ -34,6 +34,4 @@ TEST(ConcatLayerTest, Init) {
EXPECT_EQ(output[i + 5], inputB[i]);
}
cudaFree(d_output);
cudaDeviceReset();
}

View File

@@ -47,7 +47,7 @@ class Conv2dTest : public ::testing::Test {
void commonTestTeardown(float* d_input) {
// Free device memory
cudaFree(d_input);
cudaDeviceReset();
}
cudaError_t cudaStatus;

View File

@@ -41,7 +41,7 @@ class DenseLayerTest : public ::testing::Test {
void commonTestTeardown(float* d_input) {
// Free device memory
cudaFree(d_input);
cudaDeviceReset();
}
cudaError_t cudaStatus;

View File

@@ -15,5 +15,5 @@ TEST(InputLayerTest, InputForward) {
EXPECT_EQ(cudaStatus, cudaSuccess);
EXPECT_EQ(input, output);
cudaDeviceReset();
}

View File

@@ -68,5 +68,5 @@ TEST(MaxPoolingLayerTest, MaxPoolForwardTest) {
cudaFree(d_input);
cudaFree(d_output);
cudaDeviceReset();
}

View File

@@ -23,5 +23,5 @@ TEST(OutputLayerTest, OutputForward) {
}
cudaFree(d_input);
cudaDeviceReset();
}