Created
May 13, 2020 11:27
-
-
Save ganler/caa62d167eaadc9dfe1643134815664e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <type_traits> | |
| #include <utility> | |
| #include <iostream> | |
| #include <tuple> | |
| #include <array> | |
| using kDHCandidates = std::index_sequence<1, 2, 3>; | |
| using kKWCandidates = std::index_sequence<1, 3, 5, 7>; | |
| // 把REPLACE_ME删掉换成你的deep_conv即可 | |
| template <size_t A, size_t B, size_t C = 1, typename ... Args> | |
| void REPLACE_ME(Args&&...) { std::cout << A << ' ' << B << std::endl; } | |
| template <std::size_t L, size_t R, typename CUTuple, size_t...Is, typename ATuple, size_t...Js> | |
| void DoublePackInvoke(const CUTuple& cuargs, std::index_sequence<Is...>, const ATuple& args, std::index_sequence<Js...>) { | |
| // !!! 看这里!把线面改成 | |
| // YOUR_CUDA_FUNC<L, R, outNHWC><<<std::get<Is>(cuargs)...>>>(std::get<Js>(args)...); | |
| // 调用看main函数 | |
| REPLACE_ME<L, R>(std::get<Is>(cuargs)..., std::get<Js>(args)...); | |
| } | |
| template<std::size_t I=0, size_t J=0, size_t... Line, size_t... Column, typename ... Args, typename ... CUDArgs> | |
| inline std::enable_if_t<I == sizeof...(Line), void> | |
| ForEach1D( | |
| const std::index_sequence<Line...>&, const std::index_sequence<Column...>&, size_t l, size_t r, const std::tuple<Args...>&, const std::tuple<CUDArgs...>&) | |
| { } | |
| template<std::size_t I=0, size_t J=0, size_t... Line, size_t... Column, typename ... Args, typename ... CUDArgs> | |
| inline std::enable_if_t<I < sizeof...(Line), void> | |
| ForEach1D( | |
| const std::index_sequence<Line...>& line, const std::index_sequence<Column...>& column, size_t l, size_t r, const std::tuple<Args...>& args, const std::tuple<CUDArgs...>& cudargs) | |
| { | |
| constexpr size_t L = std::get<I>(std::make_tuple(Line...)); | |
| constexpr size_t R = std::get<J>(std::make_tuple(Column...)); | |
| if (l == L && r == R) | |
| DoublePackInvoke<L, R>( | |
| cudargs, | |
| std::make_index_sequence<sizeof...(CUDArgs)>{}, | |
| args, | |
| std::make_index_sequence<sizeof...(Args)>{}); | |
| ForEach1D<I+1, J>(line, column, l, r, args, cudargs); | |
| } | |
| template<std::size_t I=0, size_t J=0, size_t... Line, size_t... Column, typename ... Args, typename ... CUDArgs> | |
| inline std::enable_if_t<J == sizeof...(Column), void> | |
| ForEach2D( | |
| const std::index_sequence<Line...>&, const std::index_sequence<Column...>&, size_t l, size_t r, const std::tuple<Args...>& args, const std::tuple<CUDArgs...>& cudargs) | |
| { } | |
| template<std::size_t I=0, size_t J=0, size_t... Line, size_t... Column, typename ... Args, typename ... CUDArgs> | |
| inline std::enable_if_t<J < sizeof...(Column), void> | |
| ForEach2D( | |
| const std::index_sequence<Line...>& line, const std::index_sequence<Column...>& column, size_t l, size_t r, const std::tuple<Args...>& args, const std::tuple<CUDArgs...>& cudargs) | |
| { | |
| ForEach1D<I, J>(line, column, l, r, args, cudargs); | |
| ForEach2D<I, J+1>(line, column, l, r, args, cudargs); | |
| } | |
| template <size_t ... Ls, size_t ... Rs, typename ... Args, typename ... CUDArgs> | |
| void StaticDispatcher( | |
| std::index_sequence<Ls...>, std::index_sequence<Rs...>, size_t l, size_t r, const std::tuple<Args...>& args, const std::tuple<CUDArgs...>& cudargs) { | |
| ForEach2D(kDHCandidates{}, kKWCandidates{}, l, r, args, cudargs); | |
| } | |
| int main() { | |
| size_t i, j; | |
| std::cin >> i >> j; | |
| StaticDispatcher(kDHCandidates{}, kKWCandidates{}, i, j, std::make_tuple(1, 2, 3), std::make_tuple(1, 2, 3)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment