1 /* Copyright 2017 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/common_runtime/mkl_cpu_allocator.h" 19 20 #include "tensorflow/core/lib/core/status_test_util.h" 21 #include "tensorflow/core/platform/logging.h" 22 #include "tensorflow/core/platform/test.h" 23 24 namespace tensorflow { 25 26 TEST(MKLBFCAllocatorTest, TestMaxLimit) { 27 AllocatorStats stats; 28 setenv(MklCPUAllocator::kMaxLimitStr, "1000", 1); 29 MklCPUAllocator a; 30 TF_EXPECT_OK(a.Initialize()); 31 a.GetStats(&stats); 32 EXPECT_EQ(stats.bytes_limit, 1000); 33 34 unsetenv(MklCPUAllocator::kMaxLimitStr); 35 TF_EXPECT_OK(a.Initialize()); 36 a.GetStats(&stats); 37 uint64 max_mem_bytes = MklCPUAllocator::kDefaultMaxLimit; 38 #if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) 39 max_mem_bytes = 40 (uint64)sysconf(_SC_PHYS_PAGES) * (uint64)sysconf(_SC_PAGESIZE); 41 #endif 42 EXPECT_EQ(stats.bytes_limit, max_mem_bytes); 43 44 setenv(MklCPUAllocator::kMaxLimitStr, "wrong-input", 1); 45 EXPECT_TRUE(errors::IsInvalidArgument(a.Initialize())); 46 47 setenv(MklCPUAllocator::kMaxLimitStr, "-20", 1); 48 EXPECT_TRUE(errors::IsInvalidArgument(a.Initialize())); 49 } 50 51 } // namespace tensorflow 52 53 #endif // INTEL_MKL 54