aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/platform/denormal.h
diff options
context:
space:
mode:
authorGravatar Geoffrey Irving <geoffreyi@google.com>2016-02-19 17:10:09 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-02-19 20:32:43 -0800
commitfbf652193590d56ae556fbc1a3ea0ab5c7d5e154 (patch)
tree741948245e394121b124029b8356e14d2a85a3f8 /tensorflow/core/platform/denormal.h
parent28117ca16f60501feb1716f7c4b05cd3f20bee31 (diff)
Flush denormals to zero on both CPU and GPU
Two different mechanisms are required. On the CPU, we push and pop the appropriate processor flags in the executor (for the master thread) *and* in each threadpool thread, since the processor flags are thread local. On the GPU, we set -ftz=true for both nvcc and gcudacc so that kernels that we build flush denormals to zero using instruction flags. Caveat: On GPU, only single precision denormals are flushed to zero; double precision is unchanged. Change: 115114845
Diffstat (limited to 'tensorflow/core/platform/denormal.h')
-rw-r--r--tensorflow/core/platform/denormal.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/tensorflow/core/platform/denormal.h b/tensorflow/core/platform/denormal.h
new file mode 100644
index 0000000000..f2f6309233
--- /dev/null
+++ b/tensorflow/core/platform/denormal.h
@@ -0,0 +1,40 @@
+/* Copyright 2015 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#ifndef TENSORFLOW_PLATFORM_DENORMAL_H_
+#define TENSORFLOW_PLATFORM_DENORMAL_H_
+
+#include "tensorflow/core/platform/macros.h"
+
+namespace tensorflow {
+namespace port {
+
+// While this class is active, denormal floating point numbers are flushed
+// to zero. The destructor restores the original flags.
+class ScopedFlushDenormal {
+ public:
+ ScopedFlushDenormal();
+ ~ScopedFlushDenormal();
+
+ private:
+ bool flush_zero_mode_;
+ bool denormals_zero_mode_;
+ TF_DISALLOW_COPY_AND_ASSIGN(ScopedFlushDenormal);
+};
+
+} // namespace port
+} // namespace tensorflow
+
+#endif // TENSORFLOW_PLATFORM_DENORMAL_H_