| 231 | } |
| 232 | |
| 233 | port::Status GpuExecutor::GetKernel(const MultiKernelLoaderSpec& spec, |
| 234 | KernelBase* kernel) { |
| 235 | GpuKernel* rocm_kernel = AsGpuKernel(kernel); |
| 236 | hipModule_t module = nullptr; |
| 237 | const string* kernelname; |
| 238 | |
| 239 | const OnDiskKernelLoaderSpec* on_disk_spec = nullptr; |
| 240 | bool has_cubin = spec.has_cuda_cubin_on_disk(); |
| 241 | if (has_cubin) { |
| 242 | on_disk_spec = &spec.cuda_cubin_on_disk(); |
| 243 | } |
| 244 | |
| 245 | if (on_disk_spec != nullptr) { |
| 246 | return port::InternalError( |
| 247 | "Loading ROCM kernel from disk is not supported"); |
| 248 | } else if (spec.has_cuda_cubin_in_memory()) { |
| 249 | kernelname = &spec.cuda_cubin_in_memory().kernelname(); |
| 250 | |
| 251 | const char* hsaco = spec.cuda_cubin_in_memory().bytes(); |
| 252 | absl::MutexLock lock{&in_memory_modules_mu_}; |
| 253 | module = in_memory_modules_[hsaco]; |
| 254 | |
| 255 | if (module == nullptr) { |
| 256 | if (!GpuDriver::LoadHsaco(context_, hsaco, &module)) { |
| 257 | return port::InternalError("Failed to load HSACO"); |
| 258 | } |
| 259 | } |
| 260 | kernel_to_gpu_binary_[kernel] = hsaco; |
| 261 | } else { |
| 262 | return port::InternalError("No method of loading ROCM kernel provided"); |
| 263 | } |
| 264 | |
| 265 | VLOG(2) << "getting function " << *kernelname << " from module " << module; |
| 266 | if (!GpuDriver::GetModuleFunction(context_, module, kernelname->c_str(), |
| 267 | rocm_kernel->gpu_function_ptr())) { |
| 268 | return port::InternalError("Failed getting module function"); |
| 269 | } |
| 270 | |
| 271 | // We have to trust the kernel loader spec arity because there doesn't appear |
| 272 | // to be a way to reflect on the number of expected arguments w/the ROCM API. |
| 273 | rocm_kernel->set_arity(spec.arity()); |
| 274 | |
| 275 | KernelMetadata kernel_metadata; |
| 276 | if (!GetKernelMetadata(rocm_kernel, &kernel_metadata)) { |
| 277 | LOG(WARNING) << "Unable to get metadata for kernel " << kernelname; |
| 278 | } |
| 279 | kernel->set_metadata(kernel_metadata); |
| 280 | kernel->set_name(*kernelname); |
| 281 | return port::Status::OK(); |
| 282 | } |
| 283 | |
| 284 | bool GpuExecutor::GetKernelMetadata(GpuKernel* rocm_kernel, |
| 285 | KernelMetadata* kernel_metadata) { |
nothing calls this directly
no test coverage detected