-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
efficient implementation of softlabel softmax loss layer (GPU)
- Loading branch information
Showing
4 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
template <typename T> | ||
__device__ void softlabel_softmax_loss_backward(T *prob, T *label, int num, int spatial_dim, int prob_dim) { | ||
int idx = threadIdx.x + blockIdx.x * blockDim.x; | ||
int idx_sp = blockIdx.y; | ||
int idx_y = blockIdx.z; | ||
if (idx >= num || idx_sp >= spatial_dim || idx_y >= prob_dim) | ||
return; | ||
|
||
int loc = idx * (spatial_dim*prob_dim) + idx_y*spatial_dim + idx_sp; | ||
prob[loc] -= label[loc]; | ||
} | ||
|
||
extern "C" { | ||
__global__ void softlabel_softmax_loss_backward_float(float *prob, float *label, int num, int spatial_dim, int prob_dim) { | ||
softlabel_softmax_loss_backward(prob, label, num, spatial_dim, prob_dim); | ||
} | ||
__global__ void softlabel_softmax_loss_backward_double(double *prob, double *label, int num, int spatial_dim, int prob_dim) { | ||
softlabel_softmax_loss_backward(prob, label, num, spatial_dim, prob_dim); | ||
} | ||
} | ||
|
||
// vim: ft=cuda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters