• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLIENT_GLOBAL_DATA_H_
17 #define TENSORFLOW_COMPILER_XLA_CLIENT_GLOBAL_DATA_H_
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "absl/types/span.h"
23 #include "tensorflow/compiler/xla/service_interface.h"
24 #include "tensorflow/compiler/xla/xla.pb.h"
25 #include "tensorflow/compiler/xla/xla_data.pb.h"
26 #include "tensorflow/core/platform/macros.h"
27 
28 namespace xla {
29 
30 // A GlobalData object represents a globally-accessible allocation of
31 // data in the associated XLA service.
32 class GlobalData {
33  public:
34   // Gives ownership of the global data handle to this object.
35   GlobalData(ServiceInterface* parent, GlobalDataHandle handle);
36 
37   // Unregisters the wrapped handle, which causes the service to
38   // deallocate the associated data.
39   ~GlobalData();
40 
handle()41   const GlobalDataHandle& handle() const { return handle_; }
42 
43   // Releases a set of GlobalData handles. A single RPC will be issued
44   // per unique ServiceInterface of the given GlobalData objects.
45   static void Release(std::vector<std::unique_ptr<GlobalData>> instances);
46 
47  private:
48   // Detaches the global data handle from the object, such that the destructor
49   // will not try to release it.
Release()50   GlobalDataHandle Release() {
51     parent_ = nullptr;
52     return handle_;
53   }
54 
55   GlobalDataHandle handle_;   // Handle being wrapped.
56   ServiceInterface* parent_;  // Service used to unregister handle_.
57 
58   TF_DISALLOW_COPY_AND_ASSIGN(GlobalData);
59 };
60 
61 }  // namespace xla
62 
63 #endif  // TENSORFLOW_COMPILER_XLA_CLIENT_GLOBAL_DATA_H_
64