Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
daceml-snitch
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Andrei Ivanov
daceml-snitch
Commits
dfb845ed
Commit
dfb845ed
authored
2 years ago
by
Andrei Ivanov
Browse files
Options
Downloads
Patches
Plain Diff
BatchNorm fwd
parent
ebfdad17
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dnn_kernels/include/batchnorm.h
+10
-0
10 additions, 0 deletions
dnn_kernels/include/batchnorm.h
dnn_kernels/src/batchnorm.c
+50
-0
50 additions, 0 deletions
dnn_kernels/src/batchnorm.c
with
60 additions
and
0 deletions
dnn_kernels/include/batchnorm.h
0 → 100644
+
10
−
0
View file @
dfb845ed
#pragma once
#include
<stddef.h>
void
batch_norm_fp64
(
double
*
dst
,
double
*
src
,
double
*
mu
,
double
*
sigma2
,
double
*
gamma
,
double
*
beta
,
double
eps
,
size_t
N
,
size_t
C
,
size_t
HW
,
size_t
stride_dst_N
,
size_t
stride_dst_C
,
size_t
stride_src_N
,
size_t
stride_src_C
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
dnn_kernels/src/batchnorm.c
0 → 100644
+
50
−
0
View file @
dfb845ed
#include
"batchnorm.h"
#include
<math.h>
#define SQR(x) ((x) * (x))
#define S_(n, c, hw) src[(n) * stride_src_N + (c) * stride_src_C + hw]
#define D_(n, c, hw) dst[(n) * stride_dst_N + (c) * stride_dst_C + hw]
void
batch_norm_fp64
(
double
*
dst
,
double
*
src
,
double
*
mu
,
double
*
sigma2
,
double
*
gamma
,
double
*
beta
,
double
eps
,
size_t
N
,
size_t
C
,
size_t
HW
,
size_t
stride_dst_N
,
size_t
stride_dst_C
,
size_t
stride_src_N
,
size_t
stride_src_C
)
{
// compute mean
for
(
size_t
c
=
0
;
c
<
C
;
c
++
)
{
double
mean
=
0
;
for
(
size_t
n
=
0
;
n
<
N
;
n
++
)
{
for
(
size_t
hw
=
0
;
hw
<
HW
;
hw
++
)
{
mean
+=
S_
(
n
,
c
,
hw
);
}
}
mu
[
c
]
=
mean
/
(
N
*
HW
);
}
// compute variance
for
(
size_t
c
=
0
;
c
<
C
;
c
++
)
{
double
mean
=
mu
[
c
];
double
var
=
0
;
for
(
size_t
n
=
0
;
n
<
N
;
n
++
)
{
for
(
size_t
hw
=
0
;
hw
<
HW
;
hw
++
)
{
double
diff
=
S_
(
n
,
c
,
hw
)
-
mean
;
D_
(
n
,
c
,
hw
)
=
diff
;
var
+=
SQR
(
diff
);
}
}
sigma2
[
c
]
=
var
/
(
N
*
HW
);
}
// compute result
for
(
size_t
c
=
0
;
c
<
C
;
c
++
)
{
double
rsigma
=
1
.
0
/
sqrt
(
sigma2
[
c
]
+
eps
);
double
gamma_c
=
gamma
[
c
];
double
beta_c
=
beta
[
c
];
for
(
size_t
n
=
0
;
n
<
N
;
n
++
)
{
for
(
size_t
hw
=
0
;
hw
<
HW
;
hw
++
)
{
double
diff
=
D_
(
n
,
c
,
hw
);
D_
(
n
,
c
,
hw
)
=
diff
*
rsigma
*
gamma_c
+
beta_c
;
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment