| 312 | } |
| 313 | |
| 314 | TFE_Context* TFE_CreateContextFromSession(TF_Session* session, |
| 315 | TF_Status* status) { |
| 316 | auto* opts = TFE_NewContextOptions(); |
| 317 | |
| 318 | // Reduce GPU memory allocation, and set appropriate config options for TFE |
| 319 | // context. |
| 320 | auto* config = TF_CreateConfig( |
| 321 | /*xla*/ false, /* gpu_memory_allow_growth */ true, /* num_cpu_devices */ |
| 322 | 10); |
| 323 | TFE_ContextOptionsSetConfig(opts, config->data, config->length, status); |
| 324 | if (!status->status.ok()) { |
| 325 | CHECK(!config); |
| 326 | TFE_DeleteContextOptions(opts); |
| 327 | return nullptr; |
| 328 | } |
| 329 | |
| 330 | auto* ctx = TFE_NewContextFromSession(opts, session, status); |
| 331 | TF_DeleteBuffer(config); |
| 332 | TFE_DeleteContextOptions(opts); |
| 333 | return ctx; |
| 334 | } |
| 335 | |
| 336 | // TODO: retrieve the device string via TFE_ContextListDevices() |
| 337 | static const char DEFAULT_CPU_DEVICE[] = |
no test coverage detected