mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Add activations test
This commit is contained in:
@@ -10,7 +10,7 @@ include_directories(${CUDAToolkit_INCLUDE_DIRS})
|
||||
# Add project source files for the library
|
||||
set(LIBRARY_SOURCES
|
||||
src/utils/cuda_helper.cu
|
||||
src/functions/activations.cu
|
||||
src/kernels/activations.cu
|
||||
src/layers/dense.cu
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ target_link_libraries(${PROJECT_NAME} CUDA::cublas CUDA::cudart)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/utils
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/functions
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/kernels
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/layers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
find_package(GTest REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
|
||||
add_executable(test_dense layers/test_dense.cu)
|
||||
add_executable(test_main layers/test_dense.cu kernels/test_activations.cu)
|
||||
|
||||
add_library(test_utils
|
||||
test_utils/test_cublas_fixture.cu
|
||||
@@ -9,6 +9,6 @@ add_library(test_utils
|
||||
|
||||
target_include_directories(test_utils PUBLIC test_utils)
|
||||
|
||||
target_link_libraries(test_dense ${GTEST_BOTH_LIBRARIES} CUDANet test_utils)
|
||||
target_link_libraries(test_main ${GTEST_BOTH_LIBRARIES} CUDANet test_utils)
|
||||
|
||||
add_test(NAME TestDense COMMAND test_dense)
|
||||
add_test(NAME TestMain COMMAND test_main)
|
||||
49
test/kernels/test_activations.cu
Normal file
49
test/kernels/test_activations.cu
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <cuda_runtime_api.h>
|
||||
#include <driver_types.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "activations.cuh"
|
||||
#include "gtest/gtest.h"
|
||||
#include "test_cublas_fixture.cuh"
|
||||
|
||||
class ActivationsTest : public CublasTestFixture {
|
||||
protected:
|
||||
cudaError_t cudaStatus;
|
||||
cublasStatus_t cublasStatus;
|
||||
};
|
||||
|
||||
TEST_F(ActivationsTest, SigmoidSanityCheck) {
|
||||
|
||||
float input[3] = {-100.0f, 0.0f, 100.0f};
|
||||
|
||||
std::vector<float> expected_output = {0.0f, 0.5f, 1.0f};
|
||||
|
||||
float* d_input;
|
||||
float* d_output;
|
||||
|
||||
cudaStatus = cudaMalloc((void**)&d_input, sizeof(float) * 3);
|
||||
EXPECT_EQ(cudaStatus, cudaSuccess);
|
||||
|
||||
cudaStatus = cudaMalloc((void**)&d_output, sizeof(float) * 3);
|
||||
EXPECT_EQ(cudaStatus, cudaSuccess);
|
||||
|
||||
cublasStatus = cublasSetVector(3, sizeof(float), input, 1, d_input, 1);
|
||||
EXPECT_EQ(cublasStatus, CUBLAS_STATUS_SUCCESS);
|
||||
|
||||
sigmoid_kernel<<<1, 3>>>(d_input, d_output, 3);
|
||||
cudaStatus = cudaDeviceSynchronize();
|
||||
EXPECT_EQ(cudaStatus, cudaSuccess);
|
||||
|
||||
std::vector<float> output(3);
|
||||
|
||||
cublasStatus = cublasGetVector(3, sizeof(float), d_output, 1, output.data(), 1);
|
||||
EXPECT_EQ(cublasStatus, CUBLAS_STATUS_SUCCESS);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
EXPECT_NEAR(expected_output[i], output[i], 1e-5);
|
||||
}
|
||||
|
||||
cudaFree(d_input);
|
||||
cudaFree(d_output);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#include <cuda_runtime_api.h>
|
||||
#include <driver_types.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "functions.cuh"
|
||||
#include "gtest/gtest.h"
|
||||
#include "test_cublas_fixture.cuh"
|
||||
|
||||
class FunctionsTest : public CublasTestFixture {
|
||||
protected:
|
||||
cudaError_t cudaStatus;
|
||||
cublasStatus_t cublasStatus;
|
||||
};
|
||||
|
||||
TEST_F(FunctionsTest, sigmoid) {}
|
||||
Reference in New Issue
Block a user