| 53 | } |
| 54 | |
| 55 | void VariableOp::Compute(OpKernelContext* ctx) { |
| 56 | mutex_lock l(init_mu_); |
| 57 | if (!initialized_) { |
| 58 | OP_REQUIRES_OK(ctx, cinfo_.Init(ctx->resource_manager(), def(), |
| 59 | true /* use name() */)); |
| 60 | initialized_ = true; |
| 61 | } |
| 62 | auto creator = [this](LegacyVar** var) { |
| 63 | *var = new LegacyVar(dtype_); |
| 64 | (*var)->tensor()->set_shape(shape_); |
| 65 | return Status::OK(); |
| 66 | }; |
| 67 | LegacyVar* var; |
| 68 | OP_REQUIRES_OK(ctx, cinfo_.resource_manager()->LookupOrCreate<LegacyVar>( |
| 69 | cinfo_.container(), cinfo_.name(), &var, creator)); |
| 70 | // Output a reference to our tensor, so it may be updated. |
| 71 | // |
| 72 | // As long as the resource manager hasn't been cleared the ref we return |
| 73 | // here is valid because it owns a ref on var. |
| 74 | ctx->set_output_ref(0, var->mu(), var->tensor()); |
| 75 | if (ctx->track_allocations() && var->tensor()->IsInitialized()) { |
| 76 | ctx->record_persistent_memory_allocation(var->tensor()->AllocatedBytes()); |
| 77 | } |
| 78 | var->Unref(); |
| 79 | } |
| 80 | |
| 81 | class TemporaryVariableOp : public OpKernel { |
| 82 | public: |
nothing calls this directly
no test coverage detected