ZTWHHH commited on
Commit
7eb4d21
·
verified ·
1 Parent(s): 7f7ad8b

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/coordination/coordination_service_agent.h +283 -0
  2. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/coordination/coordination_service_error_util.h +60 -0
  3. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/async_service_interface.h +41 -0
  4. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/coordination/grpc_coordination_client.h +34 -0
  5. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/coordination/grpc_coordination_service_impl.h +117 -0
  6. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/grpc_state.h +254 -0
  7. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/abi.h +31 -0
  8. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/base64.h +60 -0
  9. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/bfloat16.h +27 -0
  10. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/blocking_counter.h +80 -0
  11. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/casts.h +31 -0
  12. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/coding.h +71 -0
  13. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/context.h +47 -0
  14. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/cord.h +26 -0
  15. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/cpu_info.h +171 -0
  16. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/ctstring.h +123 -0
  17. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/cuda_libdevice_path.h +49 -0
  18. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/demangle.h +34 -0
  19. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/denormal.h +94 -0
  20. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/dso_loader.h +31 -0
  21. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/dynamic_annotations.h +36 -0
  22. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/env.h +706 -0
  23. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/error_logging.h +29 -0
  24. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/errors.h +646 -0
  25. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/file_statistics.h +39 -0
  26. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/file_system.h +923 -0
  27. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/file_system_helper.h +64 -0
  28. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/fingerprint.h +127 -0
  29. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/gif.h +21 -0
  30. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/hash.h +135 -0
  31. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/host_info.h +58 -0
  32. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/human_readable_json.h +45 -0
  33. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/init_main.h +27 -0
  34. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/jpeg.h +29 -0
  35. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/load_library.h +37 -0
  36. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/logging.h +29 -0
  37. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/macros.h +162 -0
  38. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/mem.h +86 -0
  39. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/ml_dtypes.h +35 -0
  40. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/mutex.h +332 -0
  41. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/net.h +27 -0
  42. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/notification.h +40 -0
  43. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/null_file_system.h +111 -0
  44. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/numa.h +62 -0
  45. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/numbers.h +180 -0
  46. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/path.h +132 -0
  47. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/prefetch.h +45 -0
  48. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/protobuf.h +130 -0
  49. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/ram_file_system.h +358 -0
  50. videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/random.h +38 -0
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/coordination/coordination_service_agent.h ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2021 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_TSL_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_AGENT_H_
17
+ #define TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_AGENT_H_
18
+
19
+ #include <cstdint>
20
+ #include <functional>
21
+ #include <map>
22
+ #include <memory>
23
+ #include <string>
24
+ #include <string_view>
25
+ #include <utility>
26
+ #include <vector>
27
+
28
+ #include "absl/time/time.h"
29
+ #include "tsl/distributed_runtime/call_options.h"
30
+ #include "tsl/distributed_runtime/coordination/coordination_client.h"
31
+ #include "tsl/platform/status.h"
32
+ #include "tsl/platform/statusor.h"
33
+ #include "tsl/protobuf/coordination_service.pb.h"
34
+
35
+ namespace tensorflow {
36
+ class CoordinationServiceConfig;
37
+ }; // namespace tensorflow
38
+
39
+ namespace tsl {
40
+ class Env;
41
+
42
+ // CoordinationServiceAgent defines the interface for tasks to communicate with
43
+ // the coordination service instance (which implements
44
+ // CoordinationServiceInterface). One instance of the agent should be deployed
45
+ // on each task for it to send various requests and stores / retrieves config
46
+ // key-value data to the service.
47
+ //
48
+ // See CoordinationServiceInterface for more details on coordination service.
49
+ //
50
+ // All coordination service errors will have an additional
51
+ // CoordinationServiceError payload to distinguish themselves from RPC failures.
52
+ // The payload can optionally specify the error origin, and if the error is
53
+ // reported by the user via `agent->ReportError()`.
54
+ //
55
+ // Possible service errors:
56
+ // - Internal: Coordination service is not enabled.
57
+ // If it was previously accessible, coordination service
58
+ // has been shut down.
59
+ // - Aborted: Incarnation mismatch during heartbeat (either remote
60
+ // task or coordination service has restarted).
61
+ // - Unavailable: Heartbeat timeout from remote task (failed,
62
+ // crashed or got preempted).
63
+ // - InvalidArgument: Unexpected heartbeat from remote task (not
64
+ // registered or wrong config).
65
+ class CoordinationServiceAgent {
66
+ public:
67
+ using StatusOrValueCallback =
68
+ std::function<void(const StatusOr<std::string>&)>;
69
+ // Collection of key-value pairs in the same directory.
70
+ using StatusOrValueDirCallback = std::function<void(
71
+ const StatusOr<std::vector<tensorflow::KeyValueEntry>>&)>;
72
+ using ChangedKeyValuesCallback =
73
+ std::function<void(const std::map<std::string, std::string>&)>;
74
+
75
+ virtual ~CoordinationServiceAgent() = default;
76
+
77
+ // Initialize coordination service agent.
78
+ virtual Status Initialize(
79
+ tsl::Env* env, std::string_view job_name, int task_id,
80
+ const tensorflow::CoordinationServiceConfig& configs,
81
+ std::unique_ptr<CoordinationClient> leader_client,
82
+ StatusCallback error_fn) = 0;
83
+ virtual Status Initialize(
84
+ tsl::Env* env, const tensorflow::CoordinatedTask& task,
85
+ const tensorflow::CoordinationServiceConfig& configs,
86
+ std::unique_ptr<CoordinationClient> leader_client,
87
+ StatusCallback error_fn) = 0;
88
+
89
+ // Return true if the coordination service agent has been initialized.
90
+ virtual bool IsInitialized() = 0;
91
+
92
+ // Return true if the coordination service agent has successfully connected
93
+ // with the Coordination Service
94
+ virtual bool IsConnected() = 0;
95
+
96
+ // Return true if the coordination service agent has an error state.
97
+ virtual bool IsError() = 0;
98
+
99
+ // Connect to coordination service with the following steps:
100
+ // - connect to service address specified in the config of `server_def`
101
+ // - register itself as a task to the service
102
+ // - start a thread to periodically send heartbeat message with the service
103
+ // Possible service errors:
104
+ // - FailedPrecondition: Agent is not in DISCONNECTED state.
105
+ // - InvalidArgument: Unexpected task registration
106
+ // - Aborted: Duplicate task registration (agent will retry connecting until
107
+ // the configured timeout)
108
+ virtual Status Connect() = 0;
109
+
110
+ // Wait for all tasks to be up and registered. The call blocks until all tasks
111
+ // in the cluster are up, or some error occurs.
112
+ // Possible service errors:
113
+ // - FailedPrecondition: Agent is not in CONNECTED state.
114
+ // - InvalidArgument: Unexpected task request
115
+ virtual Status WaitForAllTasks(
116
+ const tensorflow::DeviceInfo& local_devices) = 0;
117
+
118
+ // Get the device attributes of tasks from remote tasks in the cluster.
119
+ virtual const tensorflow::DeviceInfo& GetClusterDeviceInfo() = 0;
120
+
121
+ // State transition in coordination service agent:
122
+ //
123
+ // Init Connect SetError
124
+ // UNINITIALIZED ---> DISCONNECTED ------> CONNECTED -------> ERROR
125
+ // ^ |
126
+ // |__________________________________|
127
+ // Reset
128
+
129
+ // Get task associated with this agent.
130
+ virtual StatusOr<tensorflow::CoordinatedTask> GetOwnTask() = 0;
131
+
132
+ // Get status of a remote task.
133
+ virtual StatusOr<std::vector<tensorflow::CoordinatedTaskStateInfo>>
134
+ GetTaskState(const std::vector<tensorflow::CoordinatedTask>& task) = 0;
135
+
136
+ // Report error to coordination service. This will invoke the error callback.
137
+ // Note that the error payload will set `is_reported_error` to true, to
138
+ // distinguish user-specified errors from internal service or RPC failures.
139
+ // Possible service errors:
140
+ // - FailedPrecondition: Uninitialized/disconnected/already in error state.
141
+ // - InvalidArgument: Unexpected task request
142
+ virtual Status ReportError(const Status& error) = 0;
143
+
144
+ // Shuts down by disconnecting from the service. Should only be called if
145
+ // agent is connected and no further agent calls (except the destructor) are
146
+ // expected. If `shutdown_barrier_timeout_in_ms` is specified in the config,
147
+ // blocks until all tasks reach the barrier before shutting down together. If
148
+ // the barrier times out, this agent will still disconnect, while an error is
149
+ // reported to other agents that did not reach the barrier on time.
150
+ // Possible service errors:
151
+ // - InvalidArgument: Unexpected task request.
152
+ // - FailedPrecondition: Task was in error state (note: agent is still
153
+ // shut down forcefully).
154
+ virtual Status Shutdown() = 0;
155
+
156
+ // Disconnect from the service, and clean up the internal error status.
157
+ // Possible service errors:
158
+ // - InvalidArgument: Unexpected task request.
159
+ // - FailedPrecondition: task is not in error state/has already
160
+ // disconnected.
161
+ virtual Status Reset() = 0;
162
+
163
+ // Key-value store API.
164
+ // The agent does not need to be connected to utilize the key-value store.
165
+ // There are no concurrency guarantees. To avoid a race / impose an ordering
166
+ // on potentially concurrent ops (e.g. set, delete), use WaitAtBarrier().
167
+
168
+ // Get config key-value from the service.
169
+ // If the key-value is not inserted yet, this is a blocking call that waits
170
+ // until the corresponding key is inserted.
171
+ // - DeadlineExceeded: timed out waiting for key.
172
+ virtual StatusOr<std::string> GetKeyValue(std::string_view key) = 0;
173
+ virtual StatusOr<std::string> GetKeyValue(std::string_view key,
174
+ absl::Duration timeout) = 0;
175
+ // Note: Cancel the underlying RPC call with `call_opts->StartCancel()` and
176
+ // `call_opts->ClearCancelCallback()`.
177
+ virtual std::shared_ptr<CallOptions> GetKeyValueAsync(
178
+ std::string_view, StatusOrValueCallback done) = 0;
179
+
180
+ // Get config key-value from the service.
181
+ // - NotFound: the requested key does not exist.
182
+ virtual StatusOr<std::string> TryGetKeyValue(std::string_view key) = 0;
183
+
184
+ // Get all values under a directory (key).
185
+ // A value is considered to be in the directory if its key is prefixed with
186
+ // the directory.
187
+ // This is not a blocking call. If no keys are found, an empty vector is
188
+ // returned immediately.
189
+ virtual StatusOr<std::vector<tensorflow::KeyValueEntry>> GetKeyValueDir(
190
+ std::string_view key) = 0;
191
+ virtual void GetKeyValueDirAsync(std::string_view key,
192
+ StatusOrValueDirCallback done) = 0;
193
+
194
+ // Insert config key-value to the service.
195
+ // - AlreadyExists: key is already set.
196
+ virtual Status InsertKeyValue(std::string_view key,
197
+ std::string_view value) = 0;
198
+
199
+ // Delete config keys in the coordination service.
200
+ virtual Status DeleteKeyValue(std::string_view key) = 0;
201
+
202
+ // Update the value of a config key.
203
+ virtual Status UpdateKeyValue(std::string_view key,
204
+ std::string_view value) = 0;
205
+
206
+ // Register a callback that will be invoked when the key or keys under the key
207
+ // directory are changed (inserted, deleted, or updated).
208
+ virtual Status StartWatchKey(std::string_view key,
209
+ ChangedKeyValuesCallback on_change) = 0;
210
+ virtual Status StopWatchKey(std::string_view key) = 0;
211
+
212
+ // Blocks until all (or a subset of) tasks are at the barrier or the barrier
213
+ // fails.
214
+ //
215
+ // `barrier_id` should be unique across barriers.
216
+ //
217
+ // The first WaitAtBarrier() call received by the service for a particular
218
+ // barrier_id is special in that it determines the barrier deadline based on
219
+ // timeout duration.
220
+ // However, if subsequent calls by different agents specify a different set of
221
+ // `tasks` for the same `barrier_id`, the barrier will fail instantly.
222
+ // For example,
223
+ // agent_1->WaitAtBarrier(“barrier”, 10min, <<”worker”, 1>, <”worker”, 2>>);
224
+ // agent_2->WaitAtBarrier(“barrier”, 10min, <<”worker”, 2>, <”worker”, 3>>);
225
+ // Barrier fails after agent_2’s call because it specifies a different set of
226
+ // participating tasks.
227
+ //
228
+ // If no tasks are specified (default), the barrier will block for all the
229
+ // connected tasks.
230
+ //
231
+ // Possible service errors:
232
+ // - DeadlineExceeded: Timed out waiting for specified tasks at the barrier.
233
+ // Deadline is determined by the server timestamp when it receives the
234
+ // first WaitAtBarrier() + timeout duration.
235
+ // - Cancelled: One of the tasks called CancelBarrier().
236
+ // - Aborted: Service is shutting down.
237
+ // - Internal: Any participating task is in ERROR state.
238
+ // - InvalidArgument: (1) Conflicting tasks specified by different agents
239
+ // for the same barrier, (2) one of the participating tasks is not in
240
+ // the cluster, or (3) task making the request is not included in the
241
+ // list of participating tasks.
242
+ // - FailedPrecondition: Agent is in UNINITIALIZED or ERROR state. Or the
243
+ // same barrier_id was already used previously.
244
+ virtual Status WaitAtBarrier(
245
+ std::string_view barrier_id, absl::Duration timeout,
246
+ const std::vector<tensorflow::CoordinatedTask>& tasks) = 0;
247
+
248
+ virtual void WaitAtBarrierAsync(
249
+ std::string_view barrier_id, absl::Duration timeout,
250
+ const std::vector<tensorflow::CoordinatedTask>& tasks,
251
+ StatusCallback done) = 0;
252
+
253
+ // Aborts the barrier if it is ongoing.
254
+ // Current and future WaitAtBarrier() calls with the same id will return a
255
+ // CANCELLED error status.
256
+ // Possible service errors:
257
+ // - FailedPrecondition: Barrier has already been passed.
258
+ virtual Status CancelBarrier(std::string_view barrier_id) = 0;
259
+ virtual void CancelBarrierAsync(std::string_view barrier_id,
260
+ StatusCallback done) = 0;
261
+
262
+ // Get unowned Env* that the agent was initialized with.
263
+ virtual StatusOr<tsl::Env*> GetEnv() = 0;
264
+
265
+ protected:
266
+ // Set the service agent to error status and invoke the error callback.
267
+ // Note: different from ReportError, this does not report the error status to
268
+ // remote coordination service.
269
+ virtual void SetError(const Status& error) = 0;
270
+
271
+ // Activate the key-value callback watch.
272
+ virtual Status ActivateWatch(std::string_view,
273
+ const std::map<std::string, std::string>&) = 0;
274
+
275
+ private:
276
+ friend class CoordinationServiceRpcHandler;
277
+ };
278
+
279
+ std::unique_ptr<CoordinationServiceAgent> CreateCoordinationServiceAgent();
280
+
281
+ } // namespace tsl
282
+
283
+ #endif // TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_AGENT_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/coordination/coordination_service_error_util.h ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #ifndef TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_ERROR_UTIL_H_
16
+ #define TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_ERROR_UTIL_H_
17
+
18
+ #include "absl/strings/string_view.h"
19
+ #include "tsl/platform/errors.h"
20
+ #include "tsl/platform/status.h"
21
+ #include "tsl/protobuf/coordination_service.pb.h"
22
+
23
+ namespace tsl {
24
+
25
+ constexpr absl::string_view CoordinationErrorPayloadKey() {
26
+ return "type.googleapis.com/tensorflow.CoordinationServiceError";
27
+ }
28
+
29
+ // Mark error as a coordination service error (as opposed to RPC
30
+ // errors).
31
+ inline Status MakeCoordinationError(Status s) {
32
+ s.SetPayload(CoordinationErrorPayloadKey(), absl::Cord(""));
33
+ return s;
34
+ }
35
+
36
+ // Mark error as a coordination service error (as opposed to RPC
37
+ // errors), and indicate error origin.
38
+ // Errors reported via the agent API by the user should set `is_reported_error`
39
+ // to true.
40
+ inline Status MakeCoordinationError(Status s,
41
+ const tensorflow::CoordinatedTask& origin,
42
+ bool is_reported_error = false) {
43
+ tensorflow::CoordinationServiceError error;
44
+ *error.mutable_source_task() = origin;
45
+ error.set_is_reported_error(is_reported_error);
46
+ s.SetPayload(CoordinationErrorPayloadKey(),
47
+ absl::Cord(error.SerializeAsString()));
48
+ return s;
49
+ }
50
+
51
+ // Mark error as a coordination service error with payload.
52
+ inline Status MakeCoordinationError(
53
+ Status s, const tensorflow::CoordinationServiceError& payload) {
54
+ s.SetPayload(CoordinationErrorPayloadKey(),
55
+ absl::Cord(payload.SerializeAsString()));
56
+ return s;
57
+ }
58
+ } // namespace tsl
59
+
60
+ #endif // TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_SERVICE_ERROR_UTIL_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/async_service_interface.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_DISTRIBUTED_RUNTIME_RPC_ASYNC_SERVICE_INTERFACE_H_
17
+ #define TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_ASYNC_SERVICE_INTERFACE_H_
18
+
19
+ namespace tsl {
20
+
21
+ // Represents an abstract asynchronous service that handles incoming
22
+ // RPCs with a polling loop.
23
+ class AsyncServiceInterface {
24
+ public:
25
+ virtual ~AsyncServiceInterface() {}
26
+
27
+ // A blocking method that should be called to handle incoming RPCs.
28
+ // This method will block until the service shuts down.
29
+ virtual void HandleRPCsLoop() = 0;
30
+
31
+ // Starts shutting down this service.
32
+ //
33
+ // NOTE(mrry): To shut down this service completely, the caller must
34
+ // also shut down any servers that might share ownership of this
35
+ // service's resources (e.g. completion queues).
36
+ virtual void Shutdown() = 0;
37
+ };
38
+
39
+ } // namespace tsl
40
+
41
+ #endif // TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_ASYNC_SERVICE_INTERFACE_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/coordination/grpc_coordination_client.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2021 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_TSL_DISTRIBUTED_RUNTIME_RPC_COORDINATION_GRPC_COORDINATION_CLIENT_H_
17
+ #define TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_COORDINATION_GRPC_COORDINATION_CLIENT_H_
18
+
19
+ #include <memory>
20
+
21
+ #include "tsl/distributed_runtime/coordination/coordination_client.h"
22
+ #include "tsl/distributed_runtime/rpc/grpc_channel.h"
23
+
24
+ namespace tsl {
25
+
26
+ CoordinationClientCache* NewGrpcCoordinationClientCache(
27
+ std::shared_ptr<GrpcChannelCache> channel);
28
+
29
+ CoordinationClient* NewGrpcCoordinationClient(
30
+ std::shared_ptr<::grpc::Channel> channel);
31
+
32
+ } // namespace tsl
33
+
34
+ #endif // TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_COORDINATION_GRPC_COORDINATION_CLIENT_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/coordination/grpc_coordination_service_impl.h ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2021 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_TSL_DISTRIBUTED_RUNTIME_RPC_COORDINATION_GRPC_COORDINATION_SERVICE_IMPL_H_
17
+ #define TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_COORDINATION_GRPC_COORDINATION_SERVICE_IMPL_H_
18
+
19
+ #include <memory>
20
+
21
+ #include "grpcpp/alarm.h"
22
+ #include "grpcpp/completion_queue.h"
23
+ #include "grpcpp/server_builder.h"
24
+ #include "tsl/distributed_runtime/coordination/coordination_service_agent.h"
25
+ #include "tsl/distributed_runtime/coordination/coordination_service_rpc_handler.h"
26
+ #include "tsl/distributed_runtime/rpc/async_service_interface.h"
27
+ #include "tsl/distributed_runtime/rpc/grpc_call.h"
28
+ #include "tsl/distributed_runtime/rpc/grpc_util.h"
29
+ #include "tsl/platform/mutex.h"
30
+ #include "tsl/platform/thread_annotations.h"
31
+ #include "tsl/platform/threadpool.h"
32
+ #include "tsl/protobuf/coordination_service.grpc.pb.h"
33
+ #include "tsl/protobuf/coordination_service.pb.h"
34
+
35
+ namespace tsl {
36
+
37
+ class GrpcCoordinationServiceImpl : public AsyncServiceInterface {
38
+ public:
39
+ template <class RequestMessage, class ResponseMessage>
40
+ using CoordCall = Call<GrpcCoordinationServiceImpl,
41
+ tensorflow::grpc::CoordinationService::AsyncService,
42
+ RequestMessage, ResponseMessage>;
43
+
44
+ GrpcCoordinationServiceImpl(thread::ThreadPool* compute_pool,
45
+ ::grpc::ServerBuilder* server_builder);
46
+ ~GrpcCoordinationServiceImpl() override {}
47
+
48
+ void HandleRPCsLoop() override;
49
+ void Shutdown() override;
50
+ void SetCoordinationServiceAgentInstance(CoordinationServiceAgent* agent) {
51
+ rpc_handler_.SetAgentInstance(agent);
52
+ }
53
+ void SetCoordinationServiceInstance(CoordinationServiceInterface* service) {
54
+ rpc_handler_.SetServiceInstance(service);
55
+ }
56
+ CoordinationServiceRpcHandler* GetRpcHandler() { return &rpc_handler_; }
57
+
58
+ private:
59
+ #define HANDLER(method) \
60
+ void method##Handler(CoordCall<tensorflow::method##Request, \
61
+ tensorflow::method##Response>* call) { \
62
+ tf_shared_lock l(shutdown_mu_); \
63
+ if (shutdown_) { \
64
+ call->SendResponse(ToGrpcStatus( \
65
+ errors::Internal("Coordination service has been shut down."))); \
66
+ return; \
67
+ } \
68
+ compute_pool_.Schedule([this, call]() { \
69
+ rpc_handler_.method##Async(&call->request, &call->response, \
70
+ [call](const Status& s) { \
71
+ call->ClearCancelCallback(); \
72
+ call->SendResponse(ToGrpcStatus(s)); \
73
+ }); \
74
+ }); \
75
+ Call<GrpcCoordinationServiceImpl, \
76
+ tensorflow::grpc::CoordinationService::AsyncService, \
77
+ tensorflow::method##Request, tensorflow::method##Response>:: \
78
+ EnqueueRequest(&service_, cq_.get(), \
79
+ &tensorflow::grpc::CoordinationService::AsyncService:: \
80
+ Request##method, \
81
+ &GrpcCoordinationServiceImpl::method##Handler, \
82
+ /*supports_cancel=*/false); \
83
+ }
84
+ HANDLER(RegisterTask);
85
+ HANDLER(WaitForAllTasks);
86
+ HANDLER(ShutdownTask);
87
+ HANDLER(ResetTask);
88
+ HANDLER(Heartbeat);
89
+ HANDLER(ReportErrorToTask);
90
+ HANDLER(ReportErrorToService);
91
+ HANDLER(GetTaskState);
92
+ HANDLER(InsertKeyValue);
93
+ HANDLER(GetKeyValue);
94
+ HANDLER(TryGetKeyValue);
95
+ HANDLER(GetKeyValueDir);
96
+ HANDLER(DeleteKeyValue);
97
+ HANDLER(Barrier);
98
+ HANDLER(CancelBarrier);
99
+ #undef HANDLER
100
+
101
+ thread::ThreadPool& compute_pool_;
102
+ CoordinationServiceRpcHandler rpc_handler_;
103
+
104
+ mutex shutdown_mu_;
105
+ bool shutdown_ TF_GUARDED_BY(shutdown_mu_);
106
+ std::unique_ptr<::grpc::Alarm> shutdown_alarm_;
107
+
108
+ std::unique_ptr<::grpc::ServerCompletionQueue> cq_;
109
+ tensorflow::grpc::CoordinationService::AsyncService service_;
110
+
111
+ GrpcCoordinationServiceImpl(const GrpcCoordinationServiceImpl&) = delete;
112
+ void operator=(const GrpcCoordinationServiceImpl&) = delete;
113
+ };
114
+
115
+ } // namespace tsl
116
+
117
+ #endif // TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_COORDINATION_GRPC_COORDINATION_SERVICE_IMPL_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/distributed_runtime/rpc/grpc_state.h ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_DISTRIBUTED_RUNTIME_RPC_GRPC_STATE_H_
17
+ #define TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_GRPC_STATE_H_
18
+
19
+ #include <queue>
20
+ #include <string>
21
+ #include <utility>
22
+
23
+ #include "grpcpp/generic/generic_stub.h"
24
+ #include "grpcpp/grpcpp.h"
25
+ #include "absl/status/status.h"
26
+ #include "tsl/distributed_runtime/call_options.h"
27
+ #include "tsl/distributed_runtime/rpc/grpc_client_cq_tag.h"
28
+ #include "tsl/distributed_runtime/rpc/grpc_util.h"
29
+ #include "tsl/platform/errors.h"
30
+ #include "tsl/platform/status.h"
31
+ #include "tsl/platform/strcat.h"
32
+ #include "tsl/platform/threadpool.h"
33
+ #include "tsl/util/env_var.h"
34
+
35
+ namespace tsl {
36
+
37
+ // Object allocated per active RPC.
38
+ // Manage the state of a single asynchronous RPC request. If `max_retries`
39
+ // is greater than 0, the request will be retried for any transient failures.
40
+ // Note: `parse_proto_fn` is used solely to allow TensorFlow's worker service
41
+ // to pass in an optimized function that avoids an unnecessary copy of tensors.
42
+ // That is not implemented as an overload of tsl::GrpcMaybeParseProto because it
43
+ // has dependencies on many TensorFlow-specific absractions.
44
+ template <class Response>
45
+ class RPCState : public GrpcClientCQTag {
46
+ public:
47
+ RPCState(
48
+ ::grpc::GenericStub* stub, ::grpc::CompletionQueue* cq,
49
+ const ::grpc::string& method, const protobuf::Message& request,
50
+ Response* response, StatusCallback done, CallOptions* call_opts,
51
+ thread::ThreadPool* threadpool, int32_t max_retries = 0,
52
+ bool fail_fast = true, const string* target = nullptr,
53
+ std::function<bool(::grpc::ByteBuffer*, Response*)> parse_proto_fn =
54
+ [](::grpc::ByteBuffer* src, Response* dst) {
55
+ return tsl::GrpcMaybeParseProto(src, dst);
56
+ })
57
+ : RPCState(
58
+ stub, cq, method, request, response, std::move(done), call_opts,
59
+ threadpool,
60
+ // 1) If GRPC_FAIL_FAST is set to 'true' or 'false',
61
+ // fail_fast=$GRPC_FAIL_FAST. See b/141948186.
62
+ // 2) Otherwise if GRPC_FAIL_FAST is set to 'use_caller', use the
63
+ // fail_fast from the caller. See b/140260119.
64
+ //
65
+ // Current default: use caller's fail_fast argument.
66
+ //
67
+ // NOTE: Callers mostly set fail_fast=true to prevent job hanging
68
+ // on worker task failures, except a few cases such as GetStatus
69
+ // in cluster initialization and collective param resolution.
70
+ [fail_fast, &done]() -> bool {
71
+ string fail_fast_env;
72
+ TF_CHECK_OK(ReadStringFromEnvVar("GRPC_FAIL_FAST", "use_caller",
73
+ &fail_fast_env));
74
+ string fail_fast_env_lower = absl::AsciiStrToLower(fail_fast_env);
75
+ if (fail_fast_env_lower == "true") {
76
+ return true;
77
+ } else if (fail_fast_env_lower == "use_caller") {
78
+ return fail_fast;
79
+ } else if (fail_fast_env_lower == "false") {
80
+ return false;
81
+ } else {
82
+ string error_message = strings::StrCat(
83
+ "Invalid GRPC_FAIL_FAST config: ", fail_fast_env);
84
+ LOG(WARNING) << error_message;
85
+ done(errors::InvalidArgument(error_message));
86
+ return false;
87
+ }
88
+ }(),
89
+ (call_opts != nullptr ? call_opts->GetTimeout() : 0), max_retries,
90
+ target, parse_proto_fn) {}
91
+
92
+ template <typename Request>
93
+ RPCState(
94
+ ::grpc::GenericStub* stub, ::grpc::CompletionQueue* cq,
95
+ const ::grpc::string& method, const Request& request, Response* response,
96
+ StatusCallback done, CallOptions* call_opts,
97
+ thread::ThreadPool* threadpool, bool fail_fast, int64_t timeout_in_ms,
98
+ int32_t max_retries, const string* target,
99
+ std::function<bool(::grpc::ByteBuffer*, Response*)> parse_proto_fn =
100
+ [](::grpc::ByteBuffer* src, Response* dst) {
101
+ return tsl::GrpcMaybeParseProto(src, dst);
102
+ })
103
+ : call_opts_(call_opts),
104
+ threadpool_(threadpool),
105
+ done_(std::move(done)),
106
+ timeout_in_ms_(timeout_in_ms),
107
+ max_retries_(max_retries),
108
+ cq_(cq),
109
+ stub_(stub),
110
+ method_(method),
111
+ fail_fast_(fail_fast),
112
+ target_(target),
113
+ parse_proto_fn_(std::move(parse_proto_fn)) {
114
+ response_ = response;
115
+ ::grpc::Status s = GrpcMaybeUnparseProto(request, &request_buf_);
116
+ if (!s.ok()) {
117
+ LOG(ERROR) << "GrpcMaybeUnparseProto returned with non-ok status: "
118
+ << s.error_message();
119
+ // Skip retry logic if we fail to parse our request.
120
+ done_(FromGrpcStatus(s));
121
+ delete this;
122
+ return;
123
+ }
124
+ StartCall();
125
+ }
126
+
127
+ void StartCall() {
128
+ context_.reset(new ::grpc::ClientContext());
129
+ context_->set_wait_for_ready(!fail_fast_);
130
+ if (timeout_in_ms_ > 0) {
131
+ context_->set_deadline(
132
+ gpr_time_from_millis(timeout_in_ms_, GPR_TIMESPAN));
133
+ }
134
+ if (call_opts_) {
135
+ call_opts_->SetCancelCallback([this]() { context_->TryCancel(); });
136
+ }
137
+
138
+ VLOG(2) << "Starting call: " << method_;
139
+
140
+ call_ = stub_->PrepareUnaryCall(context_.get(), method_, request_buf_, cq_);
141
+ call_->StartCall();
142
+ call_->Finish(&response_buf_, &status_, this);
143
+ }
144
+
145
+ void OnCompleted(bool ok) override {
146
+ if (call_opts_) {
147
+ call_opts_->ClearCancelCallback();
148
+ }
149
+
150
+ VLOG(2) << "Completed call: " << method_;
151
+
152
+ Status s = FromGrpcStatus(status_);
153
+ if (s.ok() && !ok) {
154
+ // Since this function is only being used for processing the response
155
+ // to Finish for client-side unary calls, ok should never be false
156
+ s.Update(
157
+ errors::Internal("GRPC status is okay but CompletionQueueStatus is "
158
+ "not. This should never happen."));
159
+ }
160
+
161
+ if (s.ok()) {
162
+ if (threadpool_) {
163
+ // Run parse and callback in another thread, returning this
164
+ // one to service more RPCs.
165
+ threadpool_->Schedule([this]() { ParseAndCallDone(); });
166
+ } else {
167
+ ParseAndCallDone();
168
+ }
169
+ return;
170
+ }
171
+
172
+ VLOG(1) << method_ << " returned with non-ok status: " << s
173
+ << " Retries: " << num_retries_ << " Max: " << max_retries_ << "\n"
174
+ << context_->debug_error_string();
175
+ // Retry if we have any attempts left
176
+ if (++num_retries_ <= max_retries_ &&
177
+ (absl::IsUnavailable(s) || absl::IsUnknown(s))) {
178
+ response_buf_.Clear();
179
+ VLOG(1) << "Retrying call for " << method_ << "Retry: " << num_retries_
180
+ << " of " << max_retries_;
181
+
182
+ ComputeRetryBackoffMs(/*min_backoff_ms=*/1, /*max_backoff_ms=*/10000);
183
+ int64_t backoff_us = retry_backoff_ms_ * 1000;
184
+ Env::Default()->SchedClosureAfter(/*micros=*/backoff_us,
185
+ [this]() { StartCall(); });
186
+ } else {
187
+ // Attach additional GRPC error information if any to the final status
188
+ string error_msg = std::string(s.message());
189
+ strings::StrAppend(&error_msg, "\nAdditional GRPC error information");
190
+ if (target_) {
191
+ strings::StrAppend(&error_msg, " from remote target ", *target_);
192
+ }
193
+ strings::StrAppend(&error_msg, " while calling ", method_);
194
+ strings::StrAppend(&error_msg, ":\n:", context_->debug_error_string());
195
+ s = errors::CreateWithUpdatedMessage(s, error_msg);
196
+ // Always treat gRPC cancellation as a derived error. This ensures that
197
+ // other error types are preferred during status aggregation. (gRPC
198
+ // cancellation messages do not contain the original status message).
199
+ if (s.code() == absl::StatusCode::kCancelled) {
200
+ s = StatusGroup::MakeDerived(s);
201
+ }
202
+
203
+ done_(s);
204
+ delete this;
205
+ }
206
+ }
207
+
208
+ void ParseAndCallDone() {
209
+ Status s;
210
+ if (!parse_proto_fn_(&response_buf_, response_)) {
211
+ s.Update(errors::Internal("could not parse rpc response"));
212
+ }
213
+ done_(s);
214
+ delete this;
215
+ }
216
+
217
+ private:
218
+ void ComputeRetryBackoffMs(int min_backoff_ms, int max_backoff_ms) {
219
+ constexpr float kBackoffBase = 1.3;
220
+ if (retry_backoff_ms_ < 0) {
221
+ retry_backoff_ms_ = min_backoff_ms;
222
+ } else {
223
+ retry_backoff_ms_ *= kBackoffBase;
224
+ if (retry_backoff_ms_ > max_backoff_ms) {
225
+ retry_backoff_ms_ = max_backoff_ms;
226
+ }
227
+ }
228
+ }
229
+
230
+ CallOptions* call_opts_;
231
+ std::unique_ptr<::grpc::ClientContext> context_;
232
+ thread::ThreadPool* threadpool_;
233
+ std::unique_ptr<::grpc::GenericClientAsyncResponseReader> call_;
234
+ Response* response_;
235
+ ::grpc::ByteBuffer request_buf_;
236
+ ::grpc::ByteBuffer response_buf_;
237
+ ::grpc::Status status_;
238
+ StatusCallback done_;
239
+ int64_t timeout_in_ms_;
240
+
241
+ size_t num_retries_ = 0;
242
+ size_t max_retries_;
243
+ double retry_backoff_ms_ = -1;
244
+
245
+ ::grpc::CompletionQueue* cq_;
246
+ ::grpc::GenericStub* stub_;
247
+ ::grpc::string method_;
248
+ bool fail_fast_;
249
+ const string* target_;
250
+ std::function<bool(::grpc::ByteBuffer*, Response*)> parse_proto_fn_ = nullptr;
251
+ };
252
+ } // namespace tsl
253
+
254
+ #endif // TENSORFLOW_TSL_DISTRIBUTED_RUNTIME_RPC_GRPC_STATE_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/abi.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_TSL_PLATFORM_ABI_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_ABI_H_
18
+
19
+ #include <string>
20
+
21
+ #include "tsl/platform/types.h"
22
+
23
+ namespace tsl {
24
+ namespace port {
25
+
26
+ std::string MaybeAbiDemangle(const char* name);
27
+
28
+ } // namespace port
29
+ } // namespace tsl
30
+
31
+ #endif // TENSORFLOW_TSL_PLATFORM_ABI_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/base64.h ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_BASE64_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_BASE64_H_
18
+
19
+ #include <string>
20
+
21
+ #include "tsl/platform/status.h"
22
+ #include "tsl/platform/stringpiece.h"
23
+
24
+ namespace tsl {
25
+
26
+ /// \brief Converts data into web-safe base64 encoding.
27
+ ///
28
+ /// See https://en.wikipedia.org/wiki/Base64
29
+ template <typename T>
30
+ Status Base64Encode(StringPiece source, bool with_padding, T* encoded);
31
+ template <typename T>
32
+ Status Base64Encode(StringPiece source,
33
+ T* encoded); // with_padding=false.
34
+
35
+ /// \brief Converts data from web-safe base64 encoding.
36
+ ///
37
+ /// See https://en.wikipedia.org/wiki/Base64
38
+ template <typename T>
39
+ Status Base64Decode(StringPiece data, T* decoded);
40
+
41
+ // Explicit instantiations defined in base64.cc.
42
+ extern template Status Base64Decode<std::string>(StringPiece data,
43
+ std::string* decoded);
44
+ extern template Status Base64Encode<std::string>(StringPiece source,
45
+ std::string* encoded);
46
+ extern template Status Base64Encode<std::string>(StringPiece source,
47
+ bool with_padding,
48
+ std::string* encoded);
49
+
50
+ extern template Status Base64Decode<tstring>(StringPiece data,
51
+ tstring* decoded);
52
+ extern template Status Base64Encode<tstring>(StringPiece source,
53
+ tstring* encoded);
54
+ extern template Status Base64Encode<tstring>(StringPiece source,
55
+ bool with_padding,
56
+ tstring* encoded);
57
+
58
+ } // namespace tsl
59
+
60
+ #endif // TENSORFLOW_TSL_PLATFORM_BASE64_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/bfloat16.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2020 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_TSL_PLATFORM_BFLOAT16_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_BFLOAT16_H_
18
+
19
+ // clang-format off
20
+ #include "Eigen/Core" // from @eigen_archive
21
+ // clang-format on
22
+
23
+ namespace tsl {
24
+ typedef Eigen::bfloat16 bfloat16;
25
+ } // end namespace tsl
26
+
27
+ #endif // TENSORFLOW_TSL_PLATFORM_BFLOAT16_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/blocking_counter.h ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_BLOCKING_COUNTER_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_BLOCKING_COUNTER_H_
18
+
19
+ #include <atomic>
20
+
21
+ #include "tsl/platform/logging.h"
22
+ #include "tsl/platform/mutex.h"
23
+
24
+ namespace tsl {
25
+
26
+ class BlockingCounter {
27
+ public:
28
+ BlockingCounter(int initial_count)
29
+ : state_(initial_count << 1), notified_(false) {
30
+ CHECK_GE(initial_count, 0);
31
+ DCHECK_EQ((initial_count << 1) >> 1, initial_count);
32
+ }
33
+
34
+ ~BlockingCounter() {}
35
+
36
+ inline void DecrementCount() {
37
+ unsigned int v = state_.fetch_sub(2, std::memory_order_acq_rel) - 2;
38
+ if (v != 1) {
39
+ DCHECK_NE(((v + 2) & ~1), 0);
40
+ return; // either count has not dropped to 0, or waiter is not waiting
41
+ }
42
+ mutex_lock l(mu_);
43
+ DCHECK(!notified_);
44
+ notified_ = true;
45
+ cond_var_.notify_all();
46
+ }
47
+
48
+ inline void Wait() {
49
+ unsigned int v = state_.fetch_or(1, std::memory_order_acq_rel);
50
+ if ((v >> 1) == 0) return;
51
+ mutex_lock l(mu_);
52
+ while (!notified_) {
53
+ cond_var_.wait(l);
54
+ }
55
+ }
56
+ // Wait for the specified time, return false iff the count has not dropped to
57
+ // zero before the timeout expired.
58
+ inline bool WaitFor(std::chrono::milliseconds ms) {
59
+ unsigned int v = state_.fetch_or(1, std::memory_order_acq_rel);
60
+ if ((v >> 1) == 0) return true;
61
+ mutex_lock l(mu_);
62
+ while (!notified_) {
63
+ const std::cv_status status = cond_var_.wait_for(l, ms);
64
+ if (status == std::cv_status::timeout) {
65
+ return false;
66
+ }
67
+ }
68
+ return true;
69
+ }
70
+
71
+ private:
72
+ mutex mu_;
73
+ condition_variable cond_var_;
74
+ std::atomic<int> state_; // low bit is waiter flag
75
+ bool notified_;
76
+ };
77
+
78
+ } // namespace tsl
79
+
80
+ #endif // TENSORFLOW_TSL_PLATFORM_BLOCKING_COUNTER_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/casts.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2020 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_TSL_PLATFORM_CASTS_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_CASTS_H_
18
+
19
+ #include "tsl/platform/platform.h"
20
+
21
+ #if defined(PLATFORM_GOOGLE)
22
+ #include "tsl/platform/google/casts.h" // IWYU pragma: export
23
+ #elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \
24
+ defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \
25
+ defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS)
26
+ #include "tsl/platform/default/casts.h" // IWYU pragma: export
27
+ #else
28
+ #error Define the appropriate PLATFORM_<foo> macro for this platform
29
+ #endif
30
+
31
+ #endif // TENSORFLOW_TSL_PLATFORM_CASTS_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/coding.h ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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
+ // Endian-neutral encoding:
17
+ // * Fixed-length numbers are encoded with least-significant byte first
18
+ // * In addition we support variable length "varint" encoding
19
+ // * Strings are encoded prefixed by their length in varint format
20
+
21
+ #ifndef TENSORFLOW_TSL_PLATFORM_CODING_H_
22
+ #define TENSORFLOW_TSL_PLATFORM_CODING_H_
23
+
24
+ #include "tsl/platform/stringpiece.h"
25
+ #include "tsl/platform/types.h"
26
+
27
+ namespace tsl {
28
+ namespace core {
29
+
30
+ // Maximum number of bytes occupied by a varint32.
31
+ static const int kMaxVarint32Bytes = 5;
32
+
33
+ // Maximum number of bytes occupied by a varint64.
34
+ static const int kMaxVarint64Bytes = 10;
35
+
36
+ // Lower-level versions of Put... that write directly into a character buffer
37
+ // REQUIRES: dst has enough space for the value being written
38
+ extern void EncodeFixed16(char* dst, uint16 value);
39
+ extern void EncodeFixed32(char* dst, uint32 value);
40
+ extern void EncodeFixed64(char* dst, uint64 value);
41
+ extern void PutFixed16(string* dst, uint16 value);
42
+ extern void PutFixed32(string* dst, uint32 value);
43
+ extern void PutFixed64(string* dst, uint64 value);
44
+
45
+ extern void PutVarint32(string* dst, uint32 value);
46
+ extern void PutVarint64(string* dst, uint64 value);
47
+
48
+ extern void PutVarint32(tstring* dst, uint32 value);
49
+ extern void PutVarint64(tstring* dst, uint64 value);
50
+
51
+ extern bool GetVarint32(StringPiece* input, uint32* value);
52
+ extern bool GetVarint64(StringPiece* input, uint64* value);
53
+
54
+ extern const char* GetVarint32Ptr(const char* p, const char* limit, uint32* v);
55
+ extern const char* GetVarint64Ptr(const char* p, const char* limit, uint64* v);
56
+
57
+ // Internal routine for use by fallback path of GetVarint32Ptr
58
+ extern const char* GetVarint32PtrFallback(const char* p, const char* limit,
59
+ uint32* value);
60
+ extern const char* GetVarint32Ptr(const char* p, const char* limit,
61
+ uint32* value);
62
+ extern char* EncodeVarint32(char* dst, uint32 v);
63
+ extern char* EncodeVarint64(char* dst, uint64 v);
64
+
65
+ // Returns the length of the varint32 or varint64 encoding of "v"
66
+ extern int VarintLength(uint64_t v);
67
+
68
+ } // namespace core
69
+ } // namespace tsl
70
+
71
+ #endif // TENSORFLOW_TSL_PLATFORM_CODING_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/context.h ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_CONTEXT_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_CONTEXT_H_
18
+
19
+ #include "tsl/platform/platform.h"
20
+
21
+ namespace tsl {
22
+
23
+ enum class ContextKind {
24
+ // Initial state with default (empty) values.
25
+ kDefault,
26
+ // Initial state inherited from the creating or scheduling thread.
27
+ kThread,
28
+ };
29
+
30
+ // Context is a container for request-specific information that should be passed
31
+ // to threads that perform related work. The default constructor should capture
32
+ // all relevant context.
33
+ class Context;
34
+
35
+ // Scoped object that sets the current thread's context until the object is
36
+ // destroyed.
37
+ class WithContext;
38
+
39
+ } // namespace tsl
40
+
41
+ #if defined(PLATFORM_GOOGLE)
42
+ #include "tsl/platform/google/context.h" // IWYU pragma: export
43
+ #else
44
+ #include "tsl/platform/default/context.h" // IWYU pragma: export
45
+ #endif
46
+
47
+ #endif // TENSORFLOW_TSL_PLATFORM_CONTEXT_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/cord.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_CORD_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_CORD_H_
18
+
19
+ // It seems CORD doesn't work well with CUDA <= 10.2
20
+ #if !defined(__CUDACC__) || ((defined(__CUDACC__) && CUDA_VERSION > 10020))
21
+ #include "absl/strings/cord.h" // IWYU pragma: export
22
+ #define TF_CORD_SUPPORT 1
23
+
24
+ #endif // __CUDACC__
25
+
26
+ #endif // TENSORFLOW_TSL_PLATFORM_CORD_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/cpu_info.h ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_CPU_INFO_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_CPU_INFO_H_
18
+
19
+ #include <string>
20
+
21
+ // TODO(ahentz): This is not strictly required here but, for historical
22
+ // reasons, many people depend on cpu_info.h in order to use kLittleEndian.
23
+ #include "tsl/platform/byte_order.h"
24
+
25
+ #if defined(_MSC_VER)
26
+ // included so __cpuidex function is available for GETCPUID on Windows
27
+ #include <intrin.h>
28
+ #endif
29
+
30
+ namespace tsl {
31
+ namespace port {
32
+
33
+ // Returns an estimate of the number of schedulable CPUs for this
34
+ // process. Usually, it's constant throughout the lifetime of a
35
+ // process, but it might change if the underlying cluster management
36
+ // software can change it dynamically. If the underlying call fails, a default
37
+ // value (e.g. `4`) may be returned.
38
+ int NumSchedulableCPUs();
39
+
40
+ // Returns an estimate for the maximum parallelism for this process.
41
+ // Applications should avoid running more than this number of threads with
42
+ // intensive workloads concurrently to avoid performance degradation and
43
+ // contention.
44
+ // This value is either the number of schedulable CPUs, or a value specific to
45
+ // the underlying cluster management. Applications should assume this value can
46
+ // change throughout the lifetime of the process. This function must not be
47
+ // called during initialization, i.e., before main() has started.
48
+ int MaxParallelism();
49
+
50
+ // Returns an estimate for the maximum parallelism for this process on the
51
+ // provided numa node, or any numa node if `numa_node` is kNUMANoAffinity.
52
+ // See MaxParallelism() for more information.
53
+ int MaxParallelism(int numa_node);
54
+
55
+ // Returns the total number of CPUs on the system. This number should
56
+ // not change even if the underlying cluster management software may
57
+ // change the number of schedulable CPUs. Unlike `NumSchedulableCPUs`, if the
58
+ // underlying call fails, an invalid value of -1 will be returned;
59
+ // the user must check for validity.
60
+ static constexpr int kUnknownCPU = -1;
61
+ int NumTotalCPUs();
62
+
63
+ // Returns the id of the current CPU. Returns -1 if the current CPU cannot be
64
+ // identified. If successful, the return value will be in [0, NumTotalCPUs()).
65
+ int GetCurrentCPU();
66
+
67
+ // Returns an estimate of the number of hyperthreads per physical core
68
+ // on the CPU
69
+ int NumHyperthreadsPerCore();
70
+
71
+ // Mostly ISA related features that we care about
72
+ enum CPUFeature {
73
+ // Do not change numeric assignments.
74
+ MMX = 0,
75
+ SSE = 1,
76
+ SSE2 = 2,
77
+ SSE3 = 3,
78
+ SSSE3 = 4,
79
+ SSE4_1 = 5,
80
+ SSE4_2 = 6,
81
+ CMOV = 7,
82
+ CMPXCHG8B = 8,
83
+ CMPXCHG16B = 9,
84
+ POPCNT = 10,
85
+ AES = 11,
86
+ AVX = 12,
87
+ RDRAND = 13,
88
+ AVX2 = 14,
89
+ FMA = 15,
90
+ F16C = 16,
91
+ PCLMULQDQ = 17,
92
+ RDSEED = 18,
93
+ ADX = 19,
94
+ SMAP = 20,
95
+
96
+ // Prefetch Vector Data Into Caches with Intent to Write and T1 Hint
97
+ // http://www.felixcloutier.com/x86/PREFETCHWT1.html.
98
+ // You probably want PREFETCHW instead.
99
+ PREFETCHWT1 = 21,
100
+
101
+ BMI1 = 22,
102
+ BMI2 = 23,
103
+ HYPERVISOR = 25, // 0 when on a real CPU, 1 on (well-behaved) hypervisor.
104
+
105
+ // Prefetch Data into Caches in Anticipation of a Write (3D Now!).
106
+ // http://www.felixcloutier.com/x86/PREFETCHW.html
107
+ PREFETCHW = 26,
108
+
109
+ // AVX-512: 512-bit vectors (plus masking, etc.) in Knights Landing,
110
+ // Skylake, Xeon, etc. Each of these entries is a different subset of
111
+ // instructions, various combinations of which occur on various CPU types.
112
+ AVX512F = 27, // Foundation
113
+ AVX512CD = 28, // Conflict detection
114
+ AVX512ER = 29, // Exponential and reciprocal
115
+ AVX512PF = 30, // Prefetching
116
+ AVX512VL = 31, // Shorter vector lengths
117
+ AVX512BW = 32, // Byte and word
118
+ AVX512DQ = 33, // Dword and qword
119
+ AVX512VBMI = 34, // Bit manipulation
120
+ AVX512IFMA = 35, // Integer multiply-add
121
+ AVX512_4VNNIW = 36, // Integer neural network (Intel Xeon Phi only)
122
+ AVX512_4FMAPS = 37, // Floating point neural network (Intel Xeon Phi only)
123
+ AVX512_VNNI = 38, // Integer neural network
124
+ AVX512_BF16 = 39, // Bfloat16 neural network
125
+
126
+ // AVX version of AVX512_VNNI in CPUs such as Alder Lake and Sapphire Rapids.
127
+ AVX_VNNI = 40, // Integer neural network
128
+
129
+ // AMX: Advanced Matrix Extension in Sapphire Rapids.
130
+ // Perform matrix multiplication on the Tile Matrix Multiply (TMUL) unit,
131
+ // supporting two popular data types in neural networks, int8 and bfloat16.
132
+ AMX_TILE = 41, // Tile configuration and load/store
133
+ AMX_INT8 = 42, // Int8 tile matrix multiplication
134
+ AMX_BF16 = 43, // Bfloat16 tile matrix multiplication
135
+
136
+ AVX512_FP16 = 44, // Float16 neural network
137
+ AMX_FP16 = 45, // Float16 tile matrix multiplication
138
+ AVX_NE_CONVERT = 46, // Instructions for faster bfloat16, float16 convert.
139
+ AVX_VNNI_INT8 = 47, // VNNI instructions for combinations of u8, s8 dtypes.
140
+ };
141
+
142
+ enum Aarch64CPU {
143
+ ARM_NEOVERSE_N1 = 0, // ARM NEOVERSE N1
144
+ ARM_NEOVERSE_V1 = 1, // ARM NEOVERSE V1
145
+ };
146
+ // Checks whether the current AArch64 processor is supported.
147
+ bool TestAarch64CPU(Aarch64CPU cpu);
148
+
149
+ // Checks whether the current processor supports one of the features above.
150
+ // Checks CPU registers to return hardware capabilities.
151
+ bool TestCPUFeature(CPUFeature feature);
152
+
153
+ // Returns CPU Vendor string (i.e. 'GenuineIntel', 'AuthenticAMD', etc.)
154
+ std::string CPUVendorIDString();
155
+
156
+ // Returns CPU family.
157
+ int CPUFamily();
158
+
159
+ // Returns CPU model number.
160
+ int CPUModelNum();
161
+
162
+ // Returns nominal core processor cycles per second of each processor.
163
+ double NominalCPUFrequency();
164
+
165
+ // Returns num of hyperthreads per physical core
166
+ int CPUIDNumSMT();
167
+
168
+ } // namespace port
169
+ } // namespace tsl
170
+
171
+ #endif // TENSORFLOW_TSL_PLATFORM_CPU_INFO_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/ctstring.h ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2019 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_TSL_PLATFORM_CTSTRING_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_CTSTRING_H_
18
+
19
+ #include <stdint.h>
20
+ #include <stdlib.h>
21
+
22
+ #include "tsl/platform/ctstring_internal.h"
23
+
24
+ // Initialize a new tstring. This must be called before using any function
25
+ // below.
26
+ inline void TF_TString_Init(TF_TString *str);
27
+ // Deallocate a tstring.
28
+ inline void TF_TString_Dealloc(TF_TString *str);
29
+
30
+ // Resizes `str' to `new_size'. This function will appropriately grow or shrink
31
+ // the string buffer to fit a `new_size' string. Grown regions of the string
32
+ // will be initialized with `c'.
33
+ inline char *TF_TString_Resize(TF_TString *str, size_t new_size, char c);
34
+ // Similar to TF_TString_Resize, except the newly allocated regions will remain
35
+ // uninitialized. This is useful if you plan on overwriting the newly grown
36
+ // regions immediately after allocation; doing so will elide a superfluous
37
+ // initialization of the new buffer.
38
+ inline char *TF_TString_ResizeUninitialized(TF_TString *str, size_t new_size);
39
+ // Reserves a string buffer with a capacity of at least `new_cap'.
40
+ // Reserve will not change the size, or the contents of the existing
41
+ // string. This is useful if you have a rough idea of `str's upperbound in
42
+ // size, and want to avoid allocations as you append to `str'. It should not be
43
+ // considered safe to write in the region between size and capacity; explicitly
44
+ // resize before doing so.
45
+ inline void TF_TString_Reserve(TF_TString *str, size_t new_cap);
46
+ // Similar to TF_TString_Reserve, except that we ensure amortized growth, i.e.
47
+ // that we grow the capacity by at least a constant factor >1.
48
+ inline void TF_TString_ReserveAmortized(TF_TString *str, size_t new_cap);
49
+
50
+ // Returns the size of the string.
51
+ inline size_t TF_TString_GetSize(const TF_TString *str);
52
+ // Returns the capacity of the string buffer. It should not be considered safe
53
+ // to write in the region between size and capacity---call Resize or
54
+ // ResizeUninitialized before doing so.
55
+ inline size_t TF_TString_GetCapacity(const TF_TString *str);
56
+ // Returns the underlying type of the tstring:
57
+ // TF_TSTR_SMALL:
58
+ // Small string optimization; the contents of strings
59
+ // less than 22-bytes are stored in the TF_TString struct. This avoids any
60
+ // heap allocations.
61
+ // TF_TSTR_LARGE:
62
+ // Heap allocated string.
63
+ // TF_TSTR_OFFSET: (currently unused)
64
+ // An offset defined string. The string buffer begins at an internally
65
+ // defined little-endian offset from `str'; i.e. GetDataPointer() = str +
66
+ // offset. This type is useful for memory mapping or reading string tensors
67
+ // directly from file, without the need to deserialize the data. For
68
+ // security reasons, it is imperative that OFFSET based string tensors are
69
+ // validated before use, or are from a trusted source.
70
+ // TF_TSTR_VIEW:
71
+ // A view into an unowned character string.
72
+ //
73
+ // NOTE:
74
+ // VIEW and OFFSET types are immutable, so any modifcation via Append,
75
+ // AppendN, or GetMutableDataPointer of a VIEW/OFFSET based tstring will
76
+ // result in a conversion to an owned type (SMALL/LARGE).
77
+ inline TF_TString_Type TF_TString_GetType(const TF_TString *str);
78
+
79
+ // Returns a const char pointer to the start of the underlying string. The
80
+ // underlying character buffer may not be null-terminated.
81
+ inline const char *TF_TString_GetDataPointer(const TF_TString *str);
82
+ // Returns a char pointer to a mutable representation of the underlying string.
83
+ // In the case of VIEW and OFFSET types, `src' is converted to an owned type
84
+ // (SMALL/LARGE). The underlying character buffer may not be null-terminated.
85
+ inline char *TF_TString_GetMutableDataPointer(TF_TString *str);
86
+
87
+ // Sets `dst' as a VIEW type to `src'. `dst' will not take ownership of `src'.
88
+ // It is the user's responsibility to ensure that the lifetime of `src' exceeds
89
+ // `dst'. Any mutations to `dst' via Append, AppendN, or GetMutableDataPointer,
90
+ // will result in a copy into an owned SMALL or LARGE type, and will not modify
91
+ // `src'.
92
+ inline void TF_TString_AssignView(TF_TString *dst, const char *src,
93
+ size_t size);
94
+
95
+ // Appends `src' onto `dst'. If `dst' is a VIEW or OFFSET type, it will first
96
+ // be converted to an owned LARGE or SMALL type. `dst' should not point to
97
+ // memory owned by `src'.
98
+ inline void TF_TString_Append(TF_TString *dst, const TF_TString *src);
99
+ inline void TF_TString_AppendN(TF_TString *dst, const char *src, size_t size);
100
+
101
+ // Copy/Move/Assign semantics
102
+ //
103
+ // | src | dst | complexity
104
+ // Copy | * | SMALL/LARGE | fixed/O(size)
105
+ // Assign | SMALL | SMALL | fixed
106
+ // Assign | OFFSET | VIEW | fixed
107
+ // Assign | VIEW | VIEW | fixed
108
+ // Assign | LARGE | LARGE | O(size)
109
+ // Move | * | same as src | fixed
110
+
111
+ // Copies `src' to `dst'. `dst' will be an owned type (SMALL/LARGE). `src'
112
+ // should not point to memory owned by `dst'.
113
+ inline void TF_TString_Copy(TF_TString *dst, const char *src, size_t size);
114
+ // Assigns a `src' tstring to `dst'. An OFFSET `src' type will yield a `VIEW'
115
+ // `dst'. LARGE `src' types will be copied to a new buffer; all other `src'
116
+ // types will incur a fixed cost.
117
+ inline void TF_TString_Assign(TF_TString *dst, const TF_TString *src);
118
+ // Moves a `src' tstring to `dst'. Moving a LARGE `src' to `dst' will result in
119
+ // a valid but unspecified `src'. This function incurs a fixed cost for all
120
+ // inputs.
121
+ inline void TF_TString_Move(TF_TString *dst, TF_TString *src);
122
+
123
+ #endif // TENSORFLOW_TSL_PLATFORM_CTSTRING_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/cuda_libdevice_path.h ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_CUDA_LIBDEVICE_PATH_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_CUDA_LIBDEVICE_PATH_H_
18
+
19
+ #include <string>
20
+ #include <vector>
21
+
22
+ namespace tsl {
23
+
24
+ // Returns, in order of preference, potential locations of the root directory of
25
+ // the CUDA SDK, which contains sub-folders such as bin, lib64, and nvvm.
26
+ std::vector<std::string> CandidateCudaRoots();
27
+
28
+ // A convenient wrapper for CandidateCudaRoots, which allows supplying a
29
+ // preferred location (inserted first in the output vector), and a flag whether
30
+ // the current working directory should be searched (inserted last).
31
+ inline std::vector<std::string> CandidateCudaRoots(
32
+ std::string preferred_location, bool use_working_directory = true) {
33
+ std::vector<std::string> candidates = CandidateCudaRoots();
34
+ if (!preferred_location.empty()) {
35
+ candidates.insert(candidates.begin(), preferred_location);
36
+ }
37
+
38
+ // "." is our last resort, even though it probably won't work.
39
+ candidates.push_back(".");
40
+
41
+ return candidates;
42
+ }
43
+
44
+ // Returns true if we should prefer ptxas from PATH.
45
+ bool PreferPtxasFromPath();
46
+
47
+ } // namespace tsl
48
+
49
+ #endif // TENSORFLOW_TSL_PLATFORM_CUDA_LIBDEVICE_PATH_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/demangle.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_DEMANGLE_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_DEMANGLE_H_
18
+
19
+ #include "tsl/platform/types.h"
20
+
21
+ namespace tsl {
22
+ namespace port {
23
+
24
+ // If the compiler supports, demangle a mangled symbol name and return
25
+ // the demangled name. Otherwise, returns 'mangled' as is.
26
+ string Demangle(const char* mangled);
27
+ inline string Demangle(const string mangled) {
28
+ return Demangle(mangled.c_str());
29
+ }
30
+
31
+ } // namespace port
32
+ } // namespace tsl
33
+
34
+ #endif // TENSORFLOW_TSL_PLATFORM_DEMANGLE_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/denormal.h ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_DENORMAL_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_DENORMAL_H_
18
+
19
+ #include "tsl/platform/macros.h"
20
+
21
+ namespace tsl {
22
+ namespace port {
23
+
24
+ // State for handling of denormals.
25
+ class DenormalState {
26
+ public:
27
+ DenormalState(bool flush_to_zero, bool denormals_are_zero)
28
+ : flush_to_zero_(flush_to_zero),
29
+ denormals_are_zero_(denormals_are_zero) {}
30
+
31
+ // Output denormals of floating-point operations are flushed to zero.
32
+ inline bool flush_to_zero() const { return flush_to_zero_; }
33
+
34
+ // Input denormals to floating-point operations are treated as zero.
35
+ inline bool denormals_are_zero() const { return denormals_are_zero_; }
36
+
37
+ bool operator==(const DenormalState& other) const;
38
+ bool operator!=(const DenormalState& other) const;
39
+
40
+ private:
41
+ bool flush_to_zero_;
42
+ bool denormals_are_zero_;
43
+ };
44
+
45
+ // Gets the platform's current state for handling denormals.
46
+ DenormalState GetDenormalState();
47
+
48
+ // Sets handling of denormals if the platform allows it. Returns `true` if the
49
+ // platform supports setting denormals to the specified state. Otherwise the
50
+ // denormal state remains unmodified and false is returned.
51
+ bool SetDenormalState(const DenormalState& state);
52
+
53
+ // Remembers the flush denormal state on construction and restores that same
54
+ // state on destruction.
55
+ class ScopedRestoreFlushDenormalState {
56
+ public:
57
+ ScopedRestoreFlushDenormalState();
58
+ ~ScopedRestoreFlushDenormalState();
59
+
60
+ private:
61
+ DenormalState denormal_state_;
62
+ ScopedRestoreFlushDenormalState(const ScopedRestoreFlushDenormalState&) =
63
+ delete;
64
+ void operator=(const ScopedRestoreFlushDenormalState&) = delete;
65
+ };
66
+
67
+ // While this class is active, denormal floating point numbers are flushed
68
+ // to zero. The destructor restores the original flags.
69
+ class ScopedFlushDenormal {
70
+ public:
71
+ ScopedFlushDenormal();
72
+
73
+ private:
74
+ ScopedRestoreFlushDenormalState restore_;
75
+ ScopedFlushDenormal(const ScopedFlushDenormal&) = delete;
76
+ void operator=(const ScopedFlushDenormal&) = delete;
77
+ };
78
+
79
+ // While this class is active, denormal floating point numbers are not flushed
80
+ // to zero. The destructor restores the original flags.
81
+ class ScopedDontFlushDenormal {
82
+ public:
83
+ ScopedDontFlushDenormal();
84
+
85
+ private:
86
+ ScopedRestoreFlushDenormalState restore_;
87
+ ScopedDontFlushDenormal(const ScopedDontFlushDenormal&) = delete;
88
+ void operator=(const ScopedDontFlushDenormal&) = delete;
89
+ };
90
+
91
+ } // namespace port
92
+ } // namespace tsl
93
+
94
+ #endif // TENSORFLOW_TSL_PLATFORM_DENORMAL_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/dso_loader.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2018 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_TSL_PLATFORM_DSO_LOADER_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_DSO_LOADER_H_
18
+
19
+ #include "tsl/platform/platform.h"
20
+
21
+ // Include appropriate platform-dependent implementations
22
+ #if defined(PLATFORM_GOOGLE) || defined(PLATFORM_CHROMIUMOS)
23
+ #include "tsl/platform/google/dso_loader.h"
24
+ #elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \
25
+ defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_WINDOWS)
26
+ #include "tsl/platform/default/dso_loader.h"
27
+ #else
28
+ #error Define the appropriate PLATFORM_<foo> macro for this platform
29
+ #endif
30
+
31
+ #endif // TENSORFLOW_TSL_PLATFORM_DSO_LOADER_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/dynamic_annotations.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_DYNAMIC_ANNOTATIONS_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_DYNAMIC_ANNOTATIONS_H_
18
+
19
+ #include "absl/base/dynamic_annotations.h"
20
+
21
+ #define TF_ANNOTATE_MEMORY_IS_INITIALIZED(ptr, bytes) \
22
+ ANNOTATE_MEMORY_IS_INITIALIZED(ptr, bytes)
23
+
24
+ #define TF_ANNOTATE_BENIGN_RACE(ptr, description) \
25
+ ANNOTATE_BENIGN_RACE(ptr, description)
26
+
27
+ // Tell MemorySanitizer to relax the handling of a given function. All "Use of
28
+ // uninitialized value" warnings from such functions will be suppressed, and
29
+ // all values loaded from memory will be considered fully initialized.
30
+ #ifdef MEMORY_SANITIZER
31
+ #define TF_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
32
+ #else
33
+ #define TF_ATTRIBUTE_NO_SANITIZE_MEMORY
34
+ #endif
35
+
36
+ #endif // TENSORFLOW_TSL_PLATFORM_DYNAMIC_ANNOTATIONS_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/env.h ADDED
@@ -0,0 +1,706 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_ENV_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_ENV_H_
18
+
19
+ #include <stdint.h>
20
+
21
+ #include <memory>
22
+ #include <string>
23
+ #include <unordered_map>
24
+ #include <utility>
25
+ #include <vector>
26
+
27
+ #include "absl/functional/any_invocable.h"
28
+ #include "tsl/platform/env_time.h"
29
+ #include "tsl/platform/errors.h"
30
+ #include "tsl/platform/file_system.h"
31
+ #include "tsl/platform/macros.h"
32
+ #include "tsl/platform/mutex.h"
33
+ #include "tsl/platform/numa.h"
34
+ #include "tsl/platform/platform.h"
35
+ #include "tsl/platform/protobuf.h"
36
+ #include "tsl/platform/status.h"
37
+ #include "tsl/platform/stringpiece.h"
38
+ #include "tsl/platform/types.h"
39
+
40
+ // Delete leaked Windows definitions.
41
+ #ifdef PLATFORM_WINDOWS
42
+ #undef CopyFile
43
+ #undef DeleteFile
44
+ #endif
45
+
46
+ namespace tsl {
47
+
48
+ class Thread;
49
+ struct ThreadOptions;
50
+
51
+ /// \brief An interface used by the tensorflow implementation to
52
+ /// access operating system functionality like the filesystem etc.
53
+ ///
54
+ /// Callers may wish to provide a custom Env object to get fine grain
55
+ /// control.
56
+ ///
57
+ /// All Env implementations are safe for concurrent access from
58
+ /// multiple threads without any external synchronization.
59
+ class Env {
60
+ public:
61
+ Env();
62
+ virtual ~Env() = default;
63
+
64
+ /// \brief Returns a default environment suitable for the current operating
65
+ /// system.
66
+ ///
67
+ /// Sophisticated users may wish to provide their own Env
68
+ /// implementation instead of relying on this default environment.
69
+ ///
70
+ /// The result of Default() belongs to this library and must never be deleted.
71
+ static Env* Default();
72
+
73
+ /// \brief Returns the FileSystem object to handle operations on the file
74
+ /// specified by 'fname'. The FileSystem object is used as the implementation
75
+ /// for the file system related (non-virtual) functions that follow.
76
+ /// Returned FileSystem object is still owned by the Env object and will
77
+ // (might) be destroyed when the environment is destroyed.
78
+ virtual Status GetFileSystemForFile(const std::string& fname,
79
+ FileSystem** result);
80
+
81
+ /// \brief Returns the file system schemes registered for this Env.
82
+ virtual Status GetRegisteredFileSystemSchemes(
83
+ std::vector<std::string>* schemes);
84
+
85
+ /// \brief Register a file system for a scheme.
86
+ virtual Status RegisterFileSystem(const std::string& scheme,
87
+ FileSystemRegistry::Factory factory);
88
+
89
+ /// \brief Register a modular file system for a scheme.
90
+ ///
91
+ /// Same as `RegisterFileSystem` but for filesystems provided by plugins.
92
+ ///
93
+ /// TODO(b/139060984): After all filesystems are converted, make this be the
94
+ /// canonical registration function.
95
+ virtual Status RegisterFileSystem(const std::string& scheme,
96
+ std::unique_ptr<FileSystem> filesystem);
97
+
98
+ Status SetOption(const std::string& scheme, const std::string& key,
99
+ const std::string& value);
100
+
101
+ Status SetOption(const std::string& scheme, const std::string& key,
102
+ const std::vector<string>& values);
103
+
104
+ Status SetOption(const std::string& scheme, const std::string& key,
105
+ const std::vector<int64_t>& values);
106
+
107
+ Status SetOption(const std::string& scheme, const std::string& key,
108
+ const std::vector<double>& values);
109
+
110
+ /// \brief Flush filesystem caches for all registered filesystems.
111
+ Status FlushFileSystemCaches();
112
+
113
+ /// \brief Creates a brand new random access read-only file with the
114
+ /// specified name.
115
+
116
+ /// On success, stores a pointer to the new file in
117
+ /// *result and returns OK. On failure stores NULL in *result and
118
+ /// returns non-OK. If the file does not exist, returns a non-OK
119
+ /// status.
120
+ ///
121
+ /// The returned file may be concurrently accessed by multiple threads.
122
+ ///
123
+ /// The ownership of the returned RandomAccessFile is passed to the caller
124
+ /// and the object should be deleted when is not used. The file object
125
+ /// shouldn't live longer than the Env object.
126
+ Status NewRandomAccessFile(const std::string& fname,
127
+ std::unique_ptr<RandomAccessFile>* result);
128
+
129
+ Status NewRandomAccessFile(const std::string& fname, TransactionToken* token,
130
+ std::unique_ptr<RandomAccessFile>* result) {
131
+ // We duplicate these methods due to Google internal coding style prevents
132
+ // virtual functions with default arguments. See PR #41615.
133
+ return OkStatus();
134
+ }
135
+
136
+ /// \brief Creates an object that writes to a new file with the specified
137
+ /// name.
138
+ ///
139
+ /// Deletes any existing file with the same name and creates a
140
+ /// new file. On success, stores a pointer to the new file in
141
+ /// *result and returns OK. On failure stores NULL in *result and
142
+ /// returns non-OK.
143
+ ///
144
+ /// The returned file will only be accessed by one thread at a time.
145
+ ///
146
+ /// The ownership of the returned WritableFile is passed to the caller
147
+ /// and the object should be deleted when is not used. The file object
148
+ /// shouldn't live longer than the Env object.
149
+ Status NewWritableFile(const std::string& fname,
150
+ std::unique_ptr<WritableFile>* result);
151
+
152
+ Status NewWritableFile(const std::string& fname, TransactionToken* token,
153
+ std::unique_ptr<WritableFile>* result) {
154
+ return OkStatus();
155
+ }
156
+
157
+ /// \brief Creates an object that either appends to an existing file, or
158
+ /// writes to a new file (if the file does not exist to begin with).
159
+ ///
160
+ /// On success, stores a pointer to the new file in *result and
161
+ /// returns OK. On failure stores NULL in *result and returns
162
+ /// non-OK.
163
+ ///
164
+ /// The returned file will only be accessed by one thread at a time.
165
+ ///
166
+ /// The ownership of the returned WritableFile is passed to the caller
167
+ /// and the object should be deleted when is not used. The file object
168
+ /// shouldn't live longer than the Env object.
169
+ Status NewAppendableFile(const std::string& fname,
170
+ std::unique_ptr<WritableFile>* result);
171
+
172
+ Status NewAppendableFile(const std::string& fname, TransactionToken* token,
173
+ std::unique_ptr<WritableFile>* result) {
174
+ return OkStatus();
175
+ }
176
+ /// \brief Creates a readonly region of memory with the file context.
177
+ ///
178
+ /// On success, it returns a pointer to read-only memory region
179
+ /// from the content of file fname. The ownership of the region is passed to
180
+ /// the caller. On failure stores nullptr in *result and returns non-OK.
181
+ ///
182
+ /// The returned memory region can be accessed from many threads in parallel.
183
+ ///
184
+ /// The ownership of the returned ReadOnlyMemoryRegion is passed to the caller
185
+ /// and the object should be deleted when is not used. The memory region
186
+ /// object shouldn't live longer than the Env object.
187
+ Status NewReadOnlyMemoryRegionFromFile(
188
+ const std::string& fname, std::unique_ptr<ReadOnlyMemoryRegion>* result);
189
+
190
+ Status NewReadOnlyMemoryRegionFromFile(
191
+ const std::string& fname, TransactionToken* token,
192
+ std::unique_ptr<ReadOnlyMemoryRegion>* result) {
193
+ return OkStatus();
194
+ }
195
+
196
+ /// Returns OK if the named path exists and NOT_FOUND otherwise.
197
+ Status FileExists(const std::string& fname);
198
+
199
+ Status FileExists(const std::string& fname, TransactionToken* token) {
200
+ return OkStatus();
201
+ }
202
+
203
+ /// Returns true if all the listed files exist, false otherwise.
204
+ /// if status is not null, populate the vector with a detailed status
205
+ /// for each file.
206
+ bool FilesExist(const std::vector<string>& files,
207
+ std::vector<Status>* status);
208
+
209
+ bool FilesExist(const std::vector<string>& files, TransactionToken* token,
210
+ std::vector<Status>* status) {
211
+ return true;
212
+ }
213
+
214
+ /// \brief Stores in *result the names of the children of the specified
215
+ /// directory. The names are relative to "dir".
216
+ ///
217
+ /// Original contents of *results are dropped.
218
+ Status GetChildren(const std::string& dir, std::vector<string>* result);
219
+
220
+ Status GetChildren(const std::string& dir, TransactionToken* token,
221
+ std::vector<string>* result) {
222
+ return OkStatus();
223
+ }
224
+
225
+ /// \brief Returns true if the path matches the given pattern. The wildcards
226
+ /// allowed in pattern are described in FileSystem::GetMatchingPaths.
227
+ virtual bool MatchPath(const std::string& path,
228
+ const std::string& pattern) = 0;
229
+
230
+ /// \brief Given a pattern, stores in *results the set of paths that matches
231
+ /// that pattern. *results is cleared.
232
+ ///
233
+ /// More details about `pattern` in FileSystem::GetMatchingPaths.
234
+ virtual Status GetMatchingPaths(const std::string& pattern,
235
+ std::vector<string>* results);
236
+
237
+ Status GetMatchingPaths(const std::string& pattern, TransactionToken* token,
238
+ std::vector<string>* results) {
239
+ return OkStatus();
240
+ }
241
+
242
+ /// Deletes the named file.
243
+ Status DeleteFile(const std::string& fname);
244
+
245
+ Status DeleteFile(const std::string& fname, TransactionToken* token) {
246
+ return OkStatus();
247
+ }
248
+
249
+ /// \brief Deletes the specified directory and all subdirectories and files
250
+ /// underneath it. This is accomplished by traversing the directory tree
251
+ /// rooted at dirname and deleting entries as they are encountered.
252
+ ///
253
+ /// If dirname itself is not readable or does not exist, *undeleted_dir_count
254
+ /// is set to 1, *undeleted_file_count is set to 0 and an appropriate status
255
+ /// (e.g. NOT_FOUND) is returned.
256
+ ///
257
+ /// If dirname and all its descendants were successfully deleted, TF_OK is
258
+ /// returned and both error counters are set to zero.
259
+ ///
260
+ /// Otherwise, while traversing the tree, undeleted_file_count and
261
+ /// undeleted_dir_count are updated if an entry of the corresponding type
262
+ /// could not be deleted. The returned error status represents the reason that
263
+ /// any one of these entries could not be deleted.
264
+ ///
265
+ /// REQUIRES: undeleted_files, undeleted_dirs to be not null.
266
+ ///
267
+ /// Typical return codes:
268
+ /// * OK - dirname exists and we were able to delete everything underneath.
269
+ /// * NOT_FOUND - dirname doesn't exist
270
+ /// * PERMISSION_DENIED - dirname or some descendant is not writable
271
+ /// * UNIMPLEMENTED - Some underlying functions (like Delete) are not
272
+ /// implemented
273
+ Status DeleteRecursively(const std::string& dirname, int64_t* undeleted_files,
274
+ int64_t* undeleted_dirs);
275
+
276
+ Status DeleteRecursively(const std::string& dirname, TransactionToken* token,
277
+ int64_t* undeleted_files, int64_t* undeleted_dirs) {
278
+ return OkStatus();
279
+ }
280
+
281
+ /// \brief Creates the specified directory and all the necessary
282
+ /// subdirectories. Typical return codes.
283
+ /// * OK - successfully created the directory and sub directories, even if
284
+ /// they were already created.
285
+ /// * PERMISSION_DENIED - dirname or some subdirectory is not writable.
286
+ Status RecursivelyCreateDir(const std::string& dirname);
287
+
288
+ Status RecursivelyCreateDir(const std::string& dirname,
289
+ TransactionToken* token) {
290
+ return OkStatus();
291
+ }
292
+ /// \brief Creates the specified directory. Typical return codes
293
+ /// * OK - successfully created the directory.
294
+ /// * ALREADY_EXISTS - directory already exists.
295
+ /// * PERMISSION_DENIED - dirname is not writable.
296
+ Status CreateDir(const std::string& dirname);
297
+
298
+ Status CreateDir(const std::string& dirname, TransactionToken* token) {
299
+ return OkStatus();
300
+ }
301
+
302
+ /// Deletes the specified directory.
303
+ Status DeleteDir(const std::string& dirname);
304
+
305
+ Status DeleteDir(const std::string& dirname, TransactionToken* token) {
306
+ return OkStatus();
307
+ }
308
+
309
+ /// Obtains statistics for the given path.
310
+ Status Stat(const std::string& fname, FileStatistics* stat);
311
+
312
+ Status Stat(const std::string& fname, TransactionToken* token,
313
+ FileStatistics* stat) {
314
+ return OkStatus();
315
+ }
316
+
317
+ /// \brief Returns whether the given path is a directory or not.
318
+ /// Typical return codes (not guaranteed exhaustive):
319
+ /// * OK - The path exists and is a directory.
320
+ /// * FAILED_PRECONDITION - The path exists and is not a directory.
321
+ /// * NOT_FOUND - The path entry does not exist.
322
+ /// * PERMISSION_DENIED - Insufficient permissions.
323
+ /// * UNIMPLEMENTED - The file factory doesn't support directories.
324
+ Status IsDirectory(const std::string& fname);
325
+
326
+ /// \brief Returns whether the given path is on a file system
327
+ /// that has atomic move capabilities. This can be used
328
+ /// to determine if there needs to be a temp location to safely write objects.
329
+ /// The second boolean argument has_atomic_move contains this information.
330
+ ///
331
+ /// Returns one of the following status codes (not guaranteed exhaustive):
332
+ /// * OK - The path is on a recognized file system,
333
+ /// so has_atomic_move holds the above information.
334
+ /// * UNIMPLEMENTED - The file system of the path hasn't been implemented in
335
+ /// TF
336
+ Status HasAtomicMove(const std::string& path, bool* has_atomic_move);
337
+
338
+ /// Stores the size of `fname` in `*file_size`.
339
+ Status GetFileSize(const std::string& fname, uint64* file_size);
340
+
341
+ Status GetFileSize(const std::string& fname, TransactionToken* token,
342
+ uint64* file_size) {
343
+ return OkStatus();
344
+ }
345
+
346
+ /// \brief Renames file src to target. If target already exists, it will be
347
+ /// replaced.
348
+ Status RenameFile(const std::string& src, const std::string& target);
349
+
350
+ Status RenameFile(const std::string& src, const std::string& target,
351
+ TransactionToken* token) {
352
+ return OkStatus();
353
+ }
354
+
355
+ /// \brief Copy the src to target.
356
+ Status CopyFile(const std::string& src, const std::string& target);
357
+
358
+ Status CopyFile(const std::string& src, const std::string& target,
359
+ TransactionToken* token) {
360
+ return OkStatus();
361
+ }
362
+
363
+ /// \brief starts a new transaction on the filesystem that handles filename
364
+ Status StartTransaction(const std::string& filename,
365
+ TransactionToken** token) {
366
+ *token = nullptr;
367
+ return OkStatus();
368
+ }
369
+
370
+ /// \brief Adds `path` to transaction in `token` if token belongs to
371
+ /// filesystem that handles the path.
372
+ Status AddToTransaction(const std::string& path, TransactionToken* token) {
373
+ return OkStatus();
374
+ }
375
+
376
+ /// \brief Get token for `path` or start a new transaction and add `path` to
377
+ /// it.
378
+ Status GetTokenOrStartTransaction(const std::string& path,
379
+ TransactionToken** token) {
380
+ *token = nullptr;
381
+ return OkStatus();
382
+ }
383
+
384
+ /// \brief Returns the transaction for `path` or nullptr in `token`
385
+ Status GetTransactionForPath(const std::string& path,
386
+ TransactionToken** token) {
387
+ *token = nullptr;
388
+ return OkStatus();
389
+ }
390
+
391
+ /// \brief Finalizes the transaction
392
+ Status EndTransaction(TransactionToken* token) { return OkStatus(); }
393
+
394
+ /// \brief Returns the absolute path of the current executable. It resolves
395
+ /// symlinks if there is any.
396
+ std::string GetExecutablePath();
397
+
398
+ /// Creates a local unique temporary file name. Returns true if success.
399
+ bool LocalTempFilename(std::string* filename);
400
+
401
+ /// Creates a local unique file name that starts with |prefix| and ends with
402
+ /// |suffix|. Returns true if success.
403
+ bool CreateUniqueFileName(std::string* prefix, const std::string& suffix);
404
+
405
+ /// \brief Return the runfiles directory if running under bazel. Returns
406
+ /// the directory the executable is located in if not running under bazel.
407
+ virtual std::string GetRunfilesDir() = 0;
408
+
409
+ // TODO(jeff,sanjay): Add back thread/thread-pool support if needed.
410
+ // TODO(jeff,sanjay): if needed, tighten spec so relative to epoch, or
411
+ // provide a routine to get the absolute time.
412
+
413
+ /// \brief Returns the number of nano-seconds since the Unix epoch.
414
+ virtual uint64 NowNanos() const { return EnvTime::NowNanos(); }
415
+
416
+ /// \brief Returns the number of micro-seconds since the Unix epoch.
417
+ virtual uint64 NowMicros() const { return EnvTime::NowMicros(); }
418
+
419
+ /// \brief Returns the number of seconds since the Unix epoch.
420
+ virtual uint64 NowSeconds() const { return EnvTime::NowSeconds(); }
421
+
422
+ /// Sleeps/delays the thread for the prescribed number of micro-seconds.
423
+ virtual void SleepForMicroseconds(int64_t micros) = 0;
424
+
425
+ /// Returns the process ID of the calling process.
426
+ int32 GetProcessId();
427
+
428
+ /// \brief Returns a new thread that is running fn() and is identified
429
+ /// (for debugging/performance-analysis) by "name".
430
+ ///
431
+ /// Caller takes ownership of the result and must delete it eventually
432
+ /// (the deletion will block until fn() stops running).
433
+ virtual Thread* StartThread(
434
+ const ThreadOptions& thread_options, const std::string& name,
435
+ absl::AnyInvocable<void()> fn) TF_MUST_USE_RESULT = 0;
436
+
437
+ // Returns the thread id of calling thread.
438
+ // Posix: Returns pthread id which is only guaranteed to be unique within a
439
+ // process.
440
+ // Windows: Returns thread id which is unique.
441
+ virtual int32 GetCurrentThreadId() = 0;
442
+
443
+ // Copies current thread name to "name". Returns true if success.
444
+ virtual bool GetCurrentThreadName(std::string* name) = 0;
445
+
446
+ // \brief Schedules the given closure on a thread-pool.
447
+ //
448
+ // NOTE(mrry): This closure may block.
449
+ virtual void SchedClosure(absl::AnyInvocable<void()> closure) = 0;
450
+
451
+ // \brief Schedules the given closure on a thread-pool after the given number
452
+ // of microseconds.
453
+ //
454
+ // NOTE(mrry): This closure must not block.
455
+ virtual void SchedClosureAfter(int64_t micros,
456
+ absl::AnyInvocable<void()> closure) = 0;
457
+
458
+ // \brief Load a dynamic library.
459
+ //
460
+ // Pass "library_filename" to a platform-specific mechanism for dynamically
461
+ // loading a library. The rules for determining the exact location of the
462
+ // library are platform-specific and are not documented here.
463
+ //
464
+ // On success, returns a handle to the library in "*handle" and returns
465
+ // OK from the function.
466
+ // Otherwise returns nullptr in "*handle" and an error status from the
467
+ // function.
468
+ virtual Status LoadDynamicLibrary(const char* library_filename,
469
+ void** handle) = 0;
470
+
471
+ // \brief Get a pointer to a symbol from a dynamic library.
472
+ //
473
+ // "handle" should be a pointer returned from a previous call to LoadLibrary.
474
+ // On success, store a pointer to the located symbol in "*symbol" and return
475
+ // OK from the function. Otherwise, returns nullptr in "*symbol" and an error
476
+ // status from the function.
477
+ virtual Status GetSymbolFromLibrary(void* handle, const char* symbol_name,
478
+ void** symbol) = 0;
479
+
480
+ // \brief build the name of dynamic library.
481
+ //
482
+ // "name" should be name of the library.
483
+ // "version" should be the version of the library or NULL
484
+ // returns the name that LoadLibrary() can use
485
+ virtual std::string FormatLibraryFileName(const std::string& name,
486
+ const std::string& version) = 0;
487
+
488
+ // Returns a possible list of local temporary directories.
489
+ virtual void GetLocalTempDirectories(std::vector<string>* list) = 0;
490
+
491
+ private:
492
+ std::unique_ptr<FileSystemRegistry> file_system_registry_;
493
+ Env(const Env&) = delete;
494
+ void operator=(const Env&) = delete;
495
+ };
496
+
497
+ /// \brief An implementation of Env that forwards all calls to another Env.
498
+ ///
499
+ /// May be useful to clients who wish to override just part of the
500
+ /// functionality of another Env.
501
+ class EnvWrapper : public Env {
502
+ public:
503
+ /// Initializes an EnvWrapper that delegates all calls to *t
504
+ explicit EnvWrapper(Env* t) : target_(t) {}
505
+ ~EnvWrapper() override;
506
+
507
+ /// Returns the target to which this Env forwards all calls
508
+ Env* target() const { return target_; }
509
+
510
+ Status GetFileSystemForFile(const std::string& fname,
511
+ FileSystem** result) override {
512
+ return target_->GetFileSystemForFile(fname, result);
513
+ }
514
+
515
+ Status GetRegisteredFileSystemSchemes(std::vector<string>* schemes) override {
516
+ return target_->GetRegisteredFileSystemSchemes(schemes);
517
+ }
518
+
519
+ Status RegisterFileSystem(const std::string& scheme,
520
+ FileSystemRegistry::Factory factory) override {
521
+ return target_->RegisterFileSystem(scheme, factory);
522
+ }
523
+
524
+ bool MatchPath(const std::string& path, const std::string& pattern) override {
525
+ return target_->MatchPath(path, pattern);
526
+ }
527
+
528
+ uint64 NowMicros() const override { return target_->NowMicros(); }
529
+ void SleepForMicroseconds(int64_t micros) override {
530
+ target_->SleepForMicroseconds(micros);
531
+ }
532
+ Thread* StartThread(const ThreadOptions& thread_options,
533
+ const std::string& name,
534
+ absl::AnyInvocable<void()> fn) override {
535
+ return target_->StartThread(thread_options, name, std::move(fn));
536
+ }
537
+ int32 GetCurrentThreadId() override { return target_->GetCurrentThreadId(); }
538
+ bool GetCurrentThreadName(std::string* name) override {
539
+ return target_->GetCurrentThreadName(name);
540
+ }
541
+ void SchedClosure(absl::AnyInvocable<void()> closure) override {
542
+ target_->SchedClosure(std::move(closure));
543
+ }
544
+ void SchedClosureAfter(int64_t micros,
545
+ absl::AnyInvocable<void()> closure) override {
546
+ target_->SchedClosureAfter(micros, std::move(closure));
547
+ }
548
+ Status LoadDynamicLibrary(const char* library_filename,
549
+ void** handle) override {
550
+ return target_->LoadDynamicLibrary(library_filename, handle);
551
+ }
552
+ Status GetSymbolFromLibrary(void* handle, const char* symbol_name,
553
+ void** symbol) override {
554
+ return target_->GetSymbolFromLibrary(handle, symbol_name, symbol);
555
+ }
556
+ std::string FormatLibraryFileName(const std::string& name,
557
+ const std::string& version) override {
558
+ return target_->FormatLibraryFileName(name, version);
559
+ }
560
+
561
+ std::string GetRunfilesDir() override { return target_->GetRunfilesDir(); }
562
+
563
+ private:
564
+ void GetLocalTempDirectories(std::vector<string>* list) override {
565
+ target_->GetLocalTempDirectories(list);
566
+ }
567
+
568
+ Env* target_;
569
+ };
570
+
571
+ /// Represents a thread used to run a TSL function.
572
+ class Thread {
573
+ public:
574
+ Thread() {}
575
+
576
+ /// Blocks until the thread of control stops running.
577
+ virtual ~Thread();
578
+
579
+ private:
580
+ Thread(const Thread&) = delete;
581
+ void operator=(const Thread&) = delete;
582
+ };
583
+
584
+ /// \brief Cross-platform setenv.
585
+ ///
586
+ /// Since setenv() is not available on windows, we provide an
587
+ /// alternative with platform specific implementations here.
588
+ int setenv(const char* name, const char* value, int overwrite);
589
+
590
+ /// Cross-platform unsetenv.
591
+ int unsetenv(const char* name);
592
+
593
+ /// \brief Options to configure a Thread.
594
+ ///
595
+ /// Note that the options are all hints, and the
596
+ /// underlying implementation may choose to ignore it.
597
+ struct ThreadOptions {
598
+ /// Thread stack size to use (in bytes).
599
+ size_t stack_size = 0; // 0: use system default value
600
+ /// Guard area size to use near thread stacks to use (in bytes)
601
+ size_t guard_size = 0; // 0: use system default value
602
+ int numa_node = port::kNUMANoAffinity;
603
+ };
604
+
605
+ /// A utility routine: copy contents of `src` in file system `src_fs`
606
+ /// to `target` in file system `target_fs`.
607
+ Status FileSystemCopyFile(FileSystem* src_fs, const std::string& src,
608
+ FileSystem* target_fs, const std::string& target);
609
+
610
+ /// A utility routine: reads contents of named file into `*data`
611
+ Status ReadFileToString(Env* env, const std::string& fname, std::string* data);
612
+
613
+ /// A utility routine: write contents of `data` to file named `fname`
614
+ /// (overwriting existing contents, if any).
615
+ Status WriteStringToFile(Env* env, const std::string& fname,
616
+ const StringPiece& data);
617
+
618
+ /// Write binary representation of "proto" to the named file.
619
+ Status WriteBinaryProto(Env* env, const std::string& fname,
620
+ const protobuf::MessageLite& proto);
621
+
622
+ /// Reads contents of named file and parse as binary encoded proto data
623
+ /// and store into `*proto`.
624
+ Status ReadBinaryProto(Env* env, const std::string& fname,
625
+ protobuf::MessageLite* proto);
626
+
627
+ /// Write the text representation of "proto" to the named file.
628
+ inline Status WriteTextProto(Env* /* env */, const std::string& /* fname */,
629
+ const protobuf::MessageLite& /* proto */) {
630
+ return errors::Unimplemented("Can't write text protos with protolite.");
631
+ }
632
+ Status WriteTextProto(Env* env, const std::string& fname,
633
+ const protobuf::Message& proto);
634
+
635
+ /// Read contents of named file and parse as text encoded proto data
636
+ /// and store into `*proto`.
637
+ inline Status ReadTextProto(Env* /* env */, const std::string& /* fname */,
638
+ protobuf::MessageLite* /* proto */) {
639
+ return errors::Unimplemented("Can't parse text protos with protolite.");
640
+ }
641
+ Status ReadTextProto(Env* env, const std::string& fname,
642
+ protobuf::Message* proto);
643
+
644
+ /// Read contents of named file and parse as either text or binary encoded proto
645
+ /// data and store into `*proto`.
646
+ Status ReadTextOrBinaryProto(Env* env, const std::string& fname,
647
+ protobuf::Message* proto);
648
+ Status ReadTextOrBinaryProto(Env* env, const std::string& fname,
649
+ protobuf::MessageLite* proto);
650
+
651
+ // START_SKIP_DOXYGEN
652
+
653
+ // The following approach to register filesystems is deprecated and will be
654
+ // replaced with modular filesystem plugins registration.
655
+ // TODO(b/139060984): After all filesystems are converted, remove this.
656
+ namespace register_file_system {
657
+
658
+ template <typename Factory>
659
+ struct Register {
660
+ Register(Env* env, const std::string& scheme, bool try_modular_filesystems) {
661
+ // TODO(yongtang): Remove legacy file system registration for hdfs/s3/gcs
662
+ // after TF 2.6+.
663
+ if (try_modular_filesystems) {
664
+ const char* env_value = getenv("TF_USE_MODULAR_FILESYSTEM");
665
+ string load_plugin = env_value ? absl::AsciiStrToLower(env_value) : "";
666
+ if (load_plugin == "true" || load_plugin == "1") {
667
+ // We don't register the static filesystem and wait for SIG IO one
668
+ LOG(WARNING) << "Using modular file system for '" << scheme << "'."
669
+ << " Please switch to tensorflow-io"
670
+ << " (https://github.com/tensorflow/io) for file system"
671
+ << " support of '" << scheme << "'.";
672
+ return;
673
+ }
674
+ // If the envvar is missing or not "true"/"1", then fall back to legacy
675
+ // implementation to be backwards compatible.
676
+ }
677
+ // TODO(b/32704451): Don't just ignore the ::tensorflow::Status object!
678
+ env->RegisterFileSystem(scheme, []() -> FileSystem* { return new Factory; })
679
+ .IgnoreError();
680
+ }
681
+ };
682
+
683
+ } // namespace register_file_system
684
+
685
+ // END_SKIP_DOXYGEN
686
+
687
+ } // namespace tsl
688
+
689
+ // Register a FileSystem implementation for a scheme. Files with names that have
690
+ // "scheme://" prefixes are routed to use this implementation.
691
+ #define REGISTER_FILE_SYSTEM_ENV(env, scheme, factory, modular) \
692
+ REGISTER_FILE_SYSTEM_UNIQ_HELPER(__COUNTER__, env, scheme, factory, modular)
693
+ #define REGISTER_FILE_SYSTEM_UNIQ_HELPER(ctr, env, scheme, factory, modular) \
694
+ REGISTER_FILE_SYSTEM_UNIQ(ctr, env, scheme, factory, modular)
695
+ #define REGISTER_FILE_SYSTEM_UNIQ(ctr, env, scheme, factory, modular) \
696
+ static ::tsl::register_file_system::Register<factory> register_ff##ctr \
697
+ TF_ATTRIBUTE_UNUSED = \
698
+ ::tsl::register_file_system::Register<factory>(env, scheme, modular)
699
+
700
+ #define REGISTER_FILE_SYSTEM(scheme, factory) \
701
+ REGISTER_FILE_SYSTEM_ENV(::tsl::Env::Default(), scheme, factory, false);
702
+
703
+ #define REGISTER_LEGACY_FILE_SYSTEM(scheme, factory) \
704
+ REGISTER_FILE_SYSTEM_ENV(::tsl::Env::Default(), scheme, factory, true);
705
+
706
+ #endif // TENSORFLOW_TSL_PLATFORM_ENV_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/error_logging.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2023 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_TSL_PLATFORM_ERROR_LOGGING_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_ERROR_LOGGING_H_
18
+
19
+ #include "absl/status/status.h"
20
+ #include "absl/strings/string_view.h"
21
+
22
+ namespace tsl::error_logging {
23
+
24
+ absl::Status Log(absl::string_view component, absl::string_view subcomponent,
25
+ absl::string_view error_msg);
26
+
27
+ }
28
+
29
+ #endif // TENSORFLOW_TSL_PLATFORM_ERROR_LOGGING_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/errors.h ADDED
@@ -0,0 +1,646 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_ERRORS_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_ERRORS_H_
18
+
19
+ #include <sstream>
20
+ #include <string>
21
+ #include <type_traits>
22
+ #include <unordered_map>
23
+ #include <utility>
24
+ #include <vector>
25
+
26
+ #include "absl/base/attributes.h"
27
+ #include "absl/status/status.h"
28
+ #include "absl/strings/cord.h"
29
+ #include "absl/strings/str_join.h"
30
+ #include "tsl/platform/logging.h"
31
+ #include "tsl/platform/macros.h"
32
+ #include "tsl/platform/status.h"
33
+ #include "tsl/platform/str_util.h"
34
+ #include "tsl/platform/strcat.h"
35
+
36
+ namespace tsl {
37
+ namespace error {
38
+ // NOLINTBEGIN(misc-unused-using-decls)
39
+ // TODO(aminim): figure out the protobuf migration story.
40
+ using tensorflow::error::ABORTED;
41
+ using tensorflow::error::ALREADY_EXISTS;
42
+ using tensorflow::error::CANCELLED;
43
+ using tensorflow::error::Code;
44
+ using tensorflow::error::DATA_LOSS;
45
+ using tensorflow::error::DEADLINE_EXCEEDED;
46
+ using tensorflow::error::FAILED_PRECONDITION;
47
+ using tensorflow::error::INTERNAL;
48
+ using tensorflow::error::INVALID_ARGUMENT;
49
+ using tensorflow::error::NOT_FOUND;
50
+ using tensorflow::error::OK;
51
+ using tensorflow::error::OUT_OF_RANGE;
52
+ using tensorflow::error::PERMISSION_DENIED;
53
+ using tensorflow::error::RESOURCE_EXHAUSTED;
54
+ using tensorflow::error::UNAUTHENTICATED;
55
+ using tensorflow::error::UNAVAILABLE;
56
+ using tensorflow::error::UNIMPLEMENTED;
57
+ using tensorflow::error::UNKNOWN;
58
+ // NOLINTEND(misc-unused-using-decls)
59
+ } // namespace error
60
+
61
+ namespace errors {
62
+
63
+ namespace internal {
64
+
65
+ // The DECLARE_ERROR macro below only supports types that can be converted
66
+ // into StrCat's AlphaNum. For the other types we rely on a slower path
67
+ // through std::stringstream. To add support of a new type, it is enough to
68
+ // make sure there is an operator<<() for it:
69
+ //
70
+ // std::ostream& operator<<(std::ostream& os, const MyType& foo) {
71
+ // os << foo.ToString();
72
+ // return os;
73
+ // }
74
+ // Eventually absl::strings will have native support for this and we will be
75
+ // able to completely remove PrepareForStrCat().
76
+ template <typename T>
77
+ typename std::enable_if<!std::is_convertible<T, strings::AlphaNum>::value,
78
+ std::string>::type
79
+ PrepareForStrCat(const T& t) {
80
+ std::stringstream ss;
81
+ ss << t;
82
+ return ss.str();
83
+ }
84
+ inline const strings::AlphaNum& PrepareForStrCat(const strings::AlphaNum& a) {
85
+ return a;
86
+ }
87
+
88
+ } // namespace internal
89
+
90
+ // Maps UNIX errors into a Status.
91
+ Status IOError(const string& context, int err_number);
92
+
93
+ // Returns all payloads from a Status as a key-value map.
94
+ inline std::unordered_map<std::string, std::string> GetPayloads(
95
+ const ::tsl::Status& status) {
96
+ std::unordered_map<std::string, std::string> payloads;
97
+ status.ForEachPayload(
98
+ [&payloads](::tsl::StringPiece key, const absl::Cord& value) {
99
+ payloads[std::string(key)] = std::string(value);
100
+ });
101
+ return payloads;
102
+ }
103
+
104
+ // Inserts all given payloads into the given status. Will overwrite existing
105
+ // payloads if they exist with the same key.
106
+ inline void InsertPayloads(
107
+ ::tsl::Status& status,
108
+ const std::unordered_map<std::string, std::string>& payloads) {
109
+ for (const auto& payload : payloads) {
110
+ status.SetPayload(payload.first, absl::Cord(payload.second));
111
+ }
112
+ }
113
+
114
+ // Copies all payloads from one Status to another. Will overwrite existing
115
+ // payloads in the destination if they exist with the same key.
116
+ inline void CopyPayloads(const ::tsl::Status& from, ::tsl::Status& to) {
117
+ from.ForEachPayload([&to](::tsl::StringPiece key, const absl::Cord& value) {
118
+ to.SetPayload(key, value);
119
+ });
120
+ }
121
+
122
+ #if defined(PLATFORM_GOOGLE)
123
+ // Creates a new status with the given code, message and payloads.
124
+ inline ::tsl::Status Create(
125
+ absl::StatusCode code, ::tsl::StringPiece message,
126
+ const std::unordered_map<std::string, std::string>& payloads,
127
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
128
+ Status status(code, message, loc);
129
+ InsertPayloads(status, payloads);
130
+ return status;
131
+ }
132
+ // Returns a new Status, replacing its message with the given.
133
+ inline ::tsl::Status CreateWithUpdatedMessage(const ::tsl::Status& status,
134
+ ::tsl::StringPiece message) {
135
+ auto locations = status.GetSourceLocations();
136
+ auto initial_loc =
137
+ locations.empty() ? absl::SourceLocation::current() : locations[0];
138
+ Status new_status = Create(static_cast<absl::StatusCode>(status.code()),
139
+ message, GetPayloads(status), initial_loc);
140
+ if (locations.size() > 1) {
141
+ for (auto loc : locations.subspan(1)) {
142
+ new_status.AddSourceLocation(loc);
143
+ }
144
+ }
145
+ return new_status;
146
+ }
147
+
148
+ #else
149
+ inline ::absl::Status Create(
150
+ absl::StatusCode code, ::tsl::StringPiece message,
151
+ const std::unordered_map<std::string, std::string>& payloads) {
152
+ Status status(code, message);
153
+ InsertPayloads(status, payloads);
154
+ return status;
155
+ }
156
+ // Returns a new Status, replacing its message with the given.
157
+ inline ::tsl::Status CreateWithUpdatedMessage(const ::tsl::Status& status,
158
+ ::tsl::StringPiece message) {
159
+ return Create(static_cast<absl::StatusCode>(status.code()), message,
160
+ GetPayloads(status));
161
+ }
162
+ #endif
163
+
164
+ // Append some context to an error message. Each time we append
165
+ // context put it on a new line, since it is possible for there
166
+ // to be several layers of additional context.
167
+ template <typename... Args>
168
+ void AppendToMessage(::tsl::Status* status, Args... args) {
169
+ auto new_status = CreateWithUpdatedMessage(
170
+ *status, ::tsl::strings::StrCat(status->message(), "\n\t", args...));
171
+ CopyPayloads(*status, new_status);
172
+ *status = std::move(new_status);
173
+ }
174
+
175
+ // For propagating errors when calling a function.
176
+ #define TF_RETURN_IF_ERROR(...) \
177
+ do { \
178
+ ::absl::Status _status = (__VA_ARGS__); \
179
+ if (TF_PREDICT_FALSE(!_status.ok())) { \
180
+ MAYBE_ADD_SOURCE_LOCATION(_status) \
181
+ return _status; \
182
+ } \
183
+ } while (0)
184
+
185
+ #define TF_RETURN_WITH_CONTEXT_IF_ERROR(expr, ...) \
186
+ do { \
187
+ ::tsl::Status _status = (expr); \
188
+ if (TF_PREDICT_FALSE(!_status.ok())) { \
189
+ ::tsl::errors::AppendToMessage(&_status, __VA_ARGS__); \
190
+ return _status; \
191
+ } \
192
+ } while (0)
193
+
194
+ // Convenience functions for generating and using error status.
195
+ // Example usage:
196
+ // status.Update(errors::InvalidArgument("The ", foo, " isn't right."));
197
+ // if (errors::IsInvalidArgument(status)) { ... }
198
+ // switch (status.code()) { case error::INVALID_ARGUMENT: ... }
199
+
200
+ // CANCELLED
201
+ template <typename... Args>
202
+ ::tsl::Status Cancelled(Args... args) {
203
+ return ::tsl::Status(absl::StatusCode::kCancelled,
204
+ ::tsl::strings::StrCat(
205
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
206
+ }
207
+ template <typename... Args>
208
+ ::tsl::Status CancelledWithPayloads(
209
+ const ::tsl::StringPiece& message,
210
+ const std::unordered_map<std::string, std::string>& payloads) {
211
+ return errors::Create(absl::StatusCode::kCancelled, message, payloads);
212
+ }
213
+
214
+ // InvalidArgument
215
+ template <typename... Args>
216
+ ::tsl::Status InvalidArgument(Args... args) {
217
+ return ::tsl::Status(absl::StatusCode::kInvalidArgument,
218
+ ::tsl::strings::StrCat(
219
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
220
+ }
221
+
222
+ #if defined(PLATFORM_GOOGLE)
223
+ // Specialized overloads to capture source location for up to three arguments.
224
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
225
+ ::absl::Status InvalidArgument(
226
+ Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,
227
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
228
+ return ::tsl::Status(
229
+ absl::StatusCode::kInvalidArgument,
230
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
231
+ ::tsl::errors::internal::PrepareForStrCat(arg2),
232
+ ::tsl::errors::internal::PrepareForStrCat(arg3),
233
+ ::tsl::errors::internal::PrepareForStrCat(arg4)),
234
+ loc);
235
+ }
236
+ template <typename Arg1, typename Arg2, typename Arg3>
237
+ ::absl::Status InvalidArgument(
238
+ Arg1 arg1, Arg2 arg2, Arg3 arg3,
239
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
240
+ return ::tsl::Status(
241
+ absl::StatusCode::kInvalidArgument,
242
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
243
+ ::tsl::errors::internal::PrepareForStrCat(arg2),
244
+ ::tsl::errors::internal::PrepareForStrCat(arg3)),
245
+ loc);
246
+ }
247
+ template <typename Arg1, typename Arg2>
248
+ ::absl::Status InvalidArgument(
249
+ Arg1 arg1, Arg2 arg2,
250
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
251
+ return ::tsl::Status(
252
+ absl::StatusCode::kInvalidArgument,
253
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
254
+ ::tsl::errors::internal::PrepareForStrCat(arg2)),
255
+ loc);
256
+ }
257
+ template <typename Arg1>
258
+ ::absl::Status InvalidArgument(
259
+ Arg1 arg1, absl::SourceLocation loc = absl::SourceLocation::current()) {
260
+ return ::tsl::Status(
261
+ absl::StatusCode::kInvalidArgument,
262
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1)),
263
+ loc);
264
+ }
265
+ template <typename... Args>
266
+ ::absl::Status InvalidArgumentWithPayloads(
267
+ const ::tsl::StringPiece& message,
268
+ const std::unordered_map<std::string, std::string>& payloads,
269
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
270
+ return errors::Create(absl::StatusCode::kInvalidArgument, message, payloads,
271
+ loc);
272
+ }
273
+ #else
274
+ template <typename Arg1, typename Arg2, typename Arg3>
275
+ ::absl::Status InvalidArgument(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
276
+ return ::absl::Status(
277
+ absl::StatusCode::kInvalidArgument,
278
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
279
+ ::tsl::errors::internal::PrepareForStrCat(arg2),
280
+ ::tsl::errors::internal::PrepareForStrCat(arg3)));
281
+ }
282
+ template <typename Arg1, typename Arg2>
283
+ ::absl::Status InvalidArgument(Arg1 arg1, Arg2 arg2) {
284
+ return ::absl::Status(
285
+ absl::StatusCode::kInvalidArgument,
286
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
287
+ ::tsl::errors::internal::PrepareForStrCat(arg2)));
288
+ }
289
+ template <typename Arg1>
290
+ ::absl::Status InvalidArgument(Arg1 arg1) {
291
+ return ::absl::Status(
292
+ absl::StatusCode::kInvalidArgument,
293
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1)));
294
+ }
295
+ template <typename... Args>
296
+ ::absl::Status InvalidArgumentWithPayloads(
297
+ const ::tsl::StringPiece& message,
298
+ const std::unordered_map<std::string, std::string>& payloads) {
299
+ return errors::Create(absl::StatusCode::kInvalidArgument, message, payloads);
300
+ }
301
+ #endif
302
+
303
+ // NotFound
304
+ template <typename... Args>
305
+ ::tsl::Status NotFound(Args... args) {
306
+ return ::tsl::Status(absl::StatusCode::kNotFound,
307
+ ::tsl::strings::StrCat(
308
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
309
+ }
310
+ #if defined(PLATFORM_GOOGLE)
311
+ // Specialized overloads to capture source location for up to three arguments.
312
+ template <typename Arg1, typename Arg2, typename Arg3>
313
+ ::absl::Status NotFound(
314
+ Arg1 arg1, Arg2 arg2, Arg3 arg3,
315
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
316
+ return ::tsl::Status(
317
+ absl::StatusCode::kNotFound,
318
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
319
+ ::tsl::errors::internal::PrepareForStrCat(arg2),
320
+ ::tsl::errors::internal::PrepareForStrCat(arg3)),
321
+ loc);
322
+ }
323
+ template <typename Arg1, typename Arg2>
324
+ ::absl::Status NotFound(
325
+ Arg1 arg1, Arg2 arg2,
326
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
327
+ return ::tsl::Status(
328
+ absl::StatusCode::kNotFound,
329
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
330
+ ::tsl::errors::internal::PrepareForStrCat(arg2)),
331
+ loc);
332
+ }
333
+ template <typename Arg1>
334
+ ::absl::Status NotFound(
335
+ Arg1 arg1, absl::SourceLocation loc = absl::SourceLocation::current()) {
336
+ return ::tsl::Status(
337
+ absl::StatusCode::kNotFound,
338
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1)),
339
+ loc);
340
+ }
341
+ template <typename... Args>
342
+ ::absl::Status NotFoundWithPayloads(
343
+ const ::tsl::StringPiece& message,
344
+ const std::unordered_map<std::string, std::string>& payloads,
345
+ absl::SourceLocation loc = absl::SourceLocation::current()) {
346
+ return errors::Create(absl::StatusCode::kNotFound, message, payloads, loc);
347
+ }
348
+ #else
349
+ template <typename Arg1, typename Arg2, typename Arg3>
350
+ ::absl::Status NotFound(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
351
+ return ::absl::Status(
352
+ absl::StatusCode::kNotFound,
353
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
354
+ ::tsl::errors::internal::PrepareForStrCat(arg2),
355
+ ::tsl::errors::internal::PrepareForStrCat(arg3)));
356
+ }
357
+ template <typename Arg1, typename Arg2>
358
+ ::absl::Status NotFound(Arg1 arg1, Arg2 arg2) {
359
+ return ::absl::Status(
360
+ absl::StatusCode::kNotFound,
361
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1),
362
+ ::tsl::errors::internal::PrepareForStrCat(arg2)));
363
+ }
364
+ template <typename Arg1>
365
+ ::absl::Status NotFound(Arg1 arg1) {
366
+ return ::absl::Status(
367
+ absl::StatusCode::kNotFound,
368
+ ::tsl::strings::StrCat(::tsl::errors::internal::PrepareForStrCat(arg1)));
369
+ }
370
+ template <typename... Args>
371
+ ::absl::Status NotFoundWithPayloads(
372
+ const ::tsl::StringPiece& message,
373
+ const std::unordered_map<std::string, std::string>& payloads) {
374
+ return errors::Create(absl::StatusCode::kNotFound, message, payloads);
375
+ }
376
+ #endif
377
+
378
+ // AlreadyExists
379
+ template <typename... Args>
380
+ ::tsl::Status AlreadyExists(Args... args) {
381
+ return ::tsl::Status(absl::StatusCode::kAlreadyExists,
382
+ ::tsl::strings::StrCat(
383
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
384
+ }
385
+ template <typename... Args>
386
+ ::tsl::Status AlreadyExistsWithPayloads(
387
+ const ::tsl::StringPiece& message,
388
+ const std::unordered_map<std::string, std::string>& payloads) {
389
+ return errors::Create(absl::StatusCode::kAlreadyExists, message, payloads);
390
+ }
391
+
392
+ // ResourceExhausted
393
+ template <typename... Args>
394
+ ::tsl::Status ResourceExhausted(Args... args) {
395
+ return ::tsl::Status(absl::StatusCode::kResourceExhausted,
396
+ ::tsl::strings::StrCat(
397
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
398
+ }
399
+ template <typename... Args>
400
+ ::tsl::Status ResourceExhaustedWithPayloads(
401
+ const ::tsl::StringPiece& message,
402
+ const std::unordered_map<std::string, std::string>& payloads) {
403
+ return errors::Create(absl::StatusCode::kResourceExhausted, message,
404
+ payloads);
405
+ }
406
+
407
+ // Unavailable
408
+ template <typename... Args>
409
+ ::tsl::Status Unavailable(Args... args) {
410
+ return ::tsl::Status(absl::StatusCode::kUnavailable,
411
+ ::tsl::strings::StrCat(
412
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
413
+ }
414
+ template <typename... Args>
415
+ ::tsl::Status UnavailableWithPayloads(
416
+ const ::tsl::StringPiece& message,
417
+ const std::unordered_map<std::string, std::string>& payloads) {
418
+ return errors::Create(absl::StatusCode::kUnavailable, message, payloads);
419
+ }
420
+
421
+ // FailedPrecondition
422
+ template <typename... Args>
423
+ ::tsl::Status FailedPrecondition(Args... args) {
424
+ return ::tsl::Status(absl::StatusCode::kFailedPrecondition,
425
+ ::tsl::strings::StrCat(
426
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
427
+ }
428
+ template <typename... Args>
429
+ ::tsl::Status FailedPreconditionWithPayloads(
430
+ const ::tsl::StringPiece& message,
431
+ const std::unordered_map<std::string, std::string>& payloads) {
432
+ return errors::Create(absl::StatusCode::kFailedPrecondition, message,
433
+ payloads);
434
+ }
435
+
436
+ // OutOfRange
437
+ template <typename... Args>
438
+ ::tsl::Status OutOfRange(Args... args) {
439
+ return ::tsl::Status(absl::StatusCode::kOutOfRange,
440
+ ::tsl::strings::StrCat(
441
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
442
+ }
443
+ template <typename... Args>
444
+ ::tsl::Status OutOfRangeWithPayloads(
445
+ const ::tsl::StringPiece& message,
446
+ const std::unordered_map<std::string, std::string>& payloads) {
447
+ return errors::Create(absl::StatusCode::kOutOfRange, message, payloads);
448
+ }
449
+
450
+ // Unimplemented
451
+ template <typename... Args>
452
+ ::tsl::Status Unimplemented(Args... args) {
453
+ return ::tsl::Status(absl::StatusCode::kUnimplemented,
454
+ ::tsl::strings::StrCat(
455
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
456
+ }
457
+ template <typename... Args>
458
+ ::tsl::Status UnimplementedWithPayloads(
459
+ const ::tsl::StringPiece& message,
460
+ const std::unordered_map<std::string, std::string>& payloads) {
461
+ return errors::Create(absl::StatusCode::kUnimplemented, message, payloads);
462
+ }
463
+
464
+ // Internal
465
+ template <typename... Args>
466
+ ::tsl::Status Internal(Args... args) {
467
+ return ::tsl::Status(absl::StatusCode::kInternal,
468
+ ::tsl::strings::StrCat(
469
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
470
+ }
471
+ template <typename... Args>
472
+ ::tsl::Status InternalWithPayloads(
473
+ const ::tsl::StringPiece& message,
474
+ const std::unordered_map<std::string, std::string>& payloads) {
475
+ return errors::Create(absl::StatusCode::kInternal, message, payloads);
476
+ }
477
+
478
+ // Aborted
479
+ template <typename... Args>
480
+ ::tsl::Status Aborted(Args... args) {
481
+ return ::tsl::Status(absl::StatusCode::kAborted,
482
+ ::tsl::strings::StrCat(
483
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
484
+ }
485
+ template <typename... Args>
486
+ ::tsl::Status AbortedWithPayloads(
487
+ const ::tsl::StringPiece& message,
488
+ const std::unordered_map<std::string, std::string>& payloads) {
489
+ return errors::Create(absl::StatusCode::kAborted, message, payloads);
490
+ }
491
+
492
+ // DeadlineExceeded
493
+ template <typename... Args>
494
+ ::tsl::Status DeadlineExceeded(Args... args) {
495
+ return ::tsl::Status(absl::StatusCode::kDeadlineExceeded,
496
+ ::tsl::strings::StrCat(
497
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
498
+ }
499
+ template <typename... Args>
500
+ ::tsl::Status DeadlineExceededWithPayloads(
501
+ const ::tsl::StringPiece& message,
502
+ const std::unordered_map<std::string, std::string>& payloads) {
503
+ return errors::Create(absl::StatusCode::kDeadlineExceeded, message, payloads);
504
+ }
505
+
506
+ // DataLoss
507
+ template <typename... Args>
508
+ ::tsl::Status DataLoss(Args... args) {
509
+ return ::tsl::Status(absl::StatusCode::kDataLoss,
510
+ ::tsl::strings::StrCat(
511
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
512
+ }
513
+ template <typename... Args>
514
+ ::tsl::Status DataLossWithPayloads(
515
+ const ::tsl::StringPiece& message,
516
+ const std::unordered_map<std::string, std::string>& payloads) {
517
+ return errors::Create(absl::StatusCode::kDataLoss, message, payloads);
518
+ }
519
+
520
+ // Unknown
521
+ template <typename... Args>
522
+ ::tsl::Status Unknown(Args... args) {
523
+ return ::tsl::Status(absl::StatusCode::kUnknown,
524
+ ::tsl::strings::StrCat(
525
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
526
+ }
527
+ template <typename... Args>
528
+ ::tsl::Status UnknownPayloads(
529
+ const ::tsl::StringPiece& message,
530
+ const std::unordered_map<std::string, std::string>& payloads) {
531
+ return errors::Create(absl::StatusCode::kUnknown, message, payloads);
532
+ }
533
+ // PermissionDenied
534
+ template <typename... Args>
535
+ ::tsl::Status PermissionDenied(Args... args) {
536
+ return ::tsl::Status(absl::StatusCode::kPermissionDenied,
537
+ ::tsl::strings::StrCat(
538
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
539
+ }
540
+ template <typename... Args>
541
+ ::tsl::Status PermissionDeniedWithPayloads(
542
+ const ::tsl::StringPiece& message,
543
+ const std::unordered_map<std::string, std::string>& payloads) {
544
+ return errors::Create(absl::StatusCode::kPermissionDenied, message, payloads);
545
+ }
546
+
547
+ // Unauthenticated
548
+ template <typename... Args>
549
+ ::tsl::Status Unauthenticated(Args... args) {
550
+ return ::tsl::Status(absl::StatusCode::kUnauthenticated,
551
+ ::tsl::strings::StrCat(
552
+ ::tsl::errors::internal::PrepareForStrCat(args)...));
553
+ }
554
+ template <typename... Args>
555
+ ::tsl::Status UnauthenticatedWithPayloads(
556
+ const ::tsl::StringPiece& message,
557
+ const std::unordered_map<std::string, std::string>& payloads) {
558
+ return errors::Create(absl::StatusCode::kUnauthenticated, message, payloads);
559
+ }
560
+
561
+ bool IsAborted(const Status& status);
562
+ bool IsAlreadyExists(const Status& status);
563
+ bool IsCancelled(const Status& status);
564
+ bool IsDataLoss(const Status& status);
565
+ bool IsDeadlineExceeded(const Status& status);
566
+ bool IsFailedPrecondition(const Status& status);
567
+ bool IsInternal(const Status& status);
568
+ bool IsInvalidArgument(const Status& status);
569
+ bool IsNotFound(const Status& status);
570
+ bool IsOutOfRange(const Status& status);
571
+ bool IsPermissionDenied(const Status& status);
572
+ bool IsResourceExhausted(const Status& status);
573
+ bool IsUnauthenticated(const Status& status);
574
+ bool IsUnavailable(const Status& status);
575
+ bool IsUnimplemented(const Status& status);
576
+ bool IsUnknown(const Status& status);
577
+
578
+ // Produces a formatted string pattern from the name which can uniquely identify
579
+ // this node upstream to produce an informative error message. The pattern
580
+ // followed is: {{node <name>}}
581
+ // Note: The pattern below determines the regex _NODEDEF_NAME_RE in the file
582
+ // tensorflow/python/client/session.py
583
+ // LINT.IfChange
584
+ inline std::string FormatNodeNameForError(absl::string_view name) {
585
+ return strings::StrCat("{{node ", name, "}}");
586
+ }
587
+ // LINT.ThenChange(//tensorflow/python/client/session.py)
588
+ template <typename T>
589
+ std::string FormatNodeNamesForError(const T& names) {
590
+ return absl::StrJoin(
591
+ names, ", ", [](std::string* output, absl::string_view s) {
592
+ ::tsl::strings::StrAppend(output, FormatNodeNameForError(s));
593
+ });
594
+ }
595
+ // LINT.IfChange
596
+ inline std::string FormatColocationNodeForError(absl::string_view name) {
597
+ return strings::StrCat("{{colocation_node ", name, "}}");
598
+ }
599
+ // LINT.ThenChange(//tensorflow/python/framework/error_interpolation.py)
600
+ template <typename T, typename = std::enable_if_t<
601
+ !std::is_convertible_v<T, absl::string_view>>>
602
+ std::string FormatColocationNodeForError(const T& names) {
603
+ return absl::StrJoin(
604
+ names, ", ", [](std::string* output, absl::string_view s) {
605
+ ::tsl::strings::StrAppend(output, FormatColocationNodeForError(s));
606
+ });
607
+ }
608
+
609
+ inline std::string FormatFunctionForError(absl::string_view name) {
610
+ return strings::StrCat("{{function_node ", name, "}}");
611
+ }
612
+
613
+ inline Status ReplaceErrorFromNonCommunicationOps(const Status s,
614
+ absl::string_view op_name) {
615
+ assert(::tsl::errors::IsUnavailable(s));
616
+ return Status(
617
+ absl::StatusCode::kInternal,
618
+ strings::StrCat(
619
+ s.message(), "\nExecuting non-communication op <", op_name,
620
+ "> originally returned UnavailableError, and was replaced by "
621
+ "InternalError to avoid invoking TF network error handling logic."));
622
+ }
623
+
624
+ template <typename T>
625
+ std::string FormatOriginalNodeLocationForError(const T& node_names,
626
+ const T& func_names) {
627
+ std::vector<std::string> error_message;
628
+ for (int i = 0; i != node_names.size(); ++i) {
629
+ if (i != 0) {
630
+ error_message.push_back(", ");
631
+ }
632
+ if (i < func_names.size()) {
633
+ error_message.push_back(FormatFunctionForError(func_names[i]));
634
+ }
635
+ error_message.push_back(FormatNodeNameForError(node_names[i]));
636
+ }
637
+ return absl::StrJoin(error_message, "");
638
+ }
639
+
640
+ // The CanonicalCode() for non-errors.
641
+ using ::tsl::error::OK; // NOLINT
642
+
643
+ } // namespace errors
644
+ } // namespace tsl
645
+
646
+ #endif // TENSORFLOW_TSL_PLATFORM_ERRORS_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/file_statistics.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_FILE_STATISTICS_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_FILE_STATISTICS_H_
18
+
19
+ #include "tsl/platform/types.h"
20
+
21
+ namespace tsl {
22
+
23
+ struct FileStatistics {
24
+ // The length of the file or -1 if finding file length is not supported.
25
+ int64_t length = -1;
26
+ // The last modified time in nanoseconds.
27
+ int64_t mtime_nsec = 0;
28
+ // True if the file is a directory, otherwise false.
29
+ bool is_directory = false;
30
+
31
+ FileStatistics() {}
32
+ FileStatistics(int64_t length, int64_t mtime_nsec, bool is_directory)
33
+ : length(length), mtime_nsec(mtime_nsec), is_directory(is_directory) {}
34
+ ~FileStatistics() {}
35
+ };
36
+
37
+ } // namespace tsl
38
+
39
+ #endif // TENSORFLOW_TSL_PLATFORM_FILE_STATISTICS_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/file_system.h ADDED
@@ -0,0 +1,923 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_FILE_SYSTEM_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_FILE_SYSTEM_H_
18
+
19
+ #include <stdint.h>
20
+
21
+ #include <functional>
22
+ #include <memory>
23
+ #include <string>
24
+ #include <unordered_map>
25
+ #include <utility>
26
+ #include <vector>
27
+
28
+ #include "tsl/platform/cord.h"
29
+ #include "tsl/platform/errors.h"
30
+ #include "tsl/platform/file_statistics.h"
31
+ #include "tsl/platform/macros.h"
32
+ #include "tsl/platform/platform.h"
33
+ #include "tsl/platform/stringpiece.h"
34
+ #include "tsl/platform/types.h"
35
+
36
+ #ifdef PLATFORM_WINDOWS
37
+ #undef DeleteFile
38
+ #undef CopyFile
39
+ #undef TranslateName
40
+ #endif
41
+
42
+ namespace tsl {
43
+
44
+ class FileAcl;
45
+ class RandomAccessFile;
46
+ class ReadOnlyMemoryRegion;
47
+ class WritableFile;
48
+
49
+ class FileSystem;
50
+ struct TransactionToken {
51
+ FileSystem* owner;
52
+ void* token;
53
+ };
54
+
55
+ /// A generic interface for accessing a file system. Implementations
56
+ /// of custom filesystem adapters must implement this interface,
57
+ /// RandomAccessFile, WritableFile, and ReadOnlyMemoryRegion classes.
58
+ class FileSystem {
59
+ public:
60
+ /// \brief Creates a brand new random access read-only file with the
61
+ /// specified name.
62
+ ///
63
+ /// On success, stores a pointer to the new file in
64
+ /// *result and returns OK. On failure stores NULL in *result and
65
+ /// returns non-OK. If the file does not exist, returns a non-OK
66
+ /// status.
67
+ ///
68
+ /// The returned file may be concurrently accessed by multiple threads.
69
+ ///
70
+ /// The ownership of the returned RandomAccessFile is passed to the caller
71
+ /// and the object should be deleted when is not used.
72
+ virtual tsl::Status NewRandomAccessFile(
73
+ const std::string& fname, std::unique_ptr<RandomAccessFile>* result) {
74
+ return NewRandomAccessFile(fname, nullptr, result);
75
+ }
76
+
77
+ virtual tsl::Status NewRandomAccessFile(
78
+ const std::string& fname, TransactionToken* token,
79
+ std::unique_ptr<RandomAccessFile>* result) {
80
+ // We duplicate these methods due to Google internal coding style prevents
81
+ // virtual functions with default arguments. See PR #41615.
82
+ return OkStatus();
83
+ }
84
+
85
+ /// \brief Creates an object that writes to a new file with the specified
86
+ /// name.
87
+ ///
88
+ /// Deletes any existing file with the same name and creates a
89
+ /// new file. On success, stores a pointer to the new file in
90
+ /// *result and returns OK. On failure stores NULL in *result and
91
+ /// returns non-OK.
92
+ ///
93
+ /// The returned file will only be accessed by one thread at a time.
94
+ ///
95
+ /// The ownership of the returned WritableFile is passed to the caller
96
+ /// and the object should be deleted when is not used.
97
+ virtual tsl::Status NewWritableFile(const std::string& fname,
98
+ std::unique_ptr<WritableFile>* result) {
99
+ return NewWritableFile(fname, nullptr, result);
100
+ }
101
+
102
+ virtual tsl::Status NewWritableFile(const std::string& fname,
103
+ TransactionToken* token,
104
+ std::unique_ptr<WritableFile>* result) {
105
+ return OkStatus();
106
+ }
107
+
108
+ /// \brief Creates an object that either appends to an existing file, or
109
+ /// writes to a new file (if the file does not exist to begin with).
110
+ ///
111
+ /// On success, stores a pointer to the new file in *result and
112
+ /// returns OK. On failure stores NULL in *result and returns
113
+ /// non-OK.
114
+ ///
115
+ /// The returned file will only be accessed by one thread at a time.
116
+ ///
117
+ /// The ownership of the returned WritableFile is passed to the caller
118
+ /// and the object should be deleted when is not used.
119
+ virtual tsl::Status NewAppendableFile(const std::string& fname,
120
+ std::unique_ptr<WritableFile>* result) {
121
+ return NewAppendableFile(fname, nullptr, result);
122
+ }
123
+
124
+ virtual tsl::Status NewAppendableFile(const std::string& fname,
125
+ TransactionToken* token,
126
+ std::unique_ptr<WritableFile>* result) {
127
+ return OkStatus();
128
+ }
129
+
130
+ /// \brief Creates a readonly region of memory with the file context.
131
+ ///
132
+ /// On success, it returns a pointer to read-only memory region
133
+ /// from the content of file fname. The ownership of the region is passed to
134
+ /// the caller. On failure stores nullptr in *result and returns non-OK.
135
+ ///
136
+ /// The returned memory region can be accessed from many threads in parallel.
137
+ ///
138
+ /// The ownership of the returned ReadOnlyMemoryRegion is passed to the caller
139
+ /// and the object should be deleted when is not used.
140
+ virtual tsl::Status NewReadOnlyMemoryRegionFromFile(
141
+ const std::string& fname, std::unique_ptr<ReadOnlyMemoryRegion>* result) {
142
+ return NewReadOnlyMemoryRegionFromFile(fname, nullptr, result);
143
+ }
144
+
145
+ virtual tsl::Status NewReadOnlyMemoryRegionFromFile(
146
+ const std::string& fname, TransactionToken* token,
147
+ std::unique_ptr<ReadOnlyMemoryRegion>* result) {
148
+ return OkStatus();
149
+ }
150
+
151
+ /// Returns OK if the named path exists and NOT_FOUND otherwise.
152
+ virtual tsl::Status FileExists(const std::string& fname) {
153
+ return FileExists(fname, nullptr);
154
+ }
155
+
156
+ virtual tsl::Status FileExists(const std::string& fname,
157
+ TransactionToken* token) {
158
+ return OkStatus();
159
+ }
160
+
161
+ /// Returns true if all the listed files exist, false otherwise.
162
+ /// if status is not null, populate the vector with a detailed status
163
+ /// for each file.
164
+ virtual bool FilesExist(const std::vector<string>& files,
165
+ std::vector<Status>* status) {
166
+ return FilesExist(files, nullptr, status);
167
+ }
168
+
169
+ virtual bool FilesExist(const std::vector<string>& files,
170
+ TransactionToken* token, std::vector<Status>* status);
171
+
172
+ /// \brief Returns the immediate children in the given directory.
173
+ ///
174
+ /// The returned paths are relative to 'dir'.
175
+ virtual tsl::Status GetChildren(const std::string& dir,
176
+ std::vector<string>* result) {
177
+ return GetChildren(dir, nullptr, result);
178
+ }
179
+
180
+ virtual tsl::Status GetChildren(const std::string& dir,
181
+ TransactionToken* token,
182
+ std::vector<string>* result) {
183
+ return OkStatus();
184
+ }
185
+
186
+ /// \brief Given a pattern, stores in *results the set of paths that matches
187
+ /// that pattern. *results is cleared.
188
+ ///
189
+ /// pattern must match all of a name, not just a substring.
190
+ ///
191
+ /// pattern: { term }
192
+ /// term:
193
+ /// '*': matches any sequence of non-'/' characters
194
+ /// '?': matches a single non-'/' character
195
+ /// '[' [ '^' ] { match-list } ']':
196
+ /// matches any single character (not) on the list
197
+ /// c: matches character c (c != '*', '?', '\\', '[')
198
+ /// '\\' c: matches character c
199
+ /// character-range:
200
+ /// c: matches character c (c != '\\', '-', ']')
201
+ /// '\\' c: matches character c
202
+ /// lo '-' hi: matches character c for lo <= c <= hi
203
+ ///
204
+ /// Typical return codes:
205
+ /// * OK - no errors
206
+ /// * UNIMPLEMENTED - Some underlying functions (like GetChildren) are not
207
+ /// implemented
208
+ virtual tsl::Status GetMatchingPaths(const std::string& pattern,
209
+ std::vector<string>* results) {
210
+ return GetMatchingPaths(pattern, nullptr, results);
211
+ }
212
+
213
+ virtual tsl::Status GetMatchingPaths(const std::string& pattern,
214
+ TransactionToken* token,
215
+ std::vector<string>* results) {
216
+ return OkStatus();
217
+ }
218
+
219
+ /// \brief Checks if the given filename matches the pattern.
220
+ ///
221
+ /// This function provides the equivalent of posix fnmatch, however it is
222
+ /// implemented without fnmatch to ensure that this can be used for cloud
223
+ /// filesystems on windows. For windows filesystems, it uses PathMatchSpec.
224
+ virtual bool Match(const std::string& filename, const std::string& pattern);
225
+
226
+ /// \brief Obtains statistics for the given path.
227
+ virtual tsl::Status Stat(const std::string& fname, FileStatistics* stat) {
228
+ return Stat(fname, nullptr, stat);
229
+ }
230
+
231
+ virtual tsl::Status Stat(const std::string& fname, TransactionToken* token,
232
+ FileStatistics* stat) {
233
+ return OkStatus();
234
+ }
235
+
236
+ /// \brief Deletes the named file.
237
+ virtual tsl::Status DeleteFile(const std::string& fname) {
238
+ return DeleteFile(fname, nullptr);
239
+ }
240
+
241
+ virtual tsl::Status DeleteFile(const std::string& fname,
242
+ TransactionToken* token) {
243
+ return OkStatus();
244
+ }
245
+
246
+ /// \brief Creates the specified directory.
247
+ /// Typical return codes:
248
+ /// * OK - successfully created the directory.
249
+ /// * ALREADY_EXISTS - directory with name dirname already exists.
250
+ /// * PERMISSION_DENIED - dirname is not writable.
251
+ virtual tsl::Status CreateDir(const std::string& dirname) {
252
+ return CreateDir(dirname, nullptr);
253
+ }
254
+
255
+ virtual tsl::Status CreateDir(const std::string& dirname,
256
+ TransactionToken* token) {
257
+ return OkStatus();
258
+ }
259
+
260
+ /// \brief Creates the specified directory and all the necessary
261
+ /// subdirectories.
262
+ /// Typical return codes:
263
+ /// * OK - successfully created the directory and sub directories, even if
264
+ /// they were already created.
265
+ /// * PERMISSION_DENIED - dirname or some subdirectory is not writable.
266
+ virtual tsl::Status RecursivelyCreateDir(const std::string& dirname) {
267
+ return RecursivelyCreateDir(dirname, nullptr);
268
+ }
269
+
270
+ virtual tsl::Status RecursivelyCreateDir(const std::string& dirname,
271
+ TransactionToken* token);
272
+
273
+ /// \brief Deletes the specified directory.
274
+ virtual tsl::Status DeleteDir(const std::string& dirname) {
275
+ return DeleteDir(dirname, nullptr);
276
+ }
277
+
278
+ virtual tsl::Status DeleteDir(const std::string& dirname,
279
+ TransactionToken* token) {
280
+ return OkStatus();
281
+ }
282
+
283
+ /// \brief Deletes the specified directory and all subdirectories and files
284
+ /// underneath it. This is accomplished by traversing the directory tree
285
+ /// rooted at dirname and deleting entries as they are encountered.
286
+ ///
287
+ /// If dirname itself is not readable or does not exist, *undeleted_dir_count
288
+ /// is set to 1, *undeleted_file_count is set to 0 and an appropriate status
289
+ /// (e.g. NOT_FOUND) is returned.
290
+ ///
291
+ /// If dirname and all its descendants were successfully deleted, TF_OK is
292
+ /// returned and both error counters are set to zero.
293
+ ///
294
+ /// Otherwise, while traversing the tree, undeleted_file_count and
295
+ /// undeleted_dir_count are updated if an entry of the corresponding type
296
+ /// could not be deleted. The returned error status represents the reason that
297
+ /// any one of these entries could not be deleted.
298
+ ///
299
+ /// REQUIRES: undeleted_files, undeleted_dirs to be not null.
300
+ ///
301
+ /// Typical return codes:
302
+ /// * OK - dirname exists and we were able to delete everything underneath.
303
+ /// * NOT_FOUND - dirname doesn't exist
304
+ /// * PERMISSION_DENIED - dirname or some descendant is not writable
305
+ /// * UNIMPLEMENTED - Some underlying functions (like Delete) are not
306
+ /// implemented
307
+ virtual tsl::Status DeleteRecursively(const std::string& dirname,
308
+ int64_t* undeleted_files,
309
+ int64_t* undeleted_dirs) {
310
+ return DeleteRecursively(dirname, nullptr, undeleted_files, undeleted_dirs);
311
+ }
312
+
313
+ virtual tsl::Status DeleteRecursively(const std::string& dirname,
314
+ TransactionToken* token,
315
+ int64_t* undeleted_files,
316
+ int64_t* undeleted_dirs);
317
+
318
+ /// \brief Stores the size of `fname` in `*file_size`.
319
+ virtual tsl::Status GetFileSize(const std::string& fname, uint64* file_size) {
320
+ return GetFileSize(fname, nullptr, file_size);
321
+ }
322
+
323
+ virtual tsl::Status GetFileSize(const std::string& fname,
324
+ TransactionToken* token, uint64* file_size) {
325
+ return OkStatus();
326
+ }
327
+
328
+ /// \brief Overwrites the target if it exists.
329
+ virtual tsl::Status RenameFile(const std::string& src,
330
+ const std::string& target) {
331
+ return RenameFile(src, target, nullptr);
332
+ }
333
+
334
+ virtual tsl::Status RenameFile(const std::string& src,
335
+ const std::string& target,
336
+ TransactionToken* token) {
337
+ return OkStatus();
338
+ }
339
+
340
+ /// \brief Copy the src to target.
341
+ virtual tsl::Status CopyFile(const std::string& src,
342
+ const std::string& target) {
343
+ return CopyFile(src, target, nullptr);
344
+ }
345
+
346
+ virtual tsl::Status CopyFile(const std::string& src,
347
+ const std::string& target,
348
+ TransactionToken* token);
349
+
350
+ /// \brief Translate an URI to a filename for the FileSystem implementation.
351
+ ///
352
+ /// The implementation in this class cleans up the path, removing
353
+ /// duplicate /'s, resolving .. and removing trailing '/'.
354
+ /// This respects relative vs. absolute paths, but does not
355
+ /// invoke any system calls (getcwd(2)) in order to resolve relative
356
+ /// paths with respect to the actual working directory. That is, this is
357
+ /// purely string manipulation, completely independent of process state.
358
+ virtual std::string TranslateName(const std::string& name) const;
359
+
360
+ /// \brief Returns whether the given path is a directory or not.
361
+ ///
362
+ /// Typical return codes (not guaranteed exhaustive):
363
+ /// * OK - The path exists and is a directory.
364
+ /// * FAILED_PRECONDITION - The path exists and is not a directory.
365
+ /// * NOT_FOUND - The path entry does not exist.
366
+ /// * PERMISSION_DENIED - Insufficient permissions.
367
+ /// * UNIMPLEMENTED - The file factory doesn't support directories.
368
+ virtual tsl::Status IsDirectory(const std::string& fname) {
369
+ return IsDirectory(fname, nullptr);
370
+ }
371
+
372
+ virtual tsl::Status IsDirectory(const std::string& fname,
373
+ TransactionToken* token);
374
+
375
+ /// \brief Returns whether the given path is on a file system
376
+ /// that has atomic move capabilities. This can be used
377
+ /// to determine if there needs to be a temp location to safely write objects.
378
+ /// The second boolean argument has_atomic_move contains this information.
379
+ ///
380
+ /// Returns one of the following status codes (not guaranteed exhaustive):
381
+ /// * OK - The path is on a recognized file system,
382
+ /// so has_atomic_move holds the above information.
383
+ /// * UNIMPLEMENTED - The file system of the path hasn't been implemented in
384
+ /// TF
385
+ virtual Status HasAtomicMove(const std::string& path, bool* has_atomic_move);
386
+
387
+ /// \brief Flushes any cached filesystem objects from memory.
388
+ virtual void FlushCaches() { FlushCaches(nullptr); }
389
+
390
+ virtual void FlushCaches(TransactionToken* token);
391
+
392
+ /// \brief The separator this filesystem uses.
393
+ ///
394
+ /// This is implemented as a part of the filesystem, because even on windows,
395
+ /// a user may need access to filesystems with '/' separators, such as cloud
396
+ /// filesystems.
397
+ virtual char Separator() const;
398
+
399
+ /// \brief Split a path to its basename and dirname.
400
+ ///
401
+ /// Helper function for Basename and Dirname.
402
+ std::pair<StringPiece, StringPiece> SplitPath(StringPiece uri) const;
403
+
404
+ /// \brief returns the final file name in the given path.
405
+ ///
406
+ /// Returns the part of the path after the final "/". If there is no
407
+ /// "/" in the path, the result is the same as the input.
408
+ virtual StringPiece Basename(StringPiece path) const;
409
+
410
+ /// \brief Returns the part of the path before the final "/".
411
+ ///
412
+ /// If there is a single leading "/" in the path, the result will be the
413
+ /// leading "/". If there is no "/" in the path, the result is the empty
414
+ /// prefix of the input.
415
+ StringPiece Dirname(StringPiece path) const;
416
+
417
+ /// \brief Returns the part of the basename of path after the final ".".
418
+ ///
419
+ /// If there is no "." in the basename, the result is empty.
420
+ StringPiece Extension(StringPiece path) const;
421
+
422
+ /// \brief Clean duplicate and trailing, "/"s, and resolve ".." and ".".
423
+ ///
424
+ /// NOTE: This respects relative vs. absolute paths, but does not
425
+ /// invoke any system calls (getcwd(2)) in order to resolve relative
426
+ /// paths with respect to the actual working directory. That is, this is
427
+ /// purely string manipulation, completely independent of process state.
428
+ std::string CleanPath(StringPiece path) const;
429
+
430
+ /// \brief Creates a URI from a scheme, host, and path.
431
+ ///
432
+ /// If the scheme is empty, we just return the path.
433
+ std::string CreateURI(StringPiece scheme, StringPiece host,
434
+ StringPiece path) const;
435
+
436
+ /// \brief Return true if path is absolute.
437
+ bool IsAbsolutePath(tsl::StringPiece path) const;
438
+
439
+ #ifndef SWIG // variadic templates
440
+ /// \brief Join multiple paths together.
441
+ ///
442
+ /// This function also removes the unnecessary path separators.
443
+ /// For example:
444
+ ///
445
+ /// Arguments | JoinPath
446
+ /// ---------------------------+----------
447
+ /// '/foo', 'bar' | /foo/bar
448
+ /// '/foo/', 'bar' | /foo/bar
449
+ /// '/foo', '/bar' | /foo/bar
450
+ ///
451
+ /// Usage:
452
+ /// string path = io::JoinPath("/mydir", filename);
453
+ /// string path = io::JoinPath(FLAGS_test_srcdir, filename);
454
+ /// string path = io::JoinPath("/full", "path", "to", "filename");
455
+ template <typename... T>
456
+ std::string JoinPath(const T&... args) {
457
+ return JoinPathImpl({args...});
458
+ }
459
+ #endif /* SWIG */
460
+
461
+ std::string JoinPathImpl(std::initializer_list<tsl::StringPiece> paths);
462
+
463
+ /// \brief Populates the scheme, host, and path from a URI.
464
+ ///
465
+ /// scheme, host, and path are guaranteed by this function to point into the
466
+ /// contents of uri, even if empty.
467
+ ///
468
+ /// Corner cases:
469
+ /// - If the URI is invalid, scheme and host are set to empty strings and the
470
+ /// passed string is assumed to be a path
471
+ /// - If the URI omits the path (e.g. file://host), then the path is left
472
+ /// empty.
473
+ void ParseURI(StringPiece remaining, StringPiece* scheme, StringPiece* host,
474
+ StringPiece* path) const;
475
+
476
+ // Transaction related API
477
+
478
+ /// \brief Starts a new transaction
479
+ virtual tsl::Status StartTransaction(TransactionToken** token) {
480
+ *token = nullptr;
481
+ return OkStatus();
482
+ }
483
+
484
+ /// \brief Adds `path` to transaction in `token`
485
+ virtual tsl::Status AddToTransaction(const std::string& path,
486
+ TransactionToken* token) {
487
+ return OkStatus();
488
+ }
489
+
490
+ /// \brief Ends transaction
491
+ virtual tsl::Status EndTransaction(TransactionToken* token) {
492
+ return OkStatus();
493
+ }
494
+
495
+ /// \brief Get token for `path` or start a new transaction and add `path` to
496
+ /// it.
497
+ virtual tsl::Status GetTokenOrStartTransaction(const std::string& path,
498
+ TransactionToken** token) {
499
+ *token = nullptr;
500
+ return OkStatus();
501
+ }
502
+
503
+ /// \brief Return transaction for `path` or nullptr in `token`
504
+ virtual tsl::Status GetTransactionForPath(const std::string& path,
505
+ TransactionToken** token) {
506
+ *token = nullptr;
507
+ return OkStatus();
508
+ }
509
+
510
+ /// \brief Decode transaction to human readable string.
511
+ virtual std::string DecodeTransaction(const TransactionToken* token);
512
+
513
+ /// \brief Set File System Configuration Options
514
+ virtual Status SetOption(const string& key, const string& value) {
515
+ return errors::Unimplemented("SetOption");
516
+ }
517
+
518
+ /// \brief Set File System Configuration Option
519
+ virtual tsl::Status SetOption(const std::string& name,
520
+ const std::vector<string>& values) {
521
+ return errors::Unimplemented("SetOption");
522
+ }
523
+
524
+ /// \brief Set File System Configuration Option
525
+ virtual tsl::Status SetOption(const std::string& name,
526
+ const std::vector<int64_t>& values) {
527
+ return errors::Unimplemented("SetOption");
528
+ }
529
+
530
+ /// \brief Set File System Configuration Option
531
+ virtual tsl::Status SetOption(const std::string& name,
532
+ const std::vector<double>& values) {
533
+ return errors::Unimplemented("SetOption");
534
+ }
535
+
536
+ /// \brief Set File System ACL checker.
537
+ ///
538
+ /// No checks are enforced if a FileAcl is never set.
539
+ virtual tsl::Status SetFileAcl(std::shared_ptr<FileAcl> file_acl) {
540
+ return errors::Unimplemented("SetFileAcl");
541
+ }
542
+
543
+ FileSystem() {}
544
+
545
+ virtual ~FileSystem() = default;
546
+ };
547
+ /// This macro adds forwarding methods from FileSystem class to
548
+ /// used class since name hiding will prevent these to be accessed from
549
+ /// derived classes and would require all use locations to migrate to
550
+ /// Transactional API. This is an interim solution until ModularFileSystem class
551
+ /// becomes a singleton.
552
+ // TODO(sami): Remove this macro when filesystem plugins migration is complete.
553
+ #define TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT \
554
+ using FileSystem::NewRandomAccessFile; \
555
+ using FileSystem::NewWritableFile; \
556
+ using FileSystem::NewAppendableFile; \
557
+ using FileSystem::NewReadOnlyMemoryRegionFromFile; \
558
+ using FileSystem::FileExists; \
559
+ using FileSystem::GetChildren; \
560
+ using FileSystem::GetMatchingPaths; \
561
+ using FileSystem::Stat; \
562
+ using FileSystem::DeleteFile; \
563
+ using FileSystem::RecursivelyCreateDir; \
564
+ using FileSystem::DeleteDir; \
565
+ using FileSystem::DeleteRecursively; \
566
+ using FileSystem::GetFileSize; \
567
+ using FileSystem::RenameFile; \
568
+ using FileSystem::CopyFile; \
569
+ using FileSystem::IsDirectory; \
570
+ using FileSystem::FlushCaches
571
+
572
+ /// A Wrapper class for Transactional FileSystem support.
573
+ /// This provides means to make use of the transactions with minimal code change
574
+ /// Any operations that are done through this interface will be through the
575
+ /// transaction created at the time of construction of this instance.
576
+ /// See FileSystem documentation for method descriptions.
577
+ /// This class simply forwards all calls to wrapped filesystem either with given
578
+ /// transaction token or with token used in its construction. This allows doing
579
+ /// transactional filesystem access with minimal code change.
580
+ class WrappedFileSystem : public FileSystem {
581
+ public:
582
+ TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT;
583
+
584
+ tsl::Status NewRandomAccessFile(
585
+ const std::string& fname, TransactionToken* token,
586
+ std::unique_ptr<RandomAccessFile>* result) override {
587
+ return fs_->NewRandomAccessFile(fname, (token ? token : token_), result);
588
+ }
589
+
590
+ tsl::Status NewWritableFile(const std::string& fname, TransactionToken* token,
591
+ std::unique_ptr<WritableFile>* result) override {
592
+ return fs_->NewWritableFile(fname, (token ? token : token_), result);
593
+ }
594
+
595
+ tsl::Status NewAppendableFile(
596
+ const std::string& fname, TransactionToken* token,
597
+ std::unique_ptr<WritableFile>* result) override {
598
+ return fs_->NewAppendableFile(fname, (token ? token : token_), result);
599
+ }
600
+
601
+ tsl::Status NewReadOnlyMemoryRegionFromFile(
602
+ const std::string& fname, TransactionToken* token,
603
+ std::unique_ptr<ReadOnlyMemoryRegion>* result) override {
604
+ return fs_->NewReadOnlyMemoryRegionFromFile(fname, (token ? token : token_),
605
+ result);
606
+ }
607
+
608
+ tsl::Status FileExists(const std::string& fname,
609
+ TransactionToken* token) override {
610
+ return fs_->FileExists(fname, (token ? token : token_));
611
+ }
612
+
613
+ bool FilesExist(const std::vector<string>& files, TransactionToken* token,
614
+ std::vector<Status>* status) override {
615
+ return fs_->FilesExist(files, (token ? token : token_), status);
616
+ }
617
+
618
+ tsl::Status GetChildren(const std::string& dir, TransactionToken* token,
619
+ std::vector<string>* result) override {
620
+ return fs_->GetChildren(dir, (token ? token : token_), result);
621
+ }
622
+
623
+ tsl::Status GetMatchingPaths(const std::string& pattern,
624
+ TransactionToken* token,
625
+ std::vector<string>* results) override {
626
+ return fs_->GetMatchingPaths(pattern, (token ? token : token_), results);
627
+ }
628
+
629
+ bool Match(const std::string& filename, const std::string& pattern) override {
630
+ return fs_->Match(filename, pattern);
631
+ }
632
+
633
+ tsl::Status Stat(const std::string& fname, TransactionToken* token,
634
+ FileStatistics* stat) override {
635
+ return fs_->Stat(fname, (token ? token : token_), stat);
636
+ }
637
+
638
+ tsl::Status DeleteFile(const std::string& fname,
639
+ TransactionToken* token) override {
640
+ return fs_->DeleteFile(fname, (token ? token : token_));
641
+ }
642
+
643
+ tsl::Status CreateDir(const std::string& dirname,
644
+ TransactionToken* token) override {
645
+ return fs_->CreateDir(dirname, (token ? token : token_));
646
+ }
647
+
648
+ tsl::Status RecursivelyCreateDir(const std::string& dirname,
649
+ TransactionToken* token) override {
650
+ return fs_->RecursivelyCreateDir(dirname, (token ? token : token_));
651
+ }
652
+
653
+ tsl::Status DeleteDir(const std::string& dirname,
654
+ TransactionToken* token) override {
655
+ return fs_->DeleteDir(dirname, (token ? token : token_));
656
+ }
657
+
658
+ tsl::Status DeleteRecursively(const std::string& dirname,
659
+ TransactionToken* token,
660
+ int64_t* undeleted_files,
661
+ int64_t* undeleted_dirs) override {
662
+ return fs_->DeleteRecursively(dirname, (token ? token : token_),
663
+ undeleted_files, undeleted_dirs);
664
+ }
665
+
666
+ tsl::Status GetFileSize(const std::string& fname, TransactionToken* token,
667
+ uint64* file_size) override {
668
+ return fs_->GetFileSize(fname, (token ? token : token_), file_size);
669
+ }
670
+
671
+ tsl::Status RenameFile(const std::string& src, const std::string& target,
672
+ TransactionToken* token) override {
673
+ return fs_->RenameFile(src, target, (token ? token : token_));
674
+ }
675
+
676
+ tsl::Status CopyFile(const std::string& src, const std::string& target,
677
+ TransactionToken* token) override {
678
+ return fs_->CopyFile(src, target, (token ? token : token_));
679
+ }
680
+
681
+ std::string TranslateName(const std::string& name) const override {
682
+ return fs_->TranslateName(name);
683
+ }
684
+
685
+ tsl::Status IsDirectory(const std::string& fname,
686
+ TransactionToken* token) override {
687
+ return fs_->IsDirectory(fname, (token ? token : token_));
688
+ }
689
+
690
+ Status HasAtomicMove(const std::string& path,
691
+ bool* has_atomic_move) override {
692
+ return fs_->HasAtomicMove(path, has_atomic_move);
693
+ }
694
+
695
+ void FlushCaches(TransactionToken* token) override {
696
+ return fs_->FlushCaches((token ? token : token_));
697
+ }
698
+
699
+ char Separator() const override { return fs_->Separator(); }
700
+
701
+ StringPiece Basename(StringPiece path) const override {
702
+ return fs_->Basename(path);
703
+ }
704
+
705
+ tsl::Status StartTransaction(TransactionToken** token) override {
706
+ return fs_->StartTransaction(token);
707
+ }
708
+
709
+ tsl::Status AddToTransaction(const std::string& path,
710
+ TransactionToken* token) override {
711
+ return fs_->AddToTransaction(path, (token ? token : token_));
712
+ }
713
+
714
+ tsl::Status EndTransaction(TransactionToken* token) override {
715
+ return fs_->EndTransaction(token);
716
+ }
717
+
718
+ tsl::Status GetTransactionForPath(const std::string& path,
719
+ TransactionToken** token) override {
720
+ return fs_->GetTransactionForPath(path, token);
721
+ }
722
+
723
+ tsl::Status GetTokenOrStartTransaction(const std::string& path,
724
+ TransactionToken** token) override {
725
+ return fs_->GetTokenOrStartTransaction(path, token);
726
+ }
727
+
728
+ std::string DecodeTransaction(const TransactionToken* token) override {
729
+ return fs_->DecodeTransaction((token ? token : token_));
730
+ }
731
+
732
+ WrappedFileSystem(FileSystem* file_system, TransactionToken* token)
733
+ : fs_(file_system), token_(token) {}
734
+
735
+ ~WrappedFileSystem() override = default;
736
+
737
+ private:
738
+ FileSystem* fs_;
739
+ TransactionToken* token_;
740
+ };
741
+
742
+ /// A file abstraction for randomly reading the contents of a file.
743
+ class RandomAccessFile {
744
+ public:
745
+ RandomAccessFile() {}
746
+ virtual ~RandomAccessFile() = default;
747
+
748
+ /// \brief Returns the name of the file.
749
+ ///
750
+ /// This is an optional operation that may not be implemented by every
751
+ /// filesystem.
752
+ virtual tsl::Status Name(StringPiece* result) const {
753
+ return errors::Unimplemented("This filesystem does not support Name()");
754
+ }
755
+
756
+ /// \brief Reads up to `n` bytes from the file starting at `offset`.
757
+ ///
758
+ /// `scratch[0..n-1]` may be written by this routine. Sets `*result`
759
+ /// to the data that was read (including if fewer than `n` bytes were
760
+ /// successfully read). May set `*result` to point at data in
761
+ /// `scratch[0..n-1]`, so `scratch[0..n-1]` must be live when
762
+ /// `*result` is used.
763
+ ///
764
+ /// On OK returned status: `n` bytes have been stored in `*result`.
765
+ /// On non-OK returned status: `[0..n]` bytes have been stored in `*result`.
766
+ ///
767
+ /// Returns `OUT_OF_RANGE` if fewer than n bytes were stored in `*result`
768
+ /// because of EOF.
769
+ ///
770
+ /// Safe for concurrent use by multiple threads.
771
+ virtual tsl::Status Read(uint64 offset, size_t n, StringPiece* result,
772
+ char* scratch) const = 0;
773
+
774
+ #if defined(TF_CORD_SUPPORT)
775
+ /// \brief Read up to `n` bytes from the file starting at `offset`.
776
+ virtual tsl::Status Read(uint64 offset, size_t n, absl::Cord* cord) const {
777
+ return errors::Unimplemented(
778
+ "Read(uint64, size_t, absl::Cord*) is not "
779
+ "implemented");
780
+ }
781
+ #endif
782
+
783
+ private:
784
+ RandomAccessFile(const RandomAccessFile&) = delete;
785
+ void operator=(const RandomAccessFile&) = delete;
786
+ };
787
+
788
+ /// \brief A file abstraction for sequential writing.
789
+ ///
790
+ /// The implementation must provide buffering since callers may append
791
+ /// small fragments at a time to the file.
792
+ class WritableFile {
793
+ public:
794
+ WritableFile() {}
795
+ virtual ~WritableFile() = default;
796
+
797
+ /// \brief Append 'data' to the file.
798
+ virtual tsl::Status Append(StringPiece data) = 0;
799
+
800
+ #if defined(TF_CORD_SUPPORT)
801
+ // \brief Append 'data' to the file.
802
+ virtual tsl::Status Append(const absl::Cord& cord) {
803
+ for (StringPiece chunk : cord.Chunks()) {
804
+ TF_RETURN_IF_ERROR(Append(chunk));
805
+ }
806
+ return OkStatus();
807
+ }
808
+ #endif
809
+
810
+ /// \brief Close the file.
811
+ ///
812
+ /// Flush() and de-allocate resources associated with this file
813
+ ///
814
+ /// Typical return codes (not guaranteed to be exhaustive):
815
+ /// * OK
816
+ /// * Other codes, as returned from Flush()
817
+ virtual tsl::Status Close() = 0;
818
+
819
+ /// \brief Flushes the file and optionally syncs contents to filesystem.
820
+ ///
821
+ /// This should flush any local buffers whose contents have not been
822
+ /// delivered to the filesystem.
823
+ ///
824
+ /// If the process terminates after a successful flush, the contents
825
+ /// may still be persisted, since the underlying filesystem may
826
+ /// eventually flush the contents. If the OS or machine crashes
827
+ /// after a successful flush, the contents may or may not be
828
+ /// persisted, depending on the implementation.
829
+ virtual tsl::Status Flush() = 0;
830
+
831
+ // \brief Returns the name of the file.
832
+ ///
833
+ /// This is an optional operation that may not be implemented by every
834
+ /// filesystem.
835
+ virtual tsl::Status Name(StringPiece* result) const {
836
+ return errors::Unimplemented("This filesystem does not support Name()");
837
+ }
838
+
839
+ /// \brief Syncs contents of file to filesystem.
840
+ ///
841
+ /// This waits for confirmation from the filesystem that the contents
842
+ /// of the file have been persisted to the filesystem; if the OS
843
+ /// or machine crashes after a successful Sync, the contents should
844
+ /// be properly saved.
845
+ virtual tsl::Status Sync() = 0;
846
+
847
+ /// \brief Retrieves the current write position in the file, or -1 on
848
+ /// error.
849
+ ///
850
+ /// This is an optional operation, subclasses may choose to return
851
+ /// errors::Unimplemented.
852
+ virtual tsl::Status Tell(int64_t* position) {
853
+ *position = -1;
854
+ return errors::Unimplemented("This filesystem does not support Tell()");
855
+ }
856
+
857
+ private:
858
+ WritableFile(const WritableFile&) = delete;
859
+ void operator=(const WritableFile&) = delete;
860
+ };
861
+
862
+ /// \brief A readonly memmapped file abstraction.
863
+ ///
864
+ /// The implementation must guarantee that all memory is accessible when the
865
+ /// object exists, independently from the Env that created it.
866
+ class ReadOnlyMemoryRegion {
867
+ public:
868
+ ReadOnlyMemoryRegion() {}
869
+ virtual ~ReadOnlyMemoryRegion() = default;
870
+
871
+ /// \brief Returns a pointer to the memory region.
872
+ virtual const void* data() = 0;
873
+
874
+ /// \brief Returns the length of the memory region in bytes.
875
+ virtual uint64 length() = 0;
876
+ };
877
+
878
+ /// \brief A registry for file system implementations.
879
+ ///
880
+ /// Filenames are specified as an URI, which is of the form
881
+ /// [scheme://]<filename>.
882
+ /// File system implementations are registered using the REGISTER_FILE_SYSTEM
883
+ /// macro, providing the 'scheme' as the key.
884
+ ///
885
+ /// There are two `Register` methods: one using `Factory` for legacy filesystems
886
+ /// (deprecated mechanism of subclassing `FileSystem` and using
887
+ /// `REGISTER_FILE_SYSTEM` macro), and one using `std::unique_ptr<FileSystem>`
888
+ /// for the new modular approach.
889
+ ///
890
+ /// Note that the new API expects a pointer to `ModularFileSystem` but this is
891
+ /// not checked as there should be exactly one caller to the API and doing the
892
+ /// check results in a circular dependency between `BUILD` targets.
893
+ ///
894
+ /// Plan is to completely remove the filesystem registration from `Env` and
895
+ /// incorporate it into `ModularFileSystem` class (which will be renamed to be
896
+ /// the only `FileSystem` class and marked as `final`). But this will happen at
897
+ /// a later time, after we convert all filesystems to the new API.
898
+ ///
899
+ /// TODO(b/139060984): After all filesystems are converted, remove old
900
+ /// registration and update comment.
901
+ class FileSystemRegistry {
902
+ public:
903
+ typedef std::function<FileSystem*()> Factory;
904
+
905
+ virtual ~FileSystemRegistry() = default;
906
+ virtual tsl::Status Register(const std::string& scheme, Factory factory) = 0;
907
+ virtual tsl::Status Register(const std::string& scheme,
908
+ std::unique_ptr<FileSystem> filesystem) = 0;
909
+ virtual FileSystem* Lookup(const std::string& scheme) = 0;
910
+ virtual tsl::Status GetRegisteredFileSystemSchemes(
911
+ std::vector<std::string>* schemes) = 0;
912
+ };
913
+
914
+ /// \brief An abstraction for enforcing ACL checks in FileSystem.
915
+ class FileAcl {
916
+ public:
917
+ virtual absl::Status CheckAccess(std::string_view path) = 0;
918
+ virtual ~FileAcl() = default;
919
+ };
920
+
921
+ } // namespace tsl
922
+
923
+ #endif // TENSORFLOW_TSL_PLATFORM_FILE_SYSTEM_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/file_system_helper.h ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2018 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_TSL_PLATFORM_FILE_SYSTEM_HELPER_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_FILE_SYSTEM_HELPER_H_
18
+
19
+ #include <string>
20
+ #include <vector>
21
+
22
+ #include "tsl/platform/env.h"
23
+ #include "tsl/platform/status.h"
24
+ #include "tsl/platform/statusor.h"
25
+
26
+ namespace tsl {
27
+
28
+ class FileSystem;
29
+ class Env;
30
+
31
+ namespace internal {
32
+
33
+ // Given a pattern, stores in 'results' the set of paths (in the given file
34
+ // system) that match that pattern.
35
+ //
36
+ // This helper may be used by implementations of FileSystem::GetMatchingPaths()
37
+ // in order to provide parallel scanning of subdirectories (except on iOS).
38
+ //
39
+ // Arguments:
40
+ // fs: may not be null and will be used to identify directories and list
41
+ // their contents.
42
+ // env: may not be null and will be used to check if a match has been found.
43
+ // pattern: see FileSystem::GetMatchingPaths() for details.
44
+ // results: will be cleared and may not be null.
45
+ //
46
+ // Returns an error status if any call to 'fs' failed.
47
+ Status GetMatchingPaths(FileSystem* fs, Env* env, const string& pattern,
48
+ std::vector<string>* results);
49
+
50
+ // Given a file path, determines whether the file exists. This helper simplifies
51
+ // the use of Env::FileExists.
52
+ //
53
+ // Arguments:
54
+ // env: may not be null.
55
+ // fname: the file path to look up
56
+ //
57
+ // Returns true if the file exists, false if it does not exist, or an error
58
+ // Status.
59
+ StatusOr<bool> FileExists(Env* env, const string& fname);
60
+
61
+ } // namespace internal
62
+ } // namespace tsl
63
+
64
+ #endif // TENSORFLOW_TSL_PLATFORM_FILE_SYSTEM_HELPER_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/fingerprint.h ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_FINGERPRINT_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_FINGERPRINT_H_
18
+
19
+ #include "tsl/platform/platform.h"
20
+ #include "tsl/platform/stringpiece.h"
21
+ #include "tsl/platform/types.h"
22
+
23
+ #if TSL_IS_IN_OSS
24
+ #define USE_OSS_FARMHASH
25
+ #endif // TSL_IS_IN_OSS
26
+
27
+ #ifdef USE_OSS_FARMHASH
28
+ #include <farmhash.h>
29
+ #else
30
+ #include "util/hash/farmhash_fingerprint.h"
31
+ #endif
32
+
33
+ namespace tsl {
34
+
35
+ struct Fprint128 {
36
+ uint64_t low64;
37
+ uint64_t high64;
38
+ };
39
+
40
+ inline bool operator==(const Fprint128& lhs, const Fprint128& rhs) {
41
+ return lhs.low64 == rhs.low64 && lhs.high64 == rhs.high64;
42
+ }
43
+
44
+ struct Fprint128Hasher {
45
+ size_t operator()(const Fprint128& v) const {
46
+ // Low64 should be sufficiently mixed to allow use of it as a Hash.
47
+ return static_cast<size_t>(v.low64);
48
+ }
49
+ };
50
+
51
+ namespace internal {
52
+ // Mixes some of the bits that got propagated to the high bits back into the
53
+ // low bits.
54
+ inline uint64_t ShiftMix(const uint64_t val) { return val ^ (val >> 47); }
55
+ } // namespace internal
56
+
57
+ // This concatenates two 64-bit fingerprints. It is a convenience function to
58
+ // get a fingerprint for a combination of already fingerprinted components. For
59
+ // example this code is used to concatenate the hashes from each of the features
60
+ // on sparse crosses.
61
+ //
62
+ // One shouldn't expect FingerprintCat64(Fingerprint64(x), Fingerprint64(y))
63
+ // to indicate anything about FingerprintCat64(StrCat(x, y)). This operation
64
+ // is not commutative.
65
+ //
66
+ // From a security standpoint, we don't encourage this pattern to be used
67
+ // for everything as it is vulnerable to length-extension attacks and it
68
+ // is easier to compute multicollisions.
69
+ inline uint64_t FingerprintCat64(const uint64_t fp1, const uint64_t fp2) {
70
+ static const uint64_t kMul = 0xc6a4a7935bd1e995ULL;
71
+ uint64_t result = fp1 ^ kMul;
72
+ result ^= internal::ShiftMix(fp2 * kMul) * kMul;
73
+ result *= kMul;
74
+ result = internal::ShiftMix(result) * kMul;
75
+ result = internal::ShiftMix(result);
76
+ return result;
77
+ }
78
+
79
+ // This is a portable fingerprint interface for strings that will never change.
80
+ // However, it is not suitable for cryptography.
81
+ inline uint64_t Fingerprint64(const tsl::StringPiece s) {
82
+ #ifdef USE_OSS_FARMHASH
83
+ return ::util::Fingerprint64(s.data(), s.size());
84
+ #else
85
+ // Fingerprint op depends on the fact that Fingerprint64() is implemented by
86
+ // Farmhash. If the implementation ever changes, Fingerprint op should be
87
+ // modified to keep using Farmhash.
88
+ // LINT.IfChange
89
+ return farmhash::Fingerprint64(s.data(), s.size());
90
+ // LINT.ThenChange(//tensorflow/core/kernels/fingerprint_op.cc)
91
+ #endif
92
+ }
93
+
94
+ // 32-bit variant of Fingerprint64 above (same properties and caveats apply).
95
+ inline uint32_t Fingerprint32(const tsl::StringPiece s) {
96
+ #ifdef USE_OSS_FARMHASH
97
+ return ::util::Fingerprint32(s.data(), s.size());
98
+ #else
99
+ return farmhash::Fingerprint32(s.data(), s.size());
100
+ #endif
101
+ }
102
+
103
+ // 128-bit variant of Fingerprint64 above (same properties and caveats apply).
104
+ inline Fprint128 Fingerprint128(const tsl::StringPiece s) {
105
+ #ifdef USE_OSS_FARMHASH
106
+ const auto fingerprint = ::util::Fingerprint128(s.data(), s.size());
107
+ return {::util::Uint128Low64(fingerprint),
108
+ ::util::Uint128High64(fingerprint)};
109
+ #else
110
+ const auto fingerprint = farmhash::Fingerprint128(s.data(), s.size());
111
+ return {absl::Uint128Low64(fingerprint), absl::Uint128High64(fingerprint)};
112
+ #endif
113
+ }
114
+
115
+ inline Fprint128 FingerprintCat128(const Fprint128& a, const Fprint128& b) {
116
+ return {FingerprintCat64(a.low64, b.low64),
117
+ FingerprintCat64(a.high64, b.high64)};
118
+ }
119
+
120
+ inline Fprint128 FingerprintCat128(const Fprint128& a, const uint64_t b) {
121
+ auto x = FingerprintCat64(a.low64, b);
122
+ return {x, FingerprintCat64(a.high64, x)};
123
+ }
124
+
125
+ } // namespace tsl
126
+
127
+ #endif // TENSORFLOW_TSL_PLATFORM_FINGERPRINT_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/gif.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_GIF_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_GIF_H_
18
+
19
+ #include "gif_lib.h" // from @gif
20
+
21
+ #endif // TENSORFLOW_TSL_PLATFORM_GIF_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/hash.h ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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
+ // Simple hash functions used for internal data structures
17
+
18
+ #ifndef TENSORFLOW_TSL_PLATFORM_HASH_H_
19
+ #define TENSORFLOW_TSL_PLATFORM_HASH_H_
20
+
21
+ #include <stddef.h>
22
+ #include <stdint.h>
23
+
24
+ #include <functional>
25
+ #include <string>
26
+
27
+ #include "tsl/platform/stringpiece.h"
28
+ #include "tsl/platform/types.h"
29
+
30
+ namespace tsl {
31
+
32
+ extern uint32 Hash32(const char* data, size_t n, uint32 seed);
33
+ extern uint64 Hash64(const char* data, size_t n, uint64 seed);
34
+
35
+ inline uint64 Hash64(const char* data, size_t n) {
36
+ return Hash64(data, n, 0xDECAFCAFFE);
37
+ }
38
+
39
+ inline uint64 Hash64(const char* data) { return Hash64(data, ::strlen(data)); }
40
+
41
+ inline uint64 Hash64(const std::string& str) {
42
+ return Hash64(str.data(), str.size());
43
+ }
44
+
45
+ inline uint64 Hash64(const tstring& str) {
46
+ return Hash64(str.data(), str.size());
47
+ }
48
+
49
+ inline uint64 Hash64Combine(uint64 a, uint64 b) {
50
+ return a ^ (b + 0x9e3779b97f4a7800ULL + (a << 10) + (a >> 4));
51
+ }
52
+
53
+ // Combine two hashes in an order-independent way. This operation should be
54
+ // associative and compute the same hash for a collection of elements
55
+ // independent of traversal order. Note that it is better to combine hashes
56
+ // symmetrically with addition rather than XOR, since (x^x) == 0 but (x+x) != 0.
57
+ inline uint64 Hash64CombineUnordered(uint64 a, uint64 b) { return a + b; }
58
+
59
+ // Hash functor suitable for use with power-of-two sized hashtables. Use
60
+ // instead of std::hash<T>.
61
+ //
62
+ // In particular, tsl::hash is not the identity function for pointers.
63
+ // This is important for power-of-two sized hashtables like FlatMap and FlatSet,
64
+ // because otherwise they waste the majority of their hash buckets.
65
+ //
66
+ // The second type argument is only used for SFNIAE below.
67
+ template <typename T, typename = void>
68
+ struct hash {
69
+ size_t operator()(const T& t) const { return std::hash<T>()(t); }
70
+ };
71
+
72
+ template <typename T>
73
+ struct hash<T, typename std::enable_if<std::is_enum<T>::value>::type> {
74
+ size_t operator()(T value) const {
75
+ // This works around a defect in the std::hash C++ spec that isn't fixed in
76
+ // (at least) gcc 4.8.4:
77
+ // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148
78
+ //
79
+ // We should be able to remove this and use the default
80
+ // tsl::hash<EnumTy>() once we stop building with GCC versions old
81
+ // enough to not have this defect fixed.
82
+ return std::hash<uint64>()(static_cast<uint64>(value));
83
+ }
84
+ };
85
+
86
+ template <typename T>
87
+ struct hash<T*> {
88
+ size_t operator()(const T* t) const {
89
+ // Hash pointers as integers, but bring more entropy to the lower bits.
90
+ size_t k = static_cast<size_t>(reinterpret_cast<uintptr_t>(t));
91
+ return k + (k >> 6);
92
+ }
93
+ };
94
+
95
+ template <>
96
+ struct hash<string> {
97
+ size_t operator()(const string& s) const {
98
+ return static_cast<size_t>(Hash64(s));
99
+ }
100
+ };
101
+
102
+ template <>
103
+ struct hash<tstring> {
104
+ size_t operator()(const tstring& s) const {
105
+ return static_cast<size_t>(Hash64(s.data(), s.size()));
106
+ }
107
+ };
108
+
109
+ template <>
110
+ struct hash<StringPiece> {
111
+ size_t operator()(StringPiece sp) const {
112
+ return static_cast<size_t>(Hash64(sp.data(), sp.size()));
113
+ }
114
+ };
115
+ using StringPieceHasher = ::tsl::hash<StringPiece>;
116
+
117
+ template <typename T, typename U>
118
+ struct hash<std::pair<T, U>> {
119
+ size_t operator()(const std::pair<T, U>& p) const {
120
+ return Hash64Combine(hash<T>()(p.first), hash<U>()(p.second));
121
+ }
122
+ };
123
+
124
+ } // namespace tsl
125
+
126
+ namespace std {
127
+ template <>
128
+ struct hash<tsl::tstring> {
129
+ size_t operator()(const tsl::tstring& s) const {
130
+ return static_cast<size_t>(tsl::Hash64(s.data(), s.size()));
131
+ }
132
+ };
133
+ } // namespace std
134
+
135
+ #endif // TENSORFLOW_TSL_PLATFORM_HASH_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/host_info.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_HOST_INFO_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_HOST_INFO_H_
18
+
19
+ #include <cstdint>
20
+
21
+ #include "tsl/platform/types.h"
22
+
23
+ namespace tsl {
24
+ namespace port {
25
+
26
+ // Statistical data of IO operations performed by the job.
27
+ struct IOStatistics {
28
+ struct Distribution {
29
+ uint64_t count = 0;
30
+ double mean = 0.0;
31
+ double std_dev = 0.0;
32
+ };
33
+ // Distribution of round trip IO latency in microseconds.
34
+ Distribution roundtrip_latency_usec;
35
+ // Distribution of data received by IO reads in bytes.
36
+ Distribution response_bytes;
37
+ };
38
+
39
+ // Return the hostname of the machine on which this process is running.
40
+ string Hostname();
41
+
42
+ // Return the job name as a string if it exists, otherwise return an empty
43
+ // string.
44
+ string JobName();
45
+
46
+ // Returns the Borg job UID as an int64_t if it exists. Otherwise return -1.
47
+ int64_t JobUid();
48
+
49
+ // Returns the Borg task ID as an int64_t if it exists. Otherwise return -1.
50
+ int64_t TaskId();
51
+
52
+ // Retrieves the host file read statistics.
53
+ IOStatistics GetIOStatistics();
54
+
55
+ } // namespace port
56
+ } // namespace tsl
57
+
58
+ #endif // TENSORFLOW_TSL_PLATFORM_HOST_INFO_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/human_readable_json.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2018 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_TSL_PLATFORM_HUMAN_READABLE_JSON_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_HUMAN_READABLE_JSON_H_
18
+
19
+ #include "tsl/platform/protobuf.h"
20
+ #include "tsl/platform/status.h"
21
+
22
+ namespace tsl {
23
+
24
+ // Converts a proto to a JSON-like string that's meant to be human-readable
25
+ // but still machine-parseable.
26
+ //
27
+ // This string may not be strictly JSON-compliant, but it must be parseable by
28
+ // HumanReadableJSONToProto.
29
+ //
30
+ // When ignore_accuracy_loss = true, this function may ignore JavaScript
31
+ // accuracy loss with large integers.
32
+ Status ProtoToHumanReadableJson(const protobuf::Message& proto, string* result,
33
+ bool ignore_accuracy_loss);
34
+ Status ProtoToHumanReadableJson(const protobuf::MessageLite& proto,
35
+ string* result, bool ignore_accuracy_loss);
36
+
37
+ // Converts a string produced by ProtoToHumanReadableJSON to a protobuf. Not
38
+ // guaranteed to work for general JSON.
39
+ Status HumanReadableJsonToProto(const string& str, protobuf::Message* proto);
40
+ Status HumanReadableJsonToProto(const string& str,
41
+ protobuf::MessageLite* proto);
42
+
43
+ } // namespace tsl
44
+
45
+ #endif // TENSORFLOW_TSL_PLATFORM_HUMAN_READABLE_JSON_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/init_main.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_INIT_MAIN_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_INIT_MAIN_H_
18
+
19
+ namespace tsl {
20
+ namespace port {
21
+
22
+ void InitMain(const char* usage, int* argc, char*** argv);
23
+
24
+ } // namespace port
25
+ } // namespace tsl
26
+
27
+ #endif // TENSORFLOW_TSL_PLATFORM_INIT_MAIN_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/jpeg.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_JPEG_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_JPEG_H_
18
+
19
+ #include <stddef.h>
20
+ #include <stdio.h>
21
+ #include <stdlib.h>
22
+ #include <sys/types.h>
23
+
24
+ extern "C" {
25
+ #include "jerror.h" // from @libjpeg_turbo // IWYU pragma: export
26
+ #include "jpeglib.h" // from @libjpeg_turbo // IWYU pragma: export
27
+ }
28
+
29
+ #endif // TENSORFLOW_TSL_PLATFORM_JPEG_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/load_library.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_LOAD_LIBRARY_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_LOAD_LIBRARY_H_
18
+
19
+ #include <string>
20
+
21
+ #include "absl/status/status.h"
22
+
23
+ namespace tsl {
24
+
25
+ namespace internal {
26
+
27
+ absl::Status LoadDynamicLibrary(const char* library_filename, void** handle);
28
+ absl::Status GetSymbolFromLibrary(void* handle, const char* symbol_name,
29
+ void** symbol);
30
+ std::string FormatLibraryFileName(const std::string& name,
31
+ const std::string& version);
32
+
33
+ } // namespace internal
34
+
35
+ } // namespace tsl
36
+
37
+ #endif // TENSORFLOW_TSL_PLATFORM_LOAD_LIBRARY_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/logging.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_LOGGING_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_LOGGING_H_
18
+
19
+ #include "tsl/platform/platform.h"
20
+
21
+ #if defined(PLATFORM_GOOGLE) || defined(PLATFORM_GOOGLE_ANDROID) || \
22
+ defined(PLATFORM_GOOGLE_IOS) || defined(GOOGLE_LOGGING) || \
23
+ defined(__EMSCRIPTEN__) || defined(PLATFORM_CHROMIUMOS)
24
+ #include "tsl/platform/google/logging.h" // IWYU pragma: export
25
+ #else
26
+ #include "tsl/platform/default/logging.h" // IWYU pragma: export
27
+ #endif
28
+
29
+ #endif // TENSORFLOW_TSL_PLATFORM_LOGGING_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/macros.h ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_MACROS_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_MACROS_H_
18
+
19
+ // Compiler attributes
20
+ #if (defined(__GNUC__) || defined(__APPLE__)) && !defined(SWIG)
21
+ // Compiler supports GCC-style attributes
22
+ #define TF_ATTRIBUTE_NORETURN __attribute__((noreturn))
23
+ #define TF_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
24
+ #define TF_ATTRIBUTE_NOINLINE __attribute__((noinline))
25
+ #define TF_ATTRIBUTE_UNUSED __attribute__((unused))
26
+ #define TF_ATTRIBUTE_COLD __attribute__((cold))
27
+ #define TF_ATTRIBUTE_WEAK __attribute__((weak))
28
+ #define TF_PACKED __attribute__((packed))
29
+ #define TF_MUST_USE_RESULT __attribute__((warn_unused_result))
30
+ #define TF_PRINTF_ATTRIBUTE(string_index, first_to_check) \
31
+ __attribute__((__format__(__printf__, string_index, first_to_check)))
32
+ #define TF_SCANF_ATTRIBUTE(string_index, first_to_check) \
33
+ __attribute__((__format__(__scanf__, string_index, first_to_check)))
34
+ #elif defined(_MSC_VER)
35
+ // Non-GCC equivalents
36
+ #define TF_ATTRIBUTE_NORETURN __declspec(noreturn)
37
+ #define TF_ATTRIBUTE_ALWAYS_INLINE __forceinline
38
+ #define TF_ATTRIBUTE_NOINLINE
39
+ #define TF_ATTRIBUTE_UNUSED
40
+ #define TF_ATTRIBUTE_COLD
41
+ #define TF_ATTRIBUTE_WEAK
42
+ #define TF_MUST_USE_RESULT
43
+ #define TF_PACKED
44
+ #define TF_PRINTF_ATTRIBUTE(string_index, first_to_check)
45
+ #define TF_SCANF_ATTRIBUTE(string_index, first_to_check)
46
+ #else
47
+ // Non-GCC equivalents
48
+ #define TF_ATTRIBUTE_NORETURN
49
+ #define TF_ATTRIBUTE_ALWAYS_INLINE
50
+ #define TF_ATTRIBUTE_NOINLINE
51
+ #define TF_ATTRIBUTE_UNUSED
52
+ #define TF_ATTRIBUTE_COLD
53
+ #define TF_ATTRIBUTE_WEAK
54
+ #define TF_MUST_USE_RESULT
55
+ #define TF_PACKED
56
+ #define TF_PRINTF_ATTRIBUTE(string_index, first_to_check)
57
+ #define TF_SCANF_ATTRIBUTE(string_index, first_to_check)
58
+ #endif
59
+
60
+ // Control visibility outside .so
61
+ #if defined(_WIN32)
62
+ #ifdef TF_COMPILE_LIBRARY
63
+ #define TF_EXPORT __declspec(dllexport)
64
+ #else
65
+ #define TF_EXPORT __declspec(dllimport)
66
+ #endif // TF_COMPILE_LIBRARY
67
+ #else
68
+ #define TF_EXPORT __attribute__((visibility("default")))
69
+ #endif // _WIN32
70
+
71
+ #ifdef __has_builtin
72
+ #define TF_HAS_BUILTIN(x) __has_builtin(x)
73
+ #else
74
+ #define TF_HAS_BUILTIN(x) 0
75
+ #endif
76
+
77
+ // C++11-style attributes (N2761)
78
+ #if defined(__has_cpp_attribute)
79
+ // Safely checks if an attribute is supported. Equivalent to
80
+ // ABSL_HAVE_CPP_ATTRIBUTE.
81
+ #define TF_HAS_CPP_ATTRIBUTE(n) __has_cpp_attribute(n)
82
+ #else
83
+ #define TF_HAS_CPP_ATTRIBUTE(n) 0
84
+ #endif
85
+
86
+ // [[clang::annotate("x")]] allows attaching custom strings (e.g. "x") to
87
+ // declarations (variables, functions, fields, etc.) for use by tools. They are
88
+ // represented in the Clang AST (as AnnotateAttr nodes) and in LLVM IR, but not
89
+ // in final output.
90
+ #if TF_HAS_CPP_ATTRIBUTE(clang::annotate)
91
+ #define TF_ATTRIBUTE_ANNOTATE(str) [[clang::annotate(str)]]
92
+ #else
93
+ #define TF_ATTRIBUTE_ANNOTATE(str)
94
+ #endif
95
+
96
+ // A variable declaration annotated with the `TF_CONST_INIT` attribute will
97
+ // not compile (on supported platforms) unless the variable has a constant
98
+ // initializer.
99
+ #if TF_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization)
100
+ #define TF_CONST_INIT [[clang::require_constant_initialization]]
101
+ #else
102
+ #define TF_CONST_INIT
103
+ #endif
104
+
105
+ // Compilers can be told that a certain branch is not likely to be taken
106
+ // (for instance, a CHECK failure), and use that information in static
107
+ // analysis. Giving it this information can help it optimize for the
108
+ // common case in the absence of better information (ie.
109
+ // -fprofile-arcs).
110
+ #if TF_HAS_BUILTIN(__builtin_expect) || (defined(__GNUC__) && __GNUC__ >= 3)
111
+ #define TF_PREDICT_FALSE(x) (__builtin_expect(x, 0))
112
+ #define TF_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
113
+ #else
114
+ #define TF_PREDICT_FALSE(x) (x)
115
+ #define TF_PREDICT_TRUE(x) (x)
116
+ #endif
117
+
118
+ // DEPRECATED: directly use the macro implementation instead.
119
+ // A macro to disallow the copy constructor and operator= functions
120
+ // This is usually placed in the private: declarations for a class.
121
+ #define TF_DISALLOW_COPY_AND_ASSIGN(TypeName) \
122
+ TypeName(const TypeName&) = delete; \
123
+ void operator=(const TypeName&) = delete
124
+
125
+ // The TF_ARRAYSIZE(arr) macro returns the # of elements in an array arr.
126
+ //
127
+ // The expression TF_ARRAYSIZE(a) is a compile-time constant of type
128
+ // size_t.
129
+ #define TF_ARRAYSIZE(a) \
130
+ ((sizeof(a) / sizeof(*(a))) / \
131
+ static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
132
+
133
+ #if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
134
+ (defined(_MSC_VER) && _MSC_VER >= 1900)
135
+ // Define this to 1 if the code is compiled in C++11 mode; leave it
136
+ // undefined otherwise. Do NOT define it to 0 -- that causes
137
+ // '#ifdef LANG_CXX11' to behave differently from '#if LANG_CXX11'.
138
+ #define LANG_CXX11 1
139
+ #endif
140
+
141
+ #if defined(__clang__) && defined(LANG_CXX11) && defined(__has_warning)
142
+ #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
143
+ #define TF_FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT
144
+ #endif
145
+ #endif
146
+
147
+ #ifndef TF_FALLTHROUGH_INTENDED
148
+ #define TF_FALLTHROUGH_INTENDED \
149
+ do { \
150
+ } while (0)
151
+ #endif
152
+
153
+ namespace tsl {
154
+ namespace internal {
155
+ template <typename T>
156
+ void remove_unused_variable_compiler_warning(const T&){};
157
+ } // namespace internal
158
+ } // namespace tsl
159
+ #define TF_UNUSED_VARIABLE(x) \
160
+ tensorflow::internal::remove_unused_variable_compiler_warning(x)
161
+
162
+ #endif // TENSORFLOW_TSL_PLATFORM_MACROS_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/mem.h ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_MEM_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_MEM_H_
18
+
19
+ // TODO(cwhipkey): remove this when callers use annotations directly.
20
+ #include "tsl/platform/dynamic_annotations.h"
21
+ #include "tsl/platform/platform.h"
22
+ #include "tsl/platform/types.h"
23
+
24
+ namespace tsl {
25
+ namespace port {
26
+
27
+ // Aligned allocation/deallocation. `minimum_alignment` must be a power of 2
28
+ // and a multiple of sizeof(void*).
29
+ void* AlignedMalloc(size_t size, int minimum_alignment);
30
+ void AlignedFree(void* aligned_memory);
31
+
32
+ void* Malloc(size_t size);
33
+ void* Realloc(void* ptr, size_t size);
34
+ void Free(void* ptr);
35
+
36
+ // Tries to release num_bytes of free memory back to the operating
37
+ // system for reuse. Use this routine with caution -- to get this
38
+ // memory back may require faulting pages back in by the OS, and
39
+ // that may be slow.
40
+ //
41
+ // Currently, if a malloc implementation does not support this
42
+ // routine, this routine is a no-op.
43
+ void MallocExtension_ReleaseToSystem(std::size_t num_bytes);
44
+
45
+ // Returns the actual number N of bytes reserved by the malloc for the
46
+ // pointer p. This number may be equal to or greater than the number
47
+ // of bytes requested when p was allocated.
48
+ //
49
+ // This routine is just useful for statistics collection. The
50
+ // client must *not* read or write from the extra bytes that are
51
+ // indicated by this call.
52
+ //
53
+ // Example, suppose the client gets memory by calling
54
+ // p = malloc(10)
55
+ // and GetAllocatedSize(p) may return 16. The client must only use the
56
+ // first 10 bytes p[0..9], and not attempt to read or write p[10..15].
57
+ //
58
+ // Currently, if a malloc implementation does not support this
59
+ // routine, this routine returns 0.
60
+ std::size_t MallocExtension_GetAllocatedSize(const void* p);
61
+
62
+ struct MemoryInfo {
63
+ int64_t total = 0;
64
+ int64_t free = 0;
65
+ };
66
+
67
+ struct MemoryBandwidthInfo {
68
+ int64_t bw_used = 0; // memory bandwidth used across all CPU (in MBs/second)
69
+ };
70
+
71
+ // Retrieves the host memory information. If any of the fields in the returned
72
+ // MemoryInfo structure is INT64_MAX, it means such information is not
73
+ // available.
74
+ MemoryInfo GetMemoryInfo();
75
+
76
+ // Retrieves the host memory bandwidth information. If any field in the returned
77
+ // structure is INT64_MAX, it means such information is not available.
78
+ MemoryBandwidthInfo GetMemoryBandwidthInfo();
79
+
80
+ // Returns the amount of RAM available in bytes, or INT64_MAX if unknown.
81
+ static inline int64_t AvailableRam() { return GetMemoryInfo().free; }
82
+
83
+ } // namespace port
84
+ } // namespace tsl
85
+
86
+ #endif // TENSORFLOW_TSL_PLATFORM_MEM_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/ml_dtypes.h ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #ifndef TENSORFLOW_TSL_PLATFORM_ML_DTYPES_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_ML_DTYPES_H_
18
+
19
+ #include "ml_dtypes/include/float8.h" // from @ml_dtypes
20
+ #include "ml_dtypes/include/int4.h" // from @ml_dtypes
21
+
22
+ namespace tsl {
23
+ using float8_e4m3fn = ml_dtypes::float8_e4m3fn;
24
+ using float8_e4m3fnuz = ml_dtypes::float8_e4m3fnuz;
25
+ using float8_e4m3b11fnuz = ml_dtypes::float8_e4m3b11fnuz;
26
+ using float8_e4m3b11 = float8_e4m3b11fnuz; // Deprecated: old name for
27
+ // backward-compatibility only.
28
+ using float8_e5m2 = ml_dtypes::float8_e5m2;
29
+ using float8_e5m2fnuz = ml_dtypes::float8_e5m2fnuz;
30
+
31
+ using int4 = ml_dtypes::int4;
32
+ using uint4 = ml_dtypes::uint4;
33
+ } // namespace tsl
34
+
35
+ #endif // TENSORFLOW_TSL_PLATFORM_ML_DTYPES_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/mutex.h ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_MUTEX_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_MUTEX_H_
18
+
19
+ #include <chrono> // NOLINT
20
+ // for std::try_to_lock_t and std::cv_status
21
+ #include <condition_variable> // NOLINT
22
+ #include <mutex> // NOLINT
23
+
24
+ #include "tsl/platform/platform.h"
25
+ #include "tsl/platform/thread_annotations.h"
26
+ #include "tsl/platform/types.h"
27
+
28
+ // Include appropriate platform-dependent implementation details of mutex etc.
29
+ #if defined(PLATFORM_GOOGLE)
30
+ #include "tsl/platform/google/mutex_data.h"
31
+ #elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \
32
+ defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \
33
+ defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS)
34
+ #include "tsl/platform/default/mutex_data.h"
35
+ #else
36
+ #error Define the appropriate PLATFORM_<foo> macro for this platform
37
+ #endif
38
+
39
+ namespace tsl {
40
+
41
+ enum ConditionResult { kCond_Timeout, kCond_MaybeNotified };
42
+ enum LinkerInitialized { LINKER_INITIALIZED };
43
+
44
+ class condition_variable;
45
+ class Condition;
46
+
47
+ // Mimic std::mutex + C++17's shared_mutex, adding a LinkerInitialized
48
+ // constructor interface. This type is as fast as mutex, but is also a shared
49
+ // lock, and provides conditional critical sections (via Await()), as an
50
+ // alternative to condition variables.
51
+ class TF_LOCKABLE mutex {
52
+ public:
53
+ mutex();
54
+ // The default implementation of the underlying mutex is safe to use after
55
+ // the linker initialization to zero.
56
+ explicit constexpr mutex(LinkerInitialized x)
57
+ :
58
+ #if defined(PLATFORM_GOOGLE)
59
+ mu_(absl::kConstInit)
60
+ #else
61
+ mu_()
62
+ #endif
63
+ {
64
+ }
65
+
66
+ void lock() TF_EXCLUSIVE_LOCK_FUNCTION();
67
+ bool try_lock() TF_EXCLUSIVE_TRYLOCK_FUNCTION(true);
68
+ void unlock() TF_UNLOCK_FUNCTION();
69
+
70
+ void lock_shared() TF_SHARED_LOCK_FUNCTION();
71
+ bool try_lock_shared() TF_SHARED_TRYLOCK_FUNCTION(true);
72
+ void unlock_shared() TF_UNLOCK_FUNCTION();
73
+
74
+ // -------
75
+ // Conditional critical sections.
76
+ // These represent an alternative to condition variables that is easier to
77
+ // use. The predicate must be encapsulated in a function (via Condition),
78
+ // but there is no need to use a while-loop, and no need to signal the
79
+ // condition. Example: suppose "mu" protects "counter"; we wish one thread
80
+ // to wait until counter is decremented to zero by another thread.
81
+ // // Predicate expressed as a function:
82
+ // static bool IntIsZero(int* pi) { return *pi == 0; }
83
+ //
84
+ // // Waiter:
85
+ // mu.lock();
86
+ // mu.Await(Condition(&IntIsZero, &counter)); // no loop needed
87
+ // // lock is held and counter==0...
88
+ // mu.unlock();
89
+ //
90
+ // // Decrementer:
91
+ // mu.lock();
92
+ // counter--;
93
+ // mu.unlock(); // no need to signal; mutex will check condition
94
+ //
95
+ // A mutex may be used with condition variables and conditional critical
96
+ // sections at the same time. Conditional critical sections are easier to
97
+ // use, but if there are multiple conditions that are simultaneously false,
98
+ // condition variables may be faster.
99
+
100
+ // Unlock *this and wait until cond.Eval() is true, then atomically reacquire
101
+ // *this in the same mode in which it was previously held and return.
102
+ void Await(const Condition& cond);
103
+
104
+ // Unlock *this and wait until either cond.Eval is true, or abs_deadline_ns
105
+ // has been reached, then atomically reacquire *this in the same mode in
106
+ // which it was previously held, and return whether cond.Eval() is true.
107
+ // See tsl/tsl/platform/env_time.h for the time interface.
108
+ bool AwaitWithDeadline(const Condition& cond, uint64 abs_deadline_ns);
109
+ // -------
110
+
111
+ private:
112
+ friend class condition_variable;
113
+ internal::MuData mu_;
114
+ };
115
+
116
+ // A Condition represents a predicate on state protected by a mutex. The
117
+ // function must have no side-effects on that state. When passed to
118
+ // mutex::Await(), the function will be called with the mutex held. It may be
119
+ // called:
120
+ // - any number of times;
121
+ // - by any thread using the mutex; and/or
122
+ // - with the mutex held in any mode (read or write).
123
+ // If you must use a lambda, prefix the lambda with +, and capture no variables.
124
+ // For example: Condition(+[](int *pi)->bool { return *pi == 0; }, &i)
125
+ class Condition {
126
+ public:
127
+ template <typename T>
128
+ Condition(bool (*func)(T* arg), T* arg); // Value is (*func)(arg)
129
+ template <typename T>
130
+ Condition(T* obj, bool (T::*method)()); // Value is obj->*method()
131
+ template <typename T>
132
+ Condition(T* obj, bool (T::*method)() const); // Value is obj->*method()
133
+ explicit Condition(const bool* flag); // Value is *flag
134
+
135
+ // Return the value of the predicate represented by this Condition.
136
+ bool Eval() const { return (*this->eval_)(this); }
137
+
138
+ private:
139
+ bool (*eval_)(const Condition*); // CallFunction, CallMethod, or, ReturnBool
140
+ bool (*function_)(void*); // predicate of form (*function_)(arg_)
141
+ bool (Condition::*method_)(); // predicate of form arg_->method_()
142
+ void* arg_;
143
+ Condition();
144
+ // The following functions can be pointed to by the eval_ field.
145
+ template <typename T>
146
+ static bool CallFunction(const Condition* cond); // call function_
147
+ template <typename T>
148
+ static bool CallMethod(const Condition* cond); // call method_
149
+ static bool ReturnBool(const Condition* cond); // access *(bool *)arg_
150
+ };
151
+
152
+ // Mimic a subset of the std::unique_lock<tsl::mutex> functionality.
153
+ class TF_SCOPED_LOCKABLE mutex_lock {
154
+ public:
155
+ typedef ::tsl::mutex mutex_type;
156
+
157
+ explicit mutex_lock(mutex_type& mu) TF_EXCLUSIVE_LOCK_FUNCTION(mu)
158
+ : mu_(&mu) {
159
+ mu_->lock();
160
+ }
161
+
162
+ mutex_lock(mutex_type& mu, std::try_to_lock_t) TF_EXCLUSIVE_LOCK_FUNCTION(mu)
163
+ : mu_(&mu) {
164
+ if (!mu.try_lock()) {
165
+ mu_ = nullptr;
166
+ }
167
+ }
168
+
169
+ // Manually nulls out the source to prevent double-free.
170
+ // (std::move does not null the source pointer by default.)
171
+ mutex_lock(mutex_lock&& ml) noexcept TF_EXCLUSIVE_LOCK_FUNCTION(ml.mu_)
172
+ : mu_(ml.mu_) {
173
+ ml.mu_ = nullptr;
174
+ }
175
+ ~mutex_lock() TF_UNLOCK_FUNCTION() {
176
+ if (mu_ != nullptr) {
177
+ mu_->unlock();
178
+ }
179
+ }
180
+ mutex_type* mutex() { return mu_; }
181
+
182
+ explicit operator bool() const { return mu_ != nullptr; }
183
+
184
+ private:
185
+ mutex_type* mu_;
186
+ };
187
+
188
+ // Catch bug where variable name is omitted, e.g. mutex_lock (mu);
189
+ #define mutex_lock(x) static_assert(0, "mutex_lock_decl_missing_var_name");
190
+
191
+ // Mimic a subset of the std::shared_lock<tsl::mutex> functionality.
192
+ // Name chosen to minimize conflicts with the tf_shared_lock macro, below.
193
+ class TF_SCOPED_LOCKABLE tf_shared_lock {
194
+ public:
195
+ typedef ::tsl::mutex mutex_type;
196
+
197
+ explicit tf_shared_lock(mutex_type& mu) TF_SHARED_LOCK_FUNCTION(mu)
198
+ : mu_(&mu) {
199
+ mu_->lock_shared();
200
+ }
201
+
202
+ tf_shared_lock(mutex_type& mu, std::try_to_lock_t) TF_SHARED_LOCK_FUNCTION(mu)
203
+ : mu_(&mu) {
204
+ if (!mu.try_lock_shared()) {
205
+ mu_ = nullptr;
206
+ }
207
+ }
208
+
209
+ // Manually nulls out the source to prevent double-free.
210
+ // (std::move does not null the source pointer by default.)
211
+ tf_shared_lock(tf_shared_lock&& ml) noexcept TF_SHARED_LOCK_FUNCTION(ml.mu_)
212
+ : mu_(ml.mu_) {
213
+ ml.mu_ = nullptr;
214
+ }
215
+ ~tf_shared_lock() TF_UNLOCK_FUNCTION() {
216
+ if (mu_ != nullptr) {
217
+ mu_->unlock_shared();
218
+ }
219
+ }
220
+ mutex_type* mutex() { return mu_; }
221
+
222
+ explicit operator bool() const { return mu_ != nullptr; }
223
+
224
+ private:
225
+ mutex_type* mu_;
226
+ };
227
+
228
+ // Catch bug where variable name is omitted, e.g. tf_shared_lock (mu);
229
+ #define tf_shared_lock(x) \
230
+ static_assert(0, "tf_shared_lock_decl_missing_var_name");
231
+
232
+ // Mimic std::condition_variable.
233
+ class condition_variable {
234
+ public:
235
+ condition_variable();
236
+
237
+ void wait(mutex_lock& lock);
238
+
239
+ template <class Predicate>
240
+ void wait(mutex_lock& lock, Predicate stop_waiting) {
241
+ while (!stop_waiting()) {
242
+ wait(lock);
243
+ }
244
+ }
245
+
246
+ template <class Rep, class Period>
247
+ std::cv_status wait_for(mutex_lock& lock,
248
+ std::chrono::duration<Rep, Period> dur);
249
+ void notify_one();
250
+ void notify_all();
251
+
252
+ private:
253
+ friend ConditionResult WaitForMilliseconds(mutex_lock* mu,
254
+ condition_variable* cv,
255
+ int64_t ms);
256
+ internal::CVData cv_;
257
+ };
258
+
259
+ // Like "cv->wait(*mu)", except that it only waits for up to "ms" milliseconds.
260
+ //
261
+ // Returns kCond_Timeout if the timeout expired without this
262
+ // thread noticing a signal on the condition variable. Otherwise may
263
+ // return either kCond_Timeout or kCond_MaybeNotified
264
+ inline ConditionResult WaitForMilliseconds(mutex_lock* mu,
265
+ condition_variable* cv, int64_t ms) {
266
+ std::cv_status s = cv->wait_for(*mu, std::chrono::milliseconds(ms));
267
+ return (s == std::cv_status::timeout) ? kCond_Timeout : kCond_MaybeNotified;
268
+ }
269
+
270
+ // ------------------------------------------------------------
271
+ // Implementation details follow. Clients should ignore them.
272
+
273
+ // private static
274
+ template <typename T>
275
+ inline bool Condition::CallFunction(const Condition* cond) {
276
+ bool (*fn)(T*) = reinterpret_cast<bool (*)(T*)>(cond->function_);
277
+ return (*fn)(static_cast<T*>(cond->arg_));
278
+ }
279
+
280
+ template <typename T>
281
+ inline Condition::Condition(bool (*func)(T*), T* arg)
282
+ : eval_(&CallFunction<T>),
283
+ function_(reinterpret_cast<bool (*)(void*)>(func)),
284
+ method_(nullptr),
285
+ arg_(const_cast<void*>(static_cast<const void*>(arg))) {}
286
+
287
+ // private static
288
+ template <typename T>
289
+ inline bool Condition::CallMethod(const Condition* cond) {
290
+ bool (T::*m)() = reinterpret_cast<bool (T::*)()>(cond->method_);
291
+ return (static_cast<T*>(cond->arg_)->*m)();
292
+ }
293
+
294
+ template <typename T>
295
+ inline Condition::Condition(T* obj, bool (T::*method)())
296
+ : eval_(&CallMethod<T>),
297
+ function_(nullptr),
298
+ method_(reinterpret_cast<bool (Condition::*)()>(method)),
299
+ arg_(const_cast<void*>(static_cast<const void*>(obj))) {}
300
+
301
+ template <typename T>
302
+ inline Condition::Condition(T* obj, bool (T::*method)() const)
303
+ : eval_(&CallMethod<T>),
304
+ function_(nullptr),
305
+ method_(reinterpret_cast<bool (Condition::*)()>(method)),
306
+ arg_(const_cast<void*>(static_cast<const void*>(obj))) {}
307
+
308
+ // private static
309
+ inline bool Condition::ReturnBool(const Condition* cond) {
310
+ return *static_cast<bool*>(cond->arg_);
311
+ }
312
+
313
+ inline Condition::Condition(const bool* flag)
314
+ : eval_(&ReturnBool),
315
+ function_(nullptr),
316
+ method_(nullptr),
317
+ arg_(const_cast<void*>(static_cast<const void*>(flag))) {}
318
+
319
+ } // namespace tsl
320
+
321
+ // Include appropriate platform-dependent implementation details of mutex etc.
322
+ #if defined(PLATFORM_GOOGLE)
323
+ #include "tsl/platform/google/mutex.h"
324
+ #elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \
325
+ defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \
326
+ defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS)
327
+ #include "tsl/platform/default/mutex.h"
328
+ #else
329
+ #error Define the appropriate PLATFORM_<foo> macro for this platform
330
+ #endif
331
+
332
+ #endif // TENSORFLOW_TSL_PLATFORM_MUTEX_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/net.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_NET_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_NET_H_
18
+
19
+ namespace tsl {
20
+ namespace internal {
21
+
22
+ int PickUnusedPortOrDie();
23
+
24
+ } // namespace internal
25
+ } // namespace tsl
26
+
27
+ #endif // TENSORFLOW_TSL_PLATFORM_NET_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/notification.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2016 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_TSL_PLATFORM_NOTIFICATION_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_NOTIFICATION_H_
18
+
19
+ #include <chrono> // NOLINT
20
+ #include <condition_variable> // NOLINT
21
+ #include <cstdint>
22
+ #include <mutex> // NOLINT
23
+
24
+ #include "absl/synchronization/notification.h"
25
+ #include "absl/time/time.h"
26
+
27
+ namespace tsl {
28
+
29
+ using absl::Notification;
30
+
31
+ // TODO(ddunleavy): remove this method and replace uses of `tsl::Notification`
32
+ // with `absl::Notification`.
33
+ inline bool WaitForNotificationWithTimeout(Notification* n,
34
+ int64_t timeout_in_us) {
35
+ return n->WaitForNotificationWithTimeout(absl::Microseconds(timeout_in_us));
36
+ }
37
+
38
+ } // namespace tsl
39
+
40
+ #endif // TENSORFLOW_TSL_PLATFORM_NOTIFICATION_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/null_file_system.h ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2018 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_TSL_PLATFORM_NULL_FILE_SYSTEM_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_NULL_FILE_SYSTEM_H_
18
+
19
+ #include <memory>
20
+ #include <string>
21
+ #include <vector>
22
+
23
+ #include "tsl/platform/env.h"
24
+ #include "tsl/platform/file_system.h"
25
+ #include "tsl/platform/file_system_helper.h"
26
+
27
+ namespace tsl {
28
+
29
+ // START_SKIP_DOXYGEN
30
+
31
+ #ifndef SWIG
32
+ // Degenerate file system that provides no implementations.
33
+ class NullFileSystem : public FileSystem {
34
+ public:
35
+ NullFileSystem() {}
36
+
37
+ ~NullFileSystem() override = default;
38
+
39
+ TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT;
40
+
41
+ Status NewRandomAccessFile(
42
+ const string& fname, TransactionToken* token,
43
+ std::unique_ptr<RandomAccessFile>* result) override {
44
+ return errors::Unimplemented("NewRandomAccessFile unimplemented");
45
+ }
46
+
47
+ Status NewWritableFile(const string& fname, TransactionToken* token,
48
+ std::unique_ptr<WritableFile>* result) override {
49
+ return errors::Unimplemented("NewWritableFile unimplemented");
50
+ }
51
+
52
+ Status NewAppendableFile(const string& fname, TransactionToken* token,
53
+ std::unique_ptr<WritableFile>* result) override {
54
+ return errors::Unimplemented("NewAppendableFile unimplemented");
55
+ }
56
+
57
+ Status NewReadOnlyMemoryRegionFromFile(
58
+ const string& fname, TransactionToken* token,
59
+ std::unique_ptr<ReadOnlyMemoryRegion>* result) override {
60
+ return errors::Unimplemented(
61
+ "NewReadOnlyMemoryRegionFromFile unimplemented");
62
+ }
63
+
64
+ Status FileExists(const string& fname, TransactionToken* token) override {
65
+ return errors::Unimplemented("FileExists unimplemented");
66
+ }
67
+
68
+ Status GetChildren(const string& dir, TransactionToken* token,
69
+ std::vector<string>* result) override {
70
+ return errors::Unimplemented("GetChildren unimplemented");
71
+ }
72
+
73
+ Status GetMatchingPaths(const string& pattern, TransactionToken* token,
74
+ std::vector<string>* results) override {
75
+ return internal::GetMatchingPaths(this, Env::Default(), pattern, results);
76
+ }
77
+
78
+ Status DeleteFile(const string& fname, TransactionToken* token) override {
79
+ return errors::Unimplemented("DeleteFile unimplemented");
80
+ }
81
+
82
+ Status CreateDir(const string& dirname, TransactionToken* token) override {
83
+ return errors::Unimplemented("CreateDir unimplemented");
84
+ }
85
+
86
+ Status DeleteDir(const string& dirname, TransactionToken* token) override {
87
+ return errors::Unimplemented("DeleteDir unimplemented");
88
+ }
89
+
90
+ Status GetFileSize(const string& fname, TransactionToken* token,
91
+ uint64* file_size) override {
92
+ return errors::Unimplemented("GetFileSize unimplemented");
93
+ }
94
+
95
+ Status RenameFile(const string& src, const string& target,
96
+ TransactionToken* token) override {
97
+ return errors::Unimplemented("RenameFile unimplemented");
98
+ }
99
+
100
+ Status Stat(const string& fname, TransactionToken* token,
101
+ FileStatistics* stat) override {
102
+ return errors::Unimplemented("Stat unimplemented");
103
+ }
104
+ };
105
+ #endif
106
+
107
+ // END_SKIP_DOXYGEN
108
+
109
+ } // namespace tsl
110
+
111
+ #endif // TENSORFLOW_TSL_PLATFORM_NULL_FILE_SYSTEM_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/numa.h ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2018 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_TSL_PLATFORM_NUMA_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_NUMA_H_
18
+
19
+ #include "tsl/platform/platform.h"
20
+ #include "tsl/platform/types.h"
21
+
22
+ namespace tsl {
23
+ namespace port {
24
+
25
+ // Returns true iff NUMA functions are supported.
26
+ bool NUMAEnabled();
27
+
28
+ // Returns the number of NUMA nodes present with respect to CPU operations.
29
+ // Typically this will be the number of sockets where some RAM has greater
30
+ // affinity with one socket than another.
31
+ int NUMANumNodes();
32
+
33
+ static const int kNUMANoAffinity = -1;
34
+
35
+ // If possible sets affinity of the current thread to the specified NUMA node.
36
+ // If node == kNUMANoAffinity removes affinity to any particular node.
37
+ void NUMASetThreadNodeAffinity(int node);
38
+
39
+ // Returns NUMA node affinity of the current thread, kNUMANoAffinity if none.
40
+ int NUMAGetThreadNodeAffinity();
41
+
42
+ // Like AlignedMalloc, but allocates memory with affinity to the specified NUMA
43
+ // node.
44
+ //
45
+ // Notes:
46
+ // 1. node must be >= 0 and < NUMANumNodes.
47
+ // 1. minimum_alignment must a factor of system page size, the memory
48
+ // returned will be page-aligned.
49
+ // 2. This function is likely significantly slower than AlignedMalloc
50
+ // and should not be used for lots of small allocations. It makes more
51
+ // sense as a backing allocator for BFCAllocator, PoolAllocator, or similar.
52
+ void* NUMAMalloc(int node, size_t size, int minimum_alignment);
53
+
54
+ // Memory allocated by NUMAMalloc must be freed via NUMAFree.
55
+ void NUMAFree(void* ptr, size_t size);
56
+
57
+ // Returns NUMA node affinity of memory address, kNUMANoAffinity if none.
58
+ int NUMAGetMemAffinity(const void* ptr);
59
+
60
+ } // namespace port
61
+ } // namespace tsl
62
+ #endif // TENSORFLOW_TSL_PLATFORM_NUMA_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/numbers.h ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_NUMBERS_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_NUMBERS_H_
18
+
19
+ #include <cstdint>
20
+ #include <string>
21
+
22
+ #include "tsl/platform/stringpiece.h"
23
+ #include "tsl/platform/types.h"
24
+
25
+ namespace tsl {
26
+ namespace strings {
27
+
28
+ // ----------------------------------------------------------------------
29
+ // FastIntToBufferLeft()
30
+ // These are intended for speed.
31
+ //
32
+ // All functions take the output buffer as an arg. FastInt() uses
33
+ // at most 22 bytes, FastTime() uses exactly 30 bytes. They all
34
+ // return a pointer to the beginning of the output, which is the same as
35
+ // the beginning of the input buffer.
36
+ //
37
+ // NOTE: In 64-bit land, sizeof(time_t) is 8, so it is possible
38
+ // to pass to FastTimeToBuffer() a time whose year cannot be
39
+ // represented in 4 digits. In this case, the output buffer
40
+ // will contain the string "Invalid:<value>"
41
+ // ----------------------------------------------------------------------
42
+
43
+ // Previously documented minimums -- the buffers provided must be at least this
44
+ // long, though these numbers are subject to change:
45
+ // Int32, UInt32: 12 bytes
46
+ // Int64, UInt64, Int, Uint: 22 bytes
47
+ // Time: 30 bytes
48
+ // Use kFastToBufferSize rather than hardcoding constants.
49
+ static const int kFastToBufferSize = 32;
50
+
51
+ // ----------------------------------------------------------------------
52
+ // FastInt32ToBufferLeft()
53
+ // FastUInt32ToBufferLeft()
54
+ // FastInt64ToBufferLeft()
55
+ // FastUInt64ToBufferLeft()
56
+ //
57
+ // These functions convert their numeric argument to an ASCII
58
+ // representation of the numeric value in base 10, with the
59
+ // representation being left-aligned in the buffer. The caller is
60
+ // responsible for ensuring that the buffer has enough space to hold
61
+ // the output. The buffer should typically be at least kFastToBufferSize
62
+ // bytes.
63
+ //
64
+ // Returns the number of characters written.
65
+ // ----------------------------------------------------------------------
66
+
67
+ size_t FastInt32ToBufferLeft(int32_t i, char* buffer); // at least 12 bytes
68
+ size_t FastUInt32ToBufferLeft(uint32_t i, char* buffer); // at least 12 bytes
69
+ size_t FastInt64ToBufferLeft(int64_t i, char* buffer); // at least 22 bytes
70
+ size_t FastUInt64ToBufferLeft(uint64_t i, char* buffer); // at least 22 bytes
71
+
72
+ // Required buffer size for DoubleToBuffer is kFastToBufferSize.
73
+ // Required buffer size for FloatToBuffer is kFastToBufferSize.
74
+ size_t DoubleToBuffer(double value, char* buffer);
75
+ size_t FloatToBuffer(float value, char* buffer);
76
+
77
+ // Convert a 64-bit fingerprint value to an ASCII representation.
78
+ std::string FpToString(Fprint fp);
79
+
80
+ // Attempt to parse a fingerprint in the form encoded by FpToString. If
81
+ // successful, stores the fingerprint in *fp and returns true. Otherwise,
82
+ // returns false.
83
+ bool StringToFp(const std::string& s, Fprint* fp);
84
+
85
+ // Convert a 64-bit fingerprint value to an ASCII representation that
86
+ // is terminated by a '\0'.
87
+ // Buf must point to an array of at least kFastToBufferSize characters
88
+ StringPiece Uint64ToHexString(uint64_t v, char* buf);
89
+
90
+ // Attempt to parse a uint64 in the form encoded by FastUint64ToHexString. If
91
+ // successful, stores the value in *v and returns true. Otherwise,
92
+ // returns false.
93
+ bool HexStringToUint64(const StringPiece& s, uint64_t* result);
94
+
95
+ // Convert strings to 32bit integer values.
96
+ // Leading and trailing spaces are allowed.
97
+ // Return false with overflow or invalid input.
98
+ bool safe_strto32(StringPiece str, int32_t* value);
99
+
100
+ // Convert strings to unsigned 32bit integer values.
101
+ // Leading and trailing spaces are allowed.
102
+ // Return false with overflow or invalid input.
103
+ bool safe_strtou32(StringPiece str, uint32_t* value);
104
+
105
+ // Convert strings to 64bit integer values.
106
+ // Leading and trailing spaces are allowed.
107
+ // Return false with overflow or invalid input.
108
+ bool safe_strto64(StringPiece str, int64_t* value);
109
+
110
+ // Convert strings to unsigned 64bit integer values.
111
+ // Leading and trailing spaces are allowed.
112
+ // Return false with overflow or invalid input.
113
+ bool safe_strtou64(StringPiece str, uint64_t* value);
114
+
115
+ // Convert strings to floating point values.
116
+ // Leading and trailing spaces are allowed.
117
+ // Values may be rounded on over- and underflow.
118
+ // Returns false on invalid input or if `strlen(value) >= kFastToBufferSize`.
119
+ bool safe_strtof(StringPiece str, float* value);
120
+
121
+ // Convert strings to double precision floating point values.
122
+ // Leading and trailing spaces are allowed.
123
+ // Values may be rounded on over- and underflow.
124
+ // Returns false on invalid input or if `strlen(value) >= kFastToBufferSize`.
125
+ bool safe_strtod(StringPiece str, double* value);
126
+
127
+ inline bool ProtoParseNumeric(StringPiece s, int32_t* value) {
128
+ return safe_strto32(s, value);
129
+ }
130
+
131
+ inline bool ProtoParseNumeric(StringPiece s, uint32_t* value) {
132
+ return safe_strtou32(s, value);
133
+ }
134
+
135
+ inline bool ProtoParseNumeric(StringPiece s, int64_t* value) {
136
+ return safe_strto64(s, value);
137
+ }
138
+
139
+ inline bool ProtoParseNumeric(StringPiece s, uint64_t* value) {
140
+ return safe_strtou64(s, value);
141
+ }
142
+
143
+ inline bool ProtoParseNumeric(StringPiece s, float* value) {
144
+ return safe_strtof(s, value);
145
+ }
146
+
147
+ inline bool ProtoParseNumeric(StringPiece s, double* value) {
148
+ return safe_strtod(s, value);
149
+ }
150
+
151
+ // Convert strings to number of type T.
152
+ // Leading and trailing spaces are allowed.
153
+ // Values may be rounded on over- and underflow.
154
+ template <typename T>
155
+ bool SafeStringToNumeric(StringPiece s, T* value) {
156
+ return ProtoParseNumeric(s, value);
157
+ }
158
+
159
+ // Converts from an int64 to a human readable string representing the
160
+ // same number, using decimal powers. e.g. 1200000 -> "1.20M".
161
+ std::string HumanReadableNum(int64_t value);
162
+
163
+ // Converts from an int64 representing a number of bytes to a
164
+ // human readable string representing the same number.
165
+ // e.g. 12345678 -> "11.77MiB".
166
+ std::string HumanReadableNumBytes(int64_t num_bytes);
167
+
168
+ // Converts a time interval as double to a human readable
169
+ // string. For example:
170
+ // 0.001 -> "1 ms"
171
+ // 10.0 -> "10 s"
172
+ // 933120.0 -> "10.8 days"
173
+ // 39420000.0 -> "1.25 years"
174
+ // -10 -> "-10 s"
175
+ std::string HumanReadableElapsedTime(double seconds);
176
+
177
+ } // namespace strings
178
+ } // namespace tsl
179
+
180
+ #endif // TENSORFLOW_TSL_PLATFORM_NUMBERS_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/path.h ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_PATH_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_PATH_H_
18
+
19
+ #include <string>
20
+
21
+ #include "tsl/platform/stringpiece.h"
22
+ #include "tsl/platform/types.h"
23
+
24
+ namespace tsl {
25
+ namespace io {
26
+ namespace internal {
27
+ std::string JoinPathImpl(std::initializer_list<tsl::StringPiece> paths);
28
+ }
29
+
30
+ // Utility routines for processing filenames
31
+
32
+ #ifndef SWIG // variadic templates
33
+ // Join multiple paths together, without introducing unnecessary path
34
+ // separators.
35
+ // For example:
36
+ //
37
+ // Arguments | JoinPath
38
+ // ---------------------------+----------
39
+ // '/foo', 'bar' | /foo/bar
40
+ // '/foo/', 'bar' | /foo/bar
41
+ // '/foo', '/bar' | /foo/bar
42
+ //
43
+ // Usage:
44
+ // string path = io::JoinPath("/mydir", filename);
45
+ // string path = io::JoinPath(FLAGS_test_srcdir, filename);
46
+ // string path = io::JoinPath("/full", "path", "to", "filename");
47
+ template <typename... T>
48
+ std::string JoinPath(const T&... args) {
49
+ return internal::JoinPathImpl({args...});
50
+ }
51
+ #endif /* SWIG */
52
+
53
+ // Return true if path is absolute.
54
+ bool IsAbsolutePath(tsl::StringPiece path);
55
+
56
+ // Returns the part of the path before the final "/". If there is a single
57
+ // leading "/" in the path, the result will be the leading "/". If there is
58
+ // no "/" in the path, the result is the empty prefix of the input.
59
+ tsl::StringPiece Dirname(tsl::StringPiece path);
60
+
61
+ // Returns the part of the path after the final "/". If there is no
62
+ // "/" in the path, the result is the same as the input.
63
+ tsl::StringPiece Basename(tsl::StringPiece path);
64
+
65
+ // Returns the part of the basename of path after the final ".". If
66
+ // there is no "." in the basename, the result is empty.
67
+ tsl::StringPiece Extension(tsl::StringPiece path);
68
+
69
+ // Returns the part of the basename of path before the final ".". If
70
+ // there is no "." in the basename, the result is empty.
71
+ tsl::StringPiece BasenamePrefix(tsl::StringPiece path);
72
+
73
+ // Returns the largest common subpath of `paths`.
74
+ //
75
+ // For example, for "/alpha/beta/gamma" and "/alpha/beta/ga" returns
76
+ // "/alpha/beta/". For "/alpha/beta/gamma" and "/alpha/beta/gamma" returns
77
+ // "/alpha/beta/".
78
+ //
79
+ // Does not perform any path normalization.
80
+ std::string CommonPathPrefix(absl::Span<std::string const> paths);
81
+
82
+ // Collapse duplicate "/"s, resolve ".." and "." path elements, remove
83
+ // trailing "/".
84
+ //
85
+ // NOTE: This respects relative vs. absolute paths, but does not
86
+ // invoke any system calls (getcwd(2)) in order to resolve relative
87
+ // paths with respect to the actual working directory. That is, this is purely
88
+ // string manipulation, completely independent of process state.
89
+ std::string CleanPath(tsl::StringPiece path);
90
+
91
+ // Populates the scheme, host, and path from a URI. scheme, host, and path are
92
+ // guaranteed by this function to point into the contents of uri, even if
93
+ // empty.
94
+ //
95
+ // Corner cases:
96
+ // - If the URI is invalid, scheme and host are set to empty strings and the
97
+ // passed string is assumed to be a path
98
+ // - If the URI omits the path (e.g. file://host), then the path is left empty.
99
+ void ParseURI(tsl::StringPiece uri, tsl::StringPiece* scheme,
100
+ tsl::StringPiece* host, tsl::StringPiece* path);
101
+
102
+ // Creates a URI from a scheme, host, and path. If the scheme is empty, we just
103
+ // return the path.
104
+ std::string CreateURI(tsl::StringPiece scheme, tsl::StringPiece host,
105
+ tsl::StringPiece path);
106
+
107
+ // Creates a temporary file name with an extension.
108
+ std::string GetTempFilename(const std::string& extension);
109
+
110
+ // Returns whether the test workspace directory is known. If it's known and dir
111
+ // != nullptr then sets *dir to that.
112
+ //
113
+ // The test workspace directory is known to be TEST_SRCDIR/TEST_WORKSPACE if
114
+ // both the TEST_SRCDIR and TEST_WORKSPACE environment variables are set.
115
+ bool GetTestWorkspaceDir(std::string* dir);
116
+
117
+ // Returns whether the TEST_UNDECLARED_OUTPUTS_DIR environment variable is set.
118
+ // If it's set and dir != nullptr then sets *dir to that.
119
+ bool GetTestUndeclaredOutputsDir(std::string* dir);
120
+
121
+ // Resolves paths to help tests find files in their workspace or output
122
+ // directory. Returns whether the path can be resolved. If it can be then sets
123
+ // resolved_path to that.
124
+ //
125
+ // Currently the TEST_WORKSPACE and the TEST_UNDECLARED_OUTPUTS_DIR prefixes can
126
+ // be resolved.
127
+ bool ResolveTestPrefixes(tsl::StringPiece path, std::string& resolved_path);
128
+
129
+ } // namespace io
130
+ } // namespace tsl
131
+
132
+ #endif // TENSORFLOW_TSL_PLATFORM_PATH_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/prefetch.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_PREFETCH_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_PREFETCH_H_
18
+
19
+ #include "absl/base/prefetch.h"
20
+
21
+ namespace tsl {
22
+ namespace port {
23
+
24
+ // Prefetching support.
25
+ // Deprecated. Prefer to call absl::Prefetch* directly.
26
+
27
+ enum PrefetchHint {
28
+ PREFETCH_HINT_T0 = 3, // Temporal locality
29
+ PREFETCH_HINT_NTA = 0 // No temporal locality
30
+ };
31
+
32
+ template <PrefetchHint hint>
33
+ void prefetch(const void* x) {
34
+ absl::PrefetchToLocalCache(x);
35
+ }
36
+
37
+ template <>
38
+ inline void prefetch<PREFETCH_HINT_NTA>(const void* x) {
39
+ absl::PrefetchToLocalCacheNta(x);
40
+ }
41
+
42
+ } // namespace port
43
+ } // namespace tsl
44
+
45
+ #endif // TENSORFLOW_TSL_PLATFORM_PREFETCH_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/protobuf.h ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_PROTOBUF_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_PROTOBUF_H_
18
+
19
+ #include <cstdint>
20
+
21
+ #include "tsl/platform/platform.h"
22
+ #include "tsl/platform/types.h"
23
+
24
+ // Import whatever namespace protobuf comes from into the
25
+ // ::tsl::protobuf namespace.
26
+ //
27
+ // TensorFlow code should use the ::tensorflow::protobuf namespace to
28
+ // refer to all protobuf APIs.
29
+
30
+ #include "google/protobuf/descriptor.pb.h" // IWYU pragma:export
31
+ #include "google/protobuf/arena.h" // IWYU pragma:export
32
+ #include "google/protobuf/descriptor.h" // IWYU pragma:export
33
+ #include "google/protobuf/dynamic_message.h" // IWYU pragma:export
34
+ #include "google/protobuf/io/coded_stream.h" // IWYU pragma:export
35
+ #include "google/protobuf/io/tokenizer.h" // IWYU pragma:export
36
+ #include "google/protobuf/io/zero_copy_stream.h" // IWYU pragma:export
37
+ #include "google/protobuf/io/zero_copy_stream_impl_lite.h" // IWYU pragma:export
38
+ #include "google/protobuf/map.h" // IWYU pragma:export
39
+ #include "google/protobuf/message.h" // IWYU pragma:export
40
+ #include "google/protobuf/repeated_field.h" // IWYU pragma:export
41
+ #include "google/protobuf/repeated_ptr_field.h" // IWYU pragma:export
42
+ #include "google/protobuf/text_format.h" // IWYU pragma:export
43
+ #include "google/protobuf/util/field_comparator.h" // IWYU pragma:export
44
+ #include "google/protobuf/util/json_util.h" // IWYU pragma:export
45
+ #include "google/protobuf/util/message_differencer.h" // IWYU pragma:export
46
+ #include "google/protobuf/util/type_resolver_util.h" // IWYU pragma:export
47
+
48
+ #if !TSL_IS_IN_OSS
49
+ #define TENSORFLOW_PROTOBUF_USES_CORD 1
50
+ #endif // TSL_IS_IN_OSS
51
+
52
+ namespace tsl {
53
+
54
+ namespace protobuf = ::google::protobuf;
55
+ using protobuf_int64 = int64_t;
56
+ using protobuf_uint64 = uint64_t;
57
+ extern const char* kProtobufInt64Typename;
58
+ extern const char* kProtobufUint64Typename;
59
+
60
+ // Parses a protocol buffer contained in a string in the binary wire format.
61
+ // Returns true on success. Note: Unlike protobuf's builtin ParseFromString,
62
+ // this function has no size restrictions on the total size of the encoded
63
+ // protocol buffer.
64
+ bool ParseProtoUnlimited(protobuf::MessageLite* proto,
65
+ const std::string& serialized);
66
+ bool ParseProtoUnlimited(protobuf::MessageLite* proto, const void* serialized,
67
+ size_t size);
68
+ inline bool ParseProtoUnlimited(protobuf::MessageLite* proto,
69
+ const tstring& serialized) {
70
+ return ParseProtoUnlimited(proto, serialized.data(), serialized.size());
71
+ }
72
+
73
+ // Returns the string value for the value of a string or bytes protobuf field.
74
+ inline const std::string& ProtobufStringToString(const std::string& s) {
75
+ return s;
76
+ }
77
+
78
+ // Set <dest> to <src>. Swapping is allowed, as <src> does not need to be
79
+ // preserved.
80
+ inline void SetProtobufStringSwapAllowed(std::string* src, std::string* dest) {
81
+ *dest = std::move(*src);
82
+ }
83
+
84
+ #if defined(TENSORFLOW_PROTOBUF_USES_CORD)
85
+ // These versions of ProtobufStringToString and SetProtobufString get used by
86
+ // tools/proto_text's generated code. They have the same name as the versions
87
+ // in tsl/platform/protobuf.h, so the generation code doesn't need to determine
88
+ // if the type is Cord or string at generation time.
89
+ inline std::string ProtobufStringToString(const absl::Cord& s) {
90
+ return std::string(s);
91
+ }
92
+ inline void SetProtobufStringSwapAllowed(std::string* src, absl::Cord* dest) {
93
+ dest->CopyFrom(*src);
94
+ }
95
+ #endif // defined(TENSORFLOW_PROTOBUF_USES_CORD)
96
+
97
+ inline bool SerializeToTString(const protobuf::MessageLite& proto,
98
+ tstring* output) {
99
+ size_t size = proto.ByteSizeLong();
100
+ output->resize_uninitialized(size);
101
+ return proto.SerializeWithCachedSizesToArray(
102
+ reinterpret_cast<uint8*>(output->data()));
103
+ }
104
+
105
+ inline bool ParseFromTString(const tstring& input,
106
+ protobuf::MessageLite* proto) {
107
+ return proto->ParseFromArray(input.data(), static_cast<int>(input.size()));
108
+ }
109
+
110
+ // Analogue to StringOutputStream for tstring.
111
+ class TStringOutputStream : public protobuf::io::ZeroCopyOutputStream {
112
+ public:
113
+ explicit TStringOutputStream(tstring* target);
114
+ ~TStringOutputStream() override = default;
115
+
116
+ TStringOutputStream(const TStringOutputStream&) = delete;
117
+ void operator=(const TStringOutputStream&) = delete;
118
+
119
+ bool Next(void** data, int* size) override;
120
+ void BackUp(int count) override;
121
+ int64_t ByteCount() const override;
122
+
123
+ private:
124
+ static constexpr int kMinimumSize = 16;
125
+
126
+ tstring* target_;
127
+ };
128
+ } // namespace tsl
129
+
130
+ #endif // TENSORFLOW_TSL_PLATFORM_PROTOBUF_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/ram_file_system.h ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2020 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_TSL_PLATFORM_RAM_FILE_SYSTEM_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_RAM_FILE_SYSTEM_H_
18
+
19
+ // Implementation of an in-memory TF filesystem for simple prototyping (e.g.
20
+ // via Colab). The TPU TF server does not have local filesystem access, which
21
+ // makes it difficult to provide Colab tutorials: users must have GCS access
22
+ // and sign-in in order to try out an example.
23
+ //
24
+ // Files are implemented on top of std::string. Directories, as with GCS or S3,
25
+ // are implicit based on the existence of child files. Multiple files may
26
+ // reference a single FS location, though no thread-safety guarantees are
27
+ // provided.
28
+
29
+ #include <string>
30
+
31
+ #include "absl/strings/match.h"
32
+ #include "tsl/platform/env.h"
33
+ #include "tsl/platform/file_system.h"
34
+ #include "tsl/platform/mutex.h"
35
+ #include "tsl/platform/stringpiece.h"
36
+ #include "tsl/platform/types.h"
37
+
38
+ #ifdef PLATFORM_WINDOWS
39
+ #undef DeleteFile
40
+ #undef CopyFile
41
+ #undef TranslateName
42
+ #endif
43
+
44
+ namespace tsl {
45
+
46
+ class RamRandomAccessFile : public RandomAccessFile, public WritableFile {
47
+ public:
48
+ RamRandomAccessFile(std::string name, std::shared_ptr<std::string> cord)
49
+ : name_(name), data_(cord) {}
50
+ ~RamRandomAccessFile() override {}
51
+
52
+ Status Name(StringPiece* result) const override {
53
+ *result = name_;
54
+ return OkStatus();
55
+ }
56
+
57
+ Status Read(uint64 offset, size_t n, StringPiece* result,
58
+ char* scratch) const override {
59
+ if (offset >= data_->size()) {
60
+ return errors::OutOfRange("");
61
+ }
62
+
63
+ uint64 left = std::min(static_cast<uint64>(n), data_->size() - offset);
64
+ auto start = data_->begin() + offset;
65
+ auto end = data_->begin() + offset + left;
66
+
67
+ std::copy(start, end, scratch);
68
+ *result = StringPiece(scratch, left);
69
+
70
+ // In case of a partial read, we must still fill `result`, but also return
71
+ // OutOfRange.
72
+ if (left < n) {
73
+ return errors::OutOfRange("");
74
+ }
75
+ return OkStatus();
76
+ }
77
+
78
+ Status Append(StringPiece data) override {
79
+ data_->append(data.data(), data.size());
80
+ return OkStatus();
81
+ }
82
+
83
+ #if defined(TF_CORD_SUPPORT)
84
+ Status Append(const absl::Cord& cord) override {
85
+ data_->append(cord.char_begin(), cord.char_end());
86
+ return OkStatus();
87
+ }
88
+ #endif
89
+
90
+ Status Close() override { return OkStatus(); }
91
+ Status Flush() override { return OkStatus(); }
92
+ Status Sync() override { return OkStatus(); }
93
+
94
+ Status Tell(int64_t* position) override {
95
+ *position = -1;
96
+ return errors::Unimplemented("This filesystem does not support Tell()");
97
+ }
98
+
99
+ private:
100
+ RamRandomAccessFile(const RamRandomAccessFile&) = delete;
101
+ void operator=(const RamRandomAccessFile&) = delete;
102
+ std::string name_;
103
+ std::shared_ptr<std::string> data_;
104
+ };
105
+
106
+ class RamFileSystem : public FileSystem {
107
+ public:
108
+ TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT;
109
+
110
+ Status NewRandomAccessFile(
111
+ const std::string& fname_, TransactionToken* token,
112
+ std::unique_ptr<RandomAccessFile>* result) override {
113
+ mutex_lock m(mu_);
114
+ auto fname = StripRamFsPrefix(fname_);
115
+
116
+ if (fs_.find(fname) == fs_.end()) {
117
+ return errors::NotFound("");
118
+ }
119
+ if (fs_[fname] == nullptr) {
120
+ return errors::InvalidArgument(fname_, " is a directory.");
121
+ }
122
+ *result = std::unique_ptr<RandomAccessFile>(
123
+ new RamRandomAccessFile(fname, fs_[fname]));
124
+ return OkStatus();
125
+ }
126
+
127
+ Status NewWritableFile(const std::string& fname_, TransactionToken* token,
128
+ std::unique_ptr<WritableFile>* result) override {
129
+ mutex_lock m(mu_);
130
+ auto fname = StripRamFsPrefix(fname_);
131
+
132
+ if (fs_.find(fname) == fs_.end()) {
133
+ fs_[fname] = std::make_shared<std::string>();
134
+ }
135
+ if (fs_[fname] == nullptr) {
136
+ return errors::InvalidArgument(fname_, " is a directory.");
137
+ }
138
+ *result = std::unique_ptr<WritableFile>(
139
+ new RamRandomAccessFile(fname, fs_[fname]));
140
+ return OkStatus();
141
+ }
142
+
143
+ Status NewAppendableFile(const std::string& fname_, TransactionToken* token,
144
+ std::unique_ptr<WritableFile>* result) override {
145
+ mutex_lock m(mu_);
146
+ auto fname = StripRamFsPrefix(fname_);
147
+
148
+ if (fs_.find(fname) == fs_.end()) {
149
+ fs_[fname] = std::make_shared<std::string>();
150
+ }
151
+ if (fs_[fname] == nullptr) {
152
+ return errors::InvalidArgument(fname_, " is a directory.");
153
+ }
154
+ *result = std::unique_ptr<WritableFile>(
155
+ new RamRandomAccessFile(fname, fs_[fname]));
156
+ return OkStatus();
157
+ }
158
+
159
+ Status NewReadOnlyMemoryRegionFromFile(
160
+ const std::string& fname, TransactionToken* token,
161
+ std::unique_ptr<ReadOnlyMemoryRegion>* result) override {
162
+ return errors::Unimplemented("");
163
+ }
164
+
165
+ Status FileExists(const std::string& fname_,
166
+ TransactionToken* token) override {
167
+ FileStatistics stat;
168
+ auto fname = StripRamFsPrefix(fname_);
169
+
170
+ return Stat(fname, token, &stat);
171
+ }
172
+
173
+ Status GetChildren(const std::string& dir_, TransactionToken* token,
174
+ std::vector<std::string>* result) override {
175
+ mutex_lock m(mu_);
176
+ auto dir = StripRamFsPrefix(dir_);
177
+
178
+ auto it = fs_.lower_bound(dir);
179
+ while (it != fs_.end() && StartsWith(it->first, dir)) {
180
+ auto filename = StripPrefix(StripPrefix(it->first, dir), "/");
181
+ // It is not either (a) the parent directory itself or (b) a subdirectory
182
+ if (!filename.empty() && filename.find("/") == std::string::npos) {
183
+ result->push_back(filename);
184
+ }
185
+ ++it;
186
+ }
187
+
188
+ return OkStatus();
189
+ }
190
+
191
+ Status GetMatchingPaths(const std::string& pattern_, TransactionToken* token,
192
+ std::vector<std::string>* results) override {
193
+ mutex_lock m(mu_);
194
+ auto pattern = StripRamFsPrefix(pattern_);
195
+
196
+ Env* env = Env::Default();
197
+ for (auto it = fs_.begin(); it != fs_.end(); ++it) {
198
+ if (env->MatchPath(it->first, pattern)) {
199
+ results->push_back("ram://" + it->first);
200
+ }
201
+ }
202
+ return OkStatus();
203
+ }
204
+
205
+ Status Stat(const std::string& fname_, TransactionToken* token,
206
+ FileStatistics* stat) override {
207
+ mutex_lock m(mu_);
208
+ auto fname = StripRamFsPrefix(fname_);
209
+
210
+ auto it = fs_.lower_bound(fname);
211
+ if (it == fs_.end() || !StartsWith(it->first, fname)) {
212
+ return errors::NotFound("");
213
+ }
214
+
215
+ if (it->first == fname && it->second != nullptr) {
216
+ stat->is_directory = false;
217
+ stat->length = fs_[fname]->size();
218
+ stat->mtime_nsec = 0;
219
+ return OkStatus();
220
+ }
221
+
222
+ stat->is_directory = true;
223
+ stat->length = 0;
224
+ stat->mtime_nsec = 0;
225
+ return OkStatus();
226
+ }
227
+
228
+ Status DeleteFile(const std::string& fname_,
229
+ TransactionToken* token) override {
230
+ mutex_lock m(mu_);
231
+ auto fname = StripRamFsPrefix(fname_);
232
+
233
+ if (fs_.find(fname) != fs_.end()) {
234
+ fs_.erase(fname);
235
+ return OkStatus();
236
+ }
237
+
238
+ return errors::NotFound("");
239
+ }
240
+
241
+ Status CreateDir(const std::string& dirname_,
242
+ TransactionToken* token) override {
243
+ mutex_lock m(mu_);
244
+ auto dirname = StripRamFsPrefix(dirname_);
245
+
246
+ auto it = fs_.find(dirname);
247
+ if (it != fs_.end() && it->second != nullptr) {
248
+ return errors::AlreadyExists(
249
+ "cannot create directory with same name as an existing file");
250
+ }
251
+
252
+ fs_[dirname] = nullptr;
253
+ return OkStatus();
254
+ }
255
+
256
+ Status RecursivelyCreateDir(const std::string& dirname_,
257
+ TransactionToken* token) override {
258
+ auto dirname = StripRamFsPrefix(dirname_);
259
+
260
+ std::vector<std::string> dirs = StrSplit(dirname, "/");
261
+ Status last_status;
262
+ std::string dir = dirs[0];
263
+ last_status = CreateDir(dir, token);
264
+
265
+ for (int i = 1; i < dirs.size(); ++i) {
266
+ dir = dir + "/" + dirs[i];
267
+ last_status = CreateDir(dir, token);
268
+ }
269
+ return last_status;
270
+ }
271
+
272
+ Status DeleteDir(const std::string& dirname_,
273
+ TransactionToken* token) override {
274
+ mutex_lock m(mu_);
275
+ auto dirname = StripRamFsPrefix(dirname_);
276
+
277
+ auto it = fs_.find(dirname);
278
+ if (it == fs_.end()) {
279
+ return errors::NotFound("");
280
+ }
281
+ if (it->second != nullptr) {
282
+ return errors::InvalidArgument("Not a directory");
283
+ }
284
+ fs_.erase(dirname);
285
+
286
+ return OkStatus();
287
+ }
288
+
289
+ Status GetFileSize(const std::string& fname_, TransactionToken* token,
290
+ uint64* file_size) override {
291
+ mutex_lock m(mu_);
292
+ auto fname = StripRamFsPrefix(fname_);
293
+
294
+ if (fs_.find(fname) != fs_.end()) {
295
+ if (fs_[fname] == nullptr) {
296
+ return errors::InvalidArgument("Not a file");
297
+ }
298
+ *file_size = fs_[fname]->size();
299
+ return OkStatus();
300
+ }
301
+ return errors::NotFound("");
302
+ }
303
+
304
+ Status RenameFile(const std::string& src_, const std::string& target_,
305
+ TransactionToken* token) override {
306
+ mutex_lock m(mu_);
307
+ auto src = StripRamFsPrefix(src_);
308
+ auto target = StripRamFsPrefix(target_);
309
+
310
+ if (fs_.find(src) != fs_.end()) {
311
+ fs_[target] = fs_[src];
312
+ fs_.erase(fs_.find(src));
313
+ return OkStatus();
314
+ }
315
+ return errors::NotFound("");
316
+ }
317
+
318
+ RamFileSystem() {}
319
+ ~RamFileSystem() override {}
320
+
321
+ private:
322
+ mutex mu_;
323
+ std::map<std::string, std::shared_ptr<std::string>> fs_;
324
+
325
+ std::vector<std::string> StrSplit(std::string s, std::string delim) {
326
+ std::vector<std::string> ret;
327
+ size_t curr_pos = 0;
328
+ while ((curr_pos = s.find(delim)) != std::string::npos) {
329
+ ret.push_back(s.substr(0, curr_pos));
330
+ s.erase(0, curr_pos + delim.size());
331
+ }
332
+ ret.push_back(s);
333
+ return ret;
334
+ }
335
+
336
+ bool StartsWith(std::string s, std::string prefix) {
337
+ return absl::StartsWith(s, prefix);
338
+ }
339
+
340
+ string StripPrefix(std::string s, std::string prefix) {
341
+ if (absl::StartsWith(s, prefix)) {
342
+ return s.erase(0, prefix.size());
343
+ }
344
+ return s;
345
+ }
346
+
347
+ string StripRamFsPrefix(std::string name) {
348
+ std::string s = StripPrefix(name, "ram://");
349
+ if (*(s.rbegin()) == '/') {
350
+ s.pop_back();
351
+ }
352
+ return s;
353
+ }
354
+ };
355
+
356
+ } // namespace tsl
357
+
358
+ #endif // TENSORFLOW_TSL_PLATFORM_RAM_FILE_SYSTEM_H_
videochat2/lib/python3.10/site-packages/tensorflow/include/tsl/platform/random.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2015 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_TSL_PLATFORM_RANDOM_H_
17
+ #define TENSORFLOW_TSL_PLATFORM_RANDOM_H_
18
+
19
+ #include "tsl/platform/types.h"
20
+
21
+ namespace tsl {
22
+ namespace random {
23
+
24
+ // Return a 64-bit random value. Different sequences are generated
25
+ // in different processes.
26
+ uint64 New64();
27
+
28
+ // Same as previous method, but uses a different RNG for each thread.
29
+ uint64 ThreadLocalNew64();
30
+
31
+ // Return a 64-bit random value. Uses
32
+ // std::mersenne_twister_engine::default_seed as seed value.
33
+ uint64 New64DefaultSeed();
34
+
35
+ } // namespace random
36
+ } // namespace tsl
37
+
38
+ #endif // TENSORFLOW_TSL_PLATFORM_RANDOM_H_