Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #261 from MyPandaShaoxiang/developing
Browse files Browse the repository at this point in the history
fix normalize
  • Loading branch information
LittleMaer authored Aug 3, 2018
2 parents 3a51e1b + d4f37cf commit 073d2d9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions saber/funcs/impl/cuda/base/cuda_c/saber_normalize.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ template <typename Dtype, bool has_scale, bool shared>
__global__ void normalize_kernel_no_across_spatial(const int size_in_channel, const int n,const int channels, \
const Dtype* scale, const Dtype* bottom_data, Dtype* top_data, const float eps, const int p){

CUDA_KERNEL_LOOP(index, size_in_channel){
CUDA_KERNEL_LOOP(index, size_in_channel * n){
float sqr_sum = 0.f;
int num_index=index/size_in_channel;
int index_in_channel=index%size_in_channel;
Expand All @@ -26,17 +26,16 @@ __global__ void normalize_kernel_no_across_spatial(const int size_in_channel, co
if (p == 1) {
norm = 1.f / (sqr_sum + eps);
} else {
norm = 1.f / (sqrtf(sqr_sum) + eps);
norm = 1.f / sqrtf(sqr_sum + eps);
}
Dtype has_scale_norm=scale[0]*norm;
for (int i = 0; i < channels; ++i) {
if (has_scale) {
if (shared) {
top_data[data_index + i * size_in_channel] = \
bottom_data[data_index + i * size_in_channel] * scale[0] * has_scale_norm;
bottom_data[data_index + i * size_in_channel] * scale[0] * norm;
} else {
top_data[data_index + i * size_in_channel] = \
bottom_data[data_index + i * size_in_channel] * scale[i] * has_scale_norm;
bottom_data[data_index + i * size_in_channel] * scale[i] * norm;
}
} else {
top_data[data_index + i * size_in_channel] = \
Expand Down

0 comments on commit 073d2d9

Please sign in to comment.