Home | History | Annotate | Download | only in platform
      1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #ifndef TENSORFLOW_PLATFORM_DENORMAL_H_
     17 #define TENSORFLOW_PLATFORM_DENORMAL_H_
     18 
     19 #include "tensorflow/core/platform/macros.h"
     20 
     21 namespace tensorflow {
     22 namespace port {
     23 
     24 // Remembers the flush denormal state on construction and restores that same
     25 // state on destruction.
     26 class ScopedRestoreFlushDenormalState {
     27  public:
     28   ScopedRestoreFlushDenormalState();
     29   ~ScopedRestoreFlushDenormalState();
     30 
     31  private:
     32   bool flush_zero_mode_;
     33   bool denormals_zero_mode_;
     34   TF_DISALLOW_COPY_AND_ASSIGN(ScopedRestoreFlushDenormalState);
     35 };
     36 
     37 // While this class is active, denormal floating point numbers are flushed
     38 // to zero.  The destructor restores the original flags.
     39 class ScopedFlushDenormal {
     40  public:
     41   ScopedFlushDenormal();
     42 
     43  private:
     44   ScopedRestoreFlushDenormalState restore_;
     45   TF_DISALLOW_COPY_AND_ASSIGN(ScopedFlushDenormal);
     46 };
     47 
     48 // While this class is active, denormal floating point numbers are not flushed
     49 // to zero.  The destructor restores the original flags.
     50 class ScopedDontFlushDenormal {
     51  public:
     52   ScopedDontFlushDenormal();
     53 
     54  private:
     55   ScopedRestoreFlushDenormalState restore_;
     56   TF_DISALLOW_COPY_AND_ASSIGN(ScopedDontFlushDenormal);
     57 };
     58 
     59 }  // namespace port
     60 }  // namespace tensorflow
     61 
     62 #endif  // TENSORFLOW_PLATFORM_DENORMAL_H_
     63