| 229 | } // namespace gpu |
| 230 | |
| 231 | void initialize_curand() { |
| 232 | port::Status status = |
| 233 | PluginRegistry::Instance()->RegisterFactory<PluginRegistry::RngFactory>( |
| 234 | cuda::kCudaPlatformId, gpu::kGpuRandPlugin, "cuRAND", |
| 235 | [](internal::StreamExecutorInterface* parent) -> rng::RngSupport* { |
| 236 | gpu::GpuExecutor* cuda_executor = |
| 237 | dynamic_cast<gpu::GpuExecutor*>(parent); |
| 238 | if (cuda_executor == nullptr) { |
| 239 | LOG(ERROR) |
| 240 | << "Attempting to initialize an instance of the cuRAND " |
| 241 | << "support library with a non-CUDA StreamExecutor"; |
| 242 | return nullptr; |
| 243 | } |
| 244 | |
| 245 | gpu::GpuRng* rng = new gpu::GpuRng(cuda_executor); |
| 246 | if (!rng->Init()) { |
| 247 | // Note: Init() will log a more specific error. |
| 248 | delete rng; |
| 249 | return nullptr; |
| 250 | } |
| 251 | return rng; |
| 252 | }); |
| 253 | |
| 254 | if (!status.ok()) { |
| 255 | LOG(ERROR) << "Unable to register cuRAND factory: " |
| 256 | << status.error_message(); |
| 257 | } |
| 258 | |
| 259 | PluginRegistry::Instance()->SetDefaultFactory( |
| 260 | cuda::kCudaPlatformId, PluginKind::kRng, gpu::kGpuRandPlugin); |
| 261 | } |
| 262 | |
| 263 | } // namespace stream_executor |
| 264 |
no test coverage detected