/** * \file dnn/src/cuda/query_blocksize.cpp * MegEngine is Licensed under the Apache License, Version 2.0 (the "License") * * Copyright (c) 2014-2020 Megvii Inc. All rights reserved. * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include "./query_blocksize.cuh" #include "src/cuda/utils.h" #include #include using namespace megdnn; using namespace cuda; namespace { size_t hash_pair_combine(size_t x, size_t y) { return y + 0x9e3779b9 + (x << 6) + (x >> 2); } //! stupid committee has no pair hash. Let's do it for them struct pairhash { public: template size_t operator()(const std::pair& x) const { return hash_pair_combine(std::hash{}(x.first), std::hash{}(x.second)); } }; } // anonymous namespace LaunchConfig cuda::query_launch_config_for_kernel(const void* kern, const SmemGetter& smem) { static std::mutex mtx; static std::unordered_map, LaunchConfig, pairhash> cache; std::lock_guard _lock{mtx}; int device = -1; cuda_check(cudaGetDevice(&device)); auto ins = cache.insert({{device, kern}, LaunchConfig{}}); if (ins.second) { ins.first->second = detail::query_launch_config_for_kernel_uncached(kern, smem); } return ins.first->second; } // vim: ft=cpp syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}