| 119 | } |
| 120 | |
| 121 | Backend::Backend(se::Platform* platform, Compiler* compiler, |
| 122 | absl::Span<se::StreamExecutor* const> stream_executors, |
| 123 | TransferManager* transfer_manager, |
| 124 | ComputationPlacer* computation_placer, |
| 125 | int intra_op_parallelism_threads) |
| 126 | : platform_(platform), |
| 127 | compiler_(compiler), |
| 128 | transfer_manager_(transfer_manager), |
| 129 | computation_placer_(computation_placer), |
| 130 | stream_executors_(stream_executors.begin(), stream_executors.end()) { |
| 131 | // Create a memory allocator for the valid stream executors. |
| 132 | memory_allocator_ = std::make_shared<se::StreamExecutorMemoryAllocator>( |
| 133 | platform, stream_executors_); |
| 134 | CHECK(!stream_executors_.empty()) |
| 135 | << "Service found no devices for backend " << platform_->Name() << '.'; |
| 136 | |
| 137 | if (platform->id() == se::host::kHostPlatformId) { |
| 138 | const int num_threads = intra_op_parallelism_threads > 0 |
| 139 | ? intra_op_parallelism_threads |
| 140 | : tensorflow::port::MaxParallelism(); |
| 141 | intra_op_thread_pool_.reset(new IntraOpThreadPool(num_threads)); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | Backend::~Backend() { |
| 146 | CHECK_EQ(memory_allocator_.use_count(), 1); |