-
Notifications
You must be signed in to change notification settings - Fork 1
/
rbm_kernels.cu
36 lines (28 loc) · 1.18 KB
/
rbm_kernels.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "rbm_kernels.h"
__global__ void sigmoid(float *dInputArray, float *dOutputArray, int arraySize) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < arraySize)
dOutputArray[idx] = 1.0 / (1.0 + exp(-dInputArray[idx]));
}
__global__ void greaterThan(float *dLHS, float *dRHS, float *dOutputArray, int arraySize) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < arraySize)
dOutputArray[idx] = dLHS[idx] > dRHS[idx];
}
__global__ void updateWeight(float *dWeights,
float *dPositiveAssociation,
float *dNegativeAssociation,
int weightsNumber,
int examplesNumber,
float learningRate) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < weightsNumber)
dWeights[idx] += learningRate * ((dPositiveAssociation[idx] - dNegativeAssociation[idx]) / examplesNumber);
}
__global__ void subAndSquare(float *a, float *b, int size) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < size) {
float sub = a[idx] - b[idx];
a[idx] = sub * sub;
}
}