Skip to content

Commit 4ee1c2c

Browse files
jspark1105facebook-github-bot
authored andcommitted
add denormal options (ftz and daz)
Summary: Pull Request resolved: pytorch#15423 Reviewed By: yinghai Differential Revision: D13526340 fbshipit-source-id: de2ecc717b4f778f33a8bf940ed144dbb230c7a8
1 parent 3a6d473 commit 4ee1c2c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

caffe2/core/init_denormals.cc

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#if defined(__SSE3__)
2+
3+
#include <immintrin.h>
4+
5+
#include "caffe2/core/common.h"
6+
#include "caffe2/core/init.h"
7+
8+
C10_DEFINE_int(
9+
caffe2_ftz,
10+
false,
11+
"If true, turn on flushing denormals to zero (FTZ)");
12+
C10_DEFINE_int(
13+
caffe2_daz,
14+
false,
15+
"If true, turn on replacing denormals loaded from memory with zero (DAZ)");
16+
17+
namespace caffe2 {
18+
19+
bool Caffe2SetDenormals(int*, char***) {
20+
if (FLAGS_caffe2_ftz) {
21+
VLOG(1) << "Setting FTZ";
22+
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
23+
}
24+
if (FLAGS_caffe2_daz) {
25+
VLOG(1) << "Setting DAZ";
26+
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
27+
}
28+
return true;
29+
}
30+
31+
REGISTER_CAFFE2_INIT_FUNCTION(
32+
Caffe2SetDenormals,
33+
&Caffe2SetDenormals,
34+
"Set denormal settings.");
35+
36+
} // namespace caffe2
37+
38+
#endif

0 commit comments

Comments
 (0)