MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compile

Method Compile

tensorflow/compiler/jit/xla_compile_on_demand_op.cc:113–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113Status XlaCompileOnDemandOp::Compile(
114 OpKernelContext* ctx, const XlaDevice::Metadata& metadata,
115 const XlaCompiler::CompilationResult** result,
116 xla::LocalExecutable** executable) {
117 std::map<int, Tensor> constant_arguments;
118 for (int64 i = 0; i < ctx->num_inputs(); ++i) {
119 const Tensor& device_tensor = ctx->input(i);
120 if (const XlaTensor* xla_tensor = XlaTensor::FromTensor(&device_tensor)) {
121 if (xla_tensor->has_host_tensor()) {
122 bool should_arg_be_const;
123 TF_RETURN_IF_ERROR(ShouldArgumentBeConstant(&ctx->op_kernel(), i,
124 ctx->function_library(),
125 &should_arg_be_const));
126 if (should_arg_be_const) {
127 constant_arguments[i] = xla_tensor->host_tensor();
128 }
129 }
130 }
131
132 if (constant_arguments.count(i) == 0) {
133 bool must_argument_be_const;
134 TF_RETURN_IF_ERROR(MustArgumentBeConstant(&ctx->op_kernel(), i,
135 ctx->function_library(),
136 &must_argument_be_const));
137
138 if (must_argument_be_const) {
139 // Slow path; the argument is not available as a host constant so we
140 // must fetch it synchronously.
141 Tensor host_tensor;
142 AllocatorAttributes attrs;
143 attrs.set_on_host(true);
144 TF_RETURN_IF_ERROR(ctx->allocate_temp(
145 device_tensor.dtype(), device_tensor.shape(), &host_tensor, attrs));
146 Notification n;
147 Status status;
148 ctx->op_device_context()->CopyDeviceTensorToCPU(
149 &device_tensor, "ConstantArgument",
150 reinterpret_cast<Device*>(ctx->device()), &host_tensor,
151 [&](Status s) {
152 status = s;
153 n.Notify();
154 });
155 n.WaitForNotification();
156 if (!status.ok()) {
157 LOG(ERROR) << "Copying tensor of shape "
158 << device_tensor.shape().DebugString() << " from "
159 << ctx->device()->name() << "to CPU failed with "
160 << status.ToString();
161 return status;
162 }
163 constant_arguments[i] = host_tensor;
164 }
165 }
166 }
167
168 // We store information about the JIT-compiled XLA computation
169 // in the ResourceMgr.
170 ResourceMgr* rm = ctx->resource_manager();

Callers

nothing calls this directly

Calls 15

GetVariablesFunction · 0.85
has_host_tensorMethod · 0.80
set_on_hostMethod · 0.80
nameMethod · 0.65
num_inputsMethod · 0.45
inputMethod · 0.45
function_libraryMethod · 0.45
countMethod · 0.45
allocate_tempMethod · 0.45
dtypeMethod · 0.45
shapeMethod · 0.45
CopyDeviceTensorToCPUMethod · 0.45

Tested by

no test coverage detected