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 | #include "tensorflow/core/framework/op_kernel.h" |
17 | #include "tensorflow/core/platform/logging.h" |
18 | |
19 | namespace tensorflow { |
20 | |
21 | class FileSystemSetConfigurationOp : public OpKernel { |
22 | public: |
23 | explicit FileSystemSetConfigurationOp(OpKernelConstruction* context) |
24 | : OpKernel(context) { |
25 | env_ = context->env(); |
26 | } |
27 | |
28 | void Compute(OpKernelContext* context) override { |
29 | const Tensor* scheme_tensor; |
30 | OP_REQUIRES_OK(context, context->input("scheme" , &scheme_tensor)); |
31 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(scheme_tensor->shape()), |
32 | errors::InvalidArgument("scheme must be scalar, got shape " , |
33 | scheme_tensor->shape().DebugString())); |
34 | const string scheme = scheme_tensor->scalar<tstring>()(); |
35 | |
36 | const Tensor* key_tensor; |
37 | OP_REQUIRES_OK(context, context->input("key" , &key_tensor)); |
38 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(key_tensor->shape()), |
39 | errors::InvalidArgument("key must be scalar, got shape " , |
40 | key_tensor->shape().DebugString())); |
41 | const string key = key_tensor->scalar<tstring>()(); |
42 | |
43 | const Tensor* value_tensor; |
44 | OP_REQUIRES_OK(context, context->input("value" , &value_tensor)); |
45 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(value_tensor->shape()), |
46 | errors::InvalidArgument("value must be scalar, got shape " , |
47 | scheme_tensor->shape().DebugString())); |
48 | const string value = value_tensor->scalar<tstring>()(); |
49 | OP_REQUIRES_OK(context, env_->SetOption(scheme, key, value)); |
50 | } |
51 | |
52 | private: |
53 | Env* env_; |
54 | }; |
55 | REGISTER_KERNEL_BUILDER(Name("FileSystemSetConfiguration" ).Device(DEVICE_CPU), |
56 | FileSystemSetConfigurationOp); |
57 | |
58 | } // namespace tensorflow |
59 | |