Fix fesetround issue when targeting pre-21 Android APIs
PiperOrigin-RevId: 249079196
This commit is contained in:
parent
79ee9071c9
commit
992d22cc3c
@ -15,11 +15,22 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/core/platform/setround.h"
|
||||
|
||||
#include <cfenv> // NOLINT
|
||||
#include "tensorflow/core/platform/logging.h"
|
||||
|
||||
namespace tensorflow {
|
||||
namespace port {
|
||||
|
||||
#if defined(TF_BROKEN_CFENV)
|
||||
|
||||
ScopedSetRound::ScopedSetRound(const int mode) : original_mode_(mode) {
|
||||
// If cfenv usage is broken, assume support only for TONEAREST.
|
||||
DCHECK_EQ(mode, FE_TONEAREST);
|
||||
}
|
||||
|
||||
ScopedSetRound::~ScopedSetRound() {}
|
||||
|
||||
#else
|
||||
|
||||
ScopedSetRound::ScopedSetRound(const int mode) {
|
||||
original_mode_ = std::fegetround();
|
||||
if (original_mode_ < 0) {
|
||||
@ -31,5 +42,7 @@ ScopedSetRound::ScopedSetRound(const int mode) {
|
||||
|
||||
ScopedSetRound::~ScopedSetRound() { std::fesetround(original_mode_); }
|
||||
|
||||
#endif // TF_BROKEN_CFENV
|
||||
|
||||
} // namespace port
|
||||
} // namespace tensorflow
|
||||
|
@ -16,7 +16,16 @@ limitations under the License.
|
||||
#ifndef TENSORFLOW_CORE_PLATFORM_SETROUND_H_
|
||||
#define TENSORFLOW_CORE_PLATFORM_SETROUND_H_
|
||||
|
||||
#include <cfenv>
|
||||
#if defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
|
||||
// The <cfenv> header is broken pre-API 21 for several NDK releases.
|
||||
#define TF_BROKEN_CFENV
|
||||
#endif
|
||||
|
||||
#if defined(TF_BROKEN_CFENV)
|
||||
#include <fenv.h> // NOLINT
|
||||
#else
|
||||
#include <cfenv> // NOLINT
|
||||
#endif
|
||||
|
||||
#include "tensorflow/core/platform/macros.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user