• 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 
27 namespace xla {
28 
29 // A GlobalData object represents a globally-accessible allocation of
30 // data in the associated XLA service.
31 class GlobalData {
32  public:
33   // Gives ownership of the global data handle to this object.
34   GlobalData(ServiceInterface* parent, GlobalDataHandle handle);
35 
36   // Unregisters the wrapped handle, which causes the service to
37   // deallocate the associated data.
38   ~GlobalData();
39 
handle()40   const GlobalDataHandle& handle() const { return handle_; }
41 
42   // Releases a set of GlobalData handles. A single RPC will be issued
43   // per unique ServiceInterface of the given GlobalData objects.
44   static void Release(std::vector<std::unique_ptr<GlobalData>> instances);
45 
46  private:
47   // Detaches the global data handle from the object, such that the destructor
48   // will not try to release it.
Release()49   GlobalDataHandle Release() {
50     parent_ = nullptr;
51     return handle_;
52   }
53 
54   GlobalDataHandle handle_;   // Handle being wrapped.
55   ServiceInterface* parent_;  // Service used to unregister handle_.
56 
57   GlobalData(const GlobalData&) = delete;
58   GlobalData& operator=(const GlobalData&) = delete;
59 };
60 
61 }  // namespace xla
62 
63 #endif  // TENSORFLOW_COMPILER_XLA_CLIENT_GLOBAL_DATA_H_
64