mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-06 01:34:22 +00:00
Migrate Activation layer
This commit is contained in:
70
include/layers/activation.hpp
Normal file
70
include/layers/activation.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef CUDANET_ACTIVATION_H
|
||||
#define CUDANET_ACTIVATION_H
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
/**
|
||||
* @brief Activation functions
|
||||
*
|
||||
* SIGMOID: Sigmoid
|
||||
* RELU: Rectified Linear Unit
|
||||
* SOFTMAX: Softmax
|
||||
*
|
||||
*/
|
||||
enum ActivationType { SIGMOID, RELU, SOFTMAX, NONE };
|
||||
|
||||
/**
|
||||
* @brief Utility class that performs activation
|
||||
*
|
||||
*/
|
||||
class Activation {
|
||||
public:
|
||||
|
||||
Activation() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new Activation object
|
||||
*
|
||||
* @param activation Type of activation
|
||||
* @param length Length of the input
|
||||
*/
|
||||
Activation(ActivationType activation, const int length);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Activation object
|
||||
*
|
||||
*/
|
||||
~Activation();
|
||||
|
||||
/**
|
||||
* @brief Run the activation function on the input
|
||||
*
|
||||
* @param d_input Pointer to the input vector on the device
|
||||
*/
|
||||
void activate(float* d_input);
|
||||
|
||||
|
||||
private:
|
||||
ActivationType activationType;
|
||||
int length;
|
||||
|
||||
#ifdef USE_CUDA
|
||||
int gridSize;
|
||||
|
||||
float* d_softmax_sum;
|
||||
float* d_max;
|
||||
|
||||
void activateCUDA(float* d_input);
|
||||
|
||||
void initCUDA();
|
||||
void delCUDA();
|
||||
#else
|
||||
void activateCPU(float* input);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
|
||||
#endif // CUDANET_ACTIVATION_H
|
||||
Reference in New Issue
Block a user