1 | /* Copyright 2022 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 | #ifdef INTEL_MKL |
17 | |
18 | #include "tensorflow/core/util/onednn_env_vars.h" |
19 | |
20 | #include "absl/base/call_once.h" |
21 | #include "tensorflow/core/util/env_var.h" |
22 | |
23 | namespace tensorflow { |
24 | |
25 | bool AreWeightsFrozen() { |
26 | static bool weights_const = false; |
27 | static absl::once_flag once; |
28 | absl::call_once(once, [&] { |
29 | TF_CHECK_OK(ReadBoolFromEnvVar("TF_ONEDNN_ASSUME_FROZEN_WEIGHTS" , |
30 | /*default_value*/ false, &weights_const)); |
31 | }); |
32 | return weights_const; |
33 | } |
34 | |
35 | bool UseSystemAlloc() { |
36 | static bool use_sys_alloc = false; |
37 | static absl::once_flag once; |
38 | absl::call_once(once, [&] { |
39 | TF_CHECK_OK(ReadBoolFromEnvVar("TF_ONEDNN_USE_SYSTEM_ALLOCATOR" , |
40 | /*default_value*/ false, &use_sys_alloc)); |
41 | }); |
42 | return use_sys_alloc; |
43 | } |
44 | |
45 | } // namespace tensorflow |
46 | #endif // INTEL_MKL |
47 | |