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 #ifndef TENSORFLOW_COMPILER_XLA_PTR_UTIL_H_ 17 #define TENSORFLOW_COMPILER_XLA_PTR_UTIL_H_ 18 19 // As this was moved to tensorflow/core/util, provide indirections here to 20 // maintain current functionality of the library. 21 22 #include <stddef.h> 23 24 #include <memory> 25 #include <type_traits> 26 #include <utility> 27 28 #include "tensorflow/core/util/ptr_util.h" 29 30 namespace xla { 31 32 template <typename T> 33 std::unique_ptr<T> WrapUnique(T* ptr) { 34 return tensorflow::WrapUnique<T>(ptr); 35 } 36 37 template <typename T, typename... Args> 38 typename tensorflow::helper::MakeUniqueResult<T>::scalar MakeUnique( 39 Args&&... args) { 40 return tensorflow::MakeUnique<T, Args...>(std::forward<Args>(args)...); 41 } 42 43 // Overload for array of unknown bound. 44 // The allocation of arrays needs to use the array form of new, 45 // and cannot take element constructor arguments. 46 template <typename T> 47 typename tensorflow::helper::MakeUniqueResult<T>::array MakeUnique(size_t n) { 48 return tensorflow::MakeUnique<T>(n); 49 } 50 51 } // namespace xla 52 53 #endif // TENSORFLOW_COMPILER_XLA_PTR_UTIL_H_ 54