| 671 | } |
| 672 | |
| 673 | void Compiler::CompileCudaModule(const Module& module, |
| 674 | const std::string& code) { |
| 675 | #ifdef CINN_WITH_CUDA |
| 676 | auto _host_module_device_module_ = |
| 677 | SplitDeviceAndHostModule(module); // NOLINT |
| 678 | auto& host_module = std::get<0>(_host_module_device_module_); |
| 679 | auto& device_module = std::get<1>(_host_module_device_module_); |
| 680 | VLOG(3) << "[CUDA] host module:\n" << host_module; |
| 681 | |
| 682 | VLOG(3) << "[CUDA] device module:\n" << device_module; |
| 683 | std::string source_code; |
| 684 | |
| 685 | if (!FLAGS_cinn_debug_custom_code_path.empty()) { |
| 686 | std::string file_path = FLAGS_cinn_debug_custom_code_path; |
| 687 | source_code = GetFileContent(file_path); |
| 688 | } else if (code.empty()) { |
| 689 | CodeGenCudaDev codegen(target_); |
| 690 | source_code = codegen.Compile(device_module); |
| 691 | } else { |
| 692 | source_code = code; |
| 693 | } |
| 694 | |
| 695 | PADDLE_ENFORCE_EQ(!source_code.empty(), |
| 696 | true, |
| 697 | ::common::errors::InvalidArgument( |
| 698 | "Compile CUDA C code failed from device module")); |
| 699 | VLOG(3) << "[CUDA] C:\n" << source_code; |
| 700 | SourceCodePrint::GetInstance()->write(source_code); |
| 701 | device_fn_code_ += source_code; |
| 702 | |
| 703 | for (auto& fn : device_module.functions()) { |
| 704 | std::string kernel_fn_name = fn->name; |
| 705 | device_fn_name_.emplace_back(kernel_fn_name); |
| 706 | } |
| 707 | engine_->Link<CodeGenGpuHost>(host_module); |
| 708 | #else |
| 709 | CINN_NOT_IMPLEMENTED |
| 710 | #endif |
| 711 | } |
| 712 | |
| 713 | void Compiler::CompileCustomDeviceModule(const Module& module, |
| 714 | const std::string& code) { |
nothing calls this directly
no test coverage detected