| 27 | : Device(id, std::move(local_device_state), kCpuPlatformName) {} |
| 28 | |
| 29 | StatusOr<std::shared_ptr<PyLocalClient>> GetCpuClient(bool asynchronous) { |
| 30 | TF_ASSIGN_OR_RETURN(se::Platform * platform, |
| 31 | PlatformUtil::GetPlatform("Host")); |
| 32 | if (platform->VisibleDeviceCount() <= 0) { |
| 33 | return FailedPrecondition("CPU platform has no visible devices."); |
| 34 | } |
| 35 | LocalClientOptions options; |
| 36 | options.set_platform(platform); |
| 37 | TF_ASSIGN_OR_RETURN(LocalClient * client, |
| 38 | ClientLibrary::GetOrCreateLocalClient(options)); |
| 39 | |
| 40 | std::vector<std::shared_ptr<Device>> devices; |
| 41 | for (int i = 0; i < client->device_count(); ++i) { |
| 42 | se::StreamExecutor* executor = |
| 43 | client->backend().stream_executor(i).ValueOrDie(); |
| 44 | auto device_state = absl::make_unique<LocalDeviceState>( |
| 45 | executor, client, /*synchronous_deallocation=*/true, asynchronous, |
| 46 | /*allow_event_reuse=*/false); |
| 47 | std::shared_ptr<Device> device = |
| 48 | std::make_shared<CpuDevice>(i, std::move(device_state)); |
| 49 | devices.push_back(std::move(device)); |
| 50 | } |
| 51 | |
| 52 | return std::make_shared<PyLocalClient>( |
| 53 | kCpuPlatformName, client, std::move(devices), /*host_id=*/0, |
| 54 | /*allocator=*/nullptr, /*host_memory_allocator=*/nullptr); |
| 55 | } |
| 56 | |
| 57 | } // namespace xla |
nothing calls this directly
no test coverage detected