| 35 | } |
| 36 | |
| 37 | void Compile(XlaOpKernelContext* ctx) override { |
| 38 | // If 'frame' is non-null, this is a function call inside an outer JIT |
| 39 | // compilation. Use the usual implementation of _Arg. |
| 40 | auto frame = ctx->call_frame(); |
| 41 | if (frame != nullptr) { |
| 42 | Tensor val; |
| 43 | OP_REQUIRES_OK(ctx, frame->GetArg(index_, &val)); |
| 44 | // Types that cannot be copied using memcpy (like DT_STRING) are wrapped |
| 45 | // in a DT_UINT8 and hence the type mismatches. Skip the test in such |
| 46 | // cases. See XlaOpKernelContext::SetOutputExpression for details. |
| 47 | if (DataTypeCanUseMemcpy(dtype_)) { |
| 48 | OP_REQUIRES(ctx, val.dtype() == dtype_, |
| 49 | errors::InvalidArgument( |
| 50 | "Type mismatch: actual ", DataTypeString(val.dtype()), |
| 51 | " vs. expect ", DataTypeString(dtype_))); |
| 52 | } |
| 53 | // Forwards the argument from the frame. |
| 54 | ctx->op_kernel_context()->set_output(0, val); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | const XlaExpression& arg = ctx->xla_context()->args()[index_]; |
| 59 | OP_REQUIRES(ctx, arg.kind() != XlaExpression::Kind::kInvalid, |
| 60 | errors::InvalidArgument("Invalid/missing argument expression")); |
| 61 | if (ctx->expected_output_dtype(0) == DT_VARIANT) { |
| 62 | ctx->SetTensorListOutput(0, arg.handle()); |
| 63 | } else { |
| 64 | ctx->SetOutputExpression(0, arg); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | int index_; |
nothing calls this directly
no test coverage detected