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

Method Compute

tensorflow/compiler/xrt/kernels/xrt_compile_ops.cc:140–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140void XRTCompileOp::Compute(OpKernelContext* ctx) {
141 VLOG(1) << "XRTCompileOp::Compute";
142
143 ResourceMgr* rm;
144 OP_REQUIRES_OK(ctx, XRTGenericDeviceAccessor::GetResourceManager(ctx, &rm));
145
146 const Tensor& computation_input = ctx->input(0);
147 OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(computation_input.shape()),
148 errors::Internal("computation input should be a string scalar"));
149
150 xrt::XLAComputation computation_proto;
151 OP_REQUIRES(
152 ctx,
153 computation_proto.ParseFromString(computation_input.scalar<tstring>()()),
154 errors::InvalidArgument(
155 "Unable to parse computation input to XLAComputation"));
156
157 string key;
158 OP_REQUIRES_OK(ctx, CompilationCacheKey(computation_proto, &key));
159
160 // Process-wide cache of XLA executables.
161 XRTCompilationCache* cache;
162 OP_REQUIRES_OK(ctx,
163 rm->LookupOrCreate<XRTCompilationCache>(
164 rm->default_container(), kXRTCompilationCacheResourceName,
165 &cache, [](XRTCompilationCache** new_cache) {
166 *new_cache = new XRTCompilationCache(kDefaultCacheSize);
167 return Status::OK();
168 }));
169 core::ScopedUnref cache_unref(cache);
170
171 int64 uid;
172 OP_REQUIRES_OK(
173 ctx, cache->CompileIfKeyAbsent(
174 key, &uid, [&](std::unique_ptr<xla::LocalExecutable>* program) {
175 VLOG(1) << "Compiling XLA executable";
176 return Compile(ctx, computation_proto, program);
177 }));
178 std::unique_ptr<XRTCompilationCacheEntryRef> entry;
179 OP_REQUIRES_OK(ctx, cache->Lookup(uid, &entry));
180
181 Tensor handle_output(DT_INT64, TensorShape({}));
182 handle_output.scalar<int64>()() = uid;
183 ctx->set_output(0, handle_output);
184
185 xla::LocalExecutable* executable = entry->get().get_executable();
186 xla::ProgramShapeProto program_shape = executable->executable()
187 ->module()
188 .config()
189 .entry_computation_layout()
190 .ComputeProgramShape()
191 .ToProto();
192 Tensor program_shape_output(DT_STRING, TensorShape({1}));
193 program_shape_output.vec<tstring>()(0) = program_shape.SerializeAsString();
194 ctx->set_output(1, program_shape_output);
195}
196
197XRTCompileOp::~XRTCompileOp() = default;

Callers

nothing calls this directly

Calls 15

InternalFunction · 0.85
InvalidArgumentFunction · 0.85
CompileIfKeyAbsentMethod · 0.80
get_executableMethod · 0.80
CompilationCacheKeyFunction · 0.70
IsScalarFunction · 0.50
CompileFunction · 0.50
TensorShapeClass · 0.50
inputMethod · 0.45
shapeMethod · 0.45
ParseFromStringMethod · 0.45
LookupMethod · 0.45

Tested by

no test coverage detected