mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Migrate Activation layer
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "activation.cuh"
|
||||
#include "activation.hpp"
|
||||
#include "activation_functions.cuh"
|
||||
#include "cuda_helper.cuh"
|
||||
#include "matmul.cuh"
|
||||
@@ -9,8 +8,7 @@
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
Activation::Activation(ActivationType activation, const int length)
|
||||
: activationType(activation), length(length) {
|
||||
void Activation::initCUDA() {
|
||||
if (activationType == SOFTMAX) {
|
||||
d_softmax_sum = nullptr;
|
||||
CUDA_CHECK(cudaMalloc((void**)&d_softmax_sum, sizeof(float) * length));
|
||||
@@ -22,14 +20,14 @@ Activation::Activation(ActivationType activation, const int length)
|
||||
gridSize = (length + BLOCK_SIZE - 1) / BLOCK_SIZE;
|
||||
}
|
||||
|
||||
Activation::~Activation() {
|
||||
void Activation::delCUDA() {
|
||||
if (activationType == SOFTMAX) {
|
||||
CUDA_CHECK(cudaFree(d_softmax_sum));
|
||||
CUDA_CHECK(cudaFree(d_max));
|
||||
}
|
||||
}
|
||||
|
||||
void Activation::activate(float* d_input) {
|
||||
void Activation::activateCUDA(float* d_input) {
|
||||
|
||||
// float sum = 0.0f;
|
||||
|
||||
31
src/layers/activation.cpp
Normal file
31
src/layers/activation.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "activation.hpp"
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
Activation::Activation(ActivationType activation, const int length)
|
||||
: activationType(activation), length(length) {
|
||||
#ifdef USE_CUDA
|
||||
initCUDA();
|
||||
#endif
|
||||
}
|
||||
|
||||
Activation::~Activation() {
|
||||
#ifdef USE_CUDA
|
||||
delCUDA();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Activation::activateCPU(float* input) {
|
||||
throw std::logic_error("Not implemented");
|
||||
}
|
||||
|
||||
void Activation::activate(float* input) {
|
||||
#ifdef USE_CUDA
|
||||
activateCUDA(input);
|
||||
#else
|
||||
activateCPU(input);
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user