mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-06 17:54:27 +00:00
Remove cublas dependency
This commit is contained in:
@@ -4,15 +4,11 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "activations.cuh"
|
||||
#include "test_cublas_fixture.cuh"
|
||||
|
||||
class ActivationsTest : public CublasTestFixture {
|
||||
protected:
|
||||
cudaError_t cudaStatus;
|
||||
cublasStatus_t cublasStatus;
|
||||
};
|
||||
TEST(ActivationsTest, SigmoidSanityCheck) {
|
||||
|
||||
cudaError_t cudaStatus;
|
||||
|
||||
TEST_F(ActivationsTest, SigmoidSanityCheck) {
|
||||
float input[3] = {-100.0f, 0.0f, 100.0f};
|
||||
|
||||
std::vector<float> expected_output = {0.0f, 0.5f, 1.0f};
|
||||
@@ -26,8 +22,8 @@ TEST_F(ActivationsTest, SigmoidSanityCheck) {
|
||||
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);
|
||||
cudaStatus = cudaMemcpy(d_input, input, sizeof(float) * 3, cudaMemcpyHostToDevice);
|
||||
EXPECT_EQ(cudaStatus, cudaSuccess);
|
||||
|
||||
sigmoid_kernel<<<1, 3>>>(d_input, d_output, 3);
|
||||
cudaStatus = cudaDeviceSynchronize();
|
||||
@@ -35,9 +31,8 @@ TEST_F(ActivationsTest, SigmoidSanityCheck) {
|
||||
|
||||
std::vector<float> output(3);
|
||||
|
||||
cublasStatus =
|
||||
cublasGetVector(3, sizeof(float), d_output, 1, output.data(), 1);
|
||||
EXPECT_EQ(cublasStatus, CUBLAS_STATUS_SUCCESS);
|
||||
cudaStatus = cudaMemcpy(output.data(), d_output, sizeof(float) * 3, cudaMemcpyDeviceToHost);
|
||||
EXPECT_EQ(cudaStatus, cudaSuccess);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
EXPECT_NEAR(expected_output[i], output[i], 1e-5);
|
||||
|
||||
@@ -4,15 +4,10 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "padding.cuh"
|
||||
#include "test_cublas_fixture.cuh"
|
||||
|
||||
class PaddingTest : public CublasTestFixture {
|
||||
protected:
|
||||
cudaError_t cudaStatus;
|
||||
cublasStatus_t cublasStatus;
|
||||
};
|
||||
TEST(PaddingTest, SimplePaddingTest) {
|
||||
cudaError_t cudaStatus;
|
||||
|
||||
TEST_F(PaddingTest, SimplePaddingTest) {
|
||||
int w = 2;
|
||||
int h = 3;
|
||||
int n = 2;
|
||||
@@ -48,9 +43,10 @@ TEST_F(PaddingTest, SimplePaddingTest) {
|
||||
std::vector<float> input = {0.0f, 2.0f, 4.0f, 1.0f, 3.0f, 5.0f,
|
||||
6.0f, 8.0f, 10.0f, 7.0f, 9.0f, 11.0f};
|
||||
|
||||
cublasStatus =
|
||||
cublasSetVector(inputSize, sizeof(float), input.data(), 1, d_input, 1);
|
||||
EXPECT_EQ(cublasStatus, CUBLAS_STATUS_SUCCESS);
|
||||
cudaStatus = cudaMemcpy(
|
||||
d_input, input.data(), sizeof(float) * inputSize, cudaMemcpyHostToDevice
|
||||
);
|
||||
EXPECT_EQ(cudaStatus, cudaSuccess);
|
||||
|
||||
int THREADS_PER_BLOCK = 64;
|
||||
int BLOCKS = paddedSize / THREADS_PER_BLOCK + 1;
|
||||
@@ -69,9 +65,12 @@ TEST_F(PaddingTest, SimplePaddingTest) {
|
||||
};
|
||||
|
||||
std::vector<float> output(paddedSize);
|
||||
cublasStatus = cublasGetVector(
|
||||
paddedSize, sizeof(float), d_padded, 1, output.data(), 1
|
||||
|
||||
cudaStatus = cudaMemcpy(
|
||||
output.data(), d_padded, sizeof(float) * paddedSize,
|
||||
cudaMemcpyDeviceToHost
|
||||
);
|
||||
EXPECT_EQ(cudaStatus, cudaSuccess);
|
||||
|
||||
for (int i = 0; i < paddedSize; i++) {
|
||||
EXPECT_NEAR(expectedOutput[i], output[i], 1e-5);
|
||||
|
||||
Reference in New Issue
Block a user