| 212 | } |
| 213 | |
| 214 | void CudaExecutable::FuncCache::exec( |
| 215 | const JITExecutor* fusion_opr, const CudaExecutable* cuda_exe) { |
| 216 | Func* func; |
| 217 | { |
| 218 | MGB_LOCK_GUARD(mtx); |
| 219 | auto ins = cn2func.insert({fusion_opr->comp_node(), {}}); |
| 220 | func = &ins.first->second; |
| 221 | if (ins.second) { |
| 222 | MGB_CUDA_CU_CHECK(cuModuleLoadData(&func->module, ptx.data())); |
| 223 | MGB_CUDA_CU_CHECK(cuModuleGetFunction( |
| 224 | &func->func, func->module, cuda_exe->m_name.c_str())); |
| 225 | int min_grid_size = 0; |
| 226 | MGB_CUDA_CU_CHECK(cuOccupancyMaxPotentialBlockSize( |
| 227 | &min_grid_size, &func->block_size, func->func, nullptr, 0, 0)); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | #pragma GCC diagnostic push |
| 232 | #pragma GCC diagnostic ignored "-Wunused-value" |
| 233 | int out_dim = fusion_opr->args().outputs[0].layout.ndim; |
| 234 | #define cb_outdim(EXPECTED_OUTDIM) \ |
| 235 | if (EXPECTED_OUTDIM == out_dim) { \ |
| 236 | setup_and_launch<EXPECTED_OUTDIM>(fusion_opr, func->func, func->block_size); \ |
| 237 | return; \ |
| 238 | } |
| 239 | #pragma GCC diagnostic push |
| 240 | cb_outdim(1); |
| 241 | cb_outdim(2); |
| 242 | cb_outdim(3); |
| 243 | cb_outdim(4); |
| 244 | mgb_throw(InternalError, "unsupported out_dim=%zu", static_cast<size_t>(out_dim)); |
| 245 | #undef cb_outdim |
| 246 | } |
| 247 | |
| 248 | CudaExecutable::~CudaExecutable() { |
| 249 | for (auto&& i : m_func_cache) { |