Repository navigation
Implement ptx_dispatch for if-target compatible target specialization - #521
alliepiper wants to merge 10 commits into
Conversation
c5ff0a7 to
d11e27e
Compare
d11e27e to
94be21e
Compare
94be21e to
662f869
Compare
|
I can see a lot of compilation errors when build with CTK 11.0, could you take a look? cub/cub/cmake/../../cub/device/dispatch/dispatch_scan.cuh:169:57: error: unused parameter ‘d_in’ [-Werror=unused-parameter]
169 | __global__ void DeviceScanKernel(InputIteratorT d_in,
| ~~~~~~~~~~~~~ ^
cub/cub/cmake/../../cub/device/dispatch/dispatch_scan.cuh:170:1: error: unused parameter ‘d_out’ [-Werror=unused-parameter]
169 | __global__ void DeviceScanKernel(InputIteratorT d_in,
|
170 | OutputIteratorT d_out,
| ^
cub/cub/cmake/../../cub/device/dispatch/dispatch_scan.cuh:171:1: error: unused parameter ‘tile_state’ [-Werror=unused-parameter]
170 | OutputIteratorT d_out,
| ~~~~~~~~~~~~~~~~~~~~~~
171 | ScanTileStateT tile_state,
| ^
cub/cub/cmake/../../cub/device/dispatch/dispatch_scan.cuh:172:1: error: unused parameter ‘start_tile’ [-Werror=unused-parameter]
171 | ScanTileStateT tile_state,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
172 | int start_tile,
| ^
cub/cmake/../../cub/device/dispatch/dispatch_scan.cuh:173:1: error: unused parameter ‘scan_op’ [-Werror=unused-parameter]
172 | int start_tile,
| ~~~~~~~~~~~~~~~
173 | ScanOpT scan_op,
| ^
cub/cub/cmake/../../cub/device/dispatch/dispatch_scan.cuh:174:1: error: unused parameter ‘init_value’ [-Werror=unused-parameter]
173 | ScanOpT scan_op,
| ~~~~~~~~~~~~~~~~
174 | InitValueT init_value,
| ^
cub/cub/cmake/../../cub/device/dispatch/dispatch_scan.cuh:175:1: error: unused parameter ‘num_items’ [-Werror=unused-parameter]
174 | InitValueT init_value,
| ~~~~~~~~~~~~~~~~~~~~~~
175 | OffsetT num_items)
| ^ |
gevtushenko
left a comment
There was a problem hiding this comment.
The code looks much better now, thanks! A few minor notes below:
| template <typename T> | ||
| struct type_wrapper | ||
| { | ||
| using type = T; |
There was a problem hiding this comment.
Policy might be a user defined type. This type wrapper implementation doesn't isolate from ADL:
#include <iostream>
namespace ns {
struct A{};
template <class T>
void foo(T&&) {
std::cout << "ns" << std::endl;
}
}
template <class T>
struct type_wrapper_1 {
using type = T;
};
template <class T>
struct type_wrapper_2_impl {
using type = struct t {
using type = T;
};
};
template <class T>
using type_wrapper_2 = typename type_wrapper_2_impl<T>::type;
template <class T>
struct library_type {
};
int main() {
using wrapped_type_1 = type_wrapper_1<ns::A>;
using wrapped_type_2 = type_wrapper_2<ns::A>;
library_type<wrapped_type_1> library_obj_1;
library_type<wrapped_type_2> library_obj_2;
foo(library_obj_1);
// foo(library_obj_2); // does isolate from ADL
} This might be worth it to reproduce @ericniebler implementation from the beginning.
There was a problem hiding this comment.
This isn't intended to interact with ADL, and ADL shouldn't be a concern in ptx_dispatch. type_wrapper just prevents PtxTypes from requiring default constructability.
There was a problem hiding this comment.
e.g. this way, the ptx_dispatch takes a functor that defines operator()(type_wrapper<T>) instead of operator()(T).
I've run into issues with similar dispatch mechanisms when using types that required ctor arguments.
There was a problem hiding this comment.
Is there anything blocking us from using the suggested implementation? Otherwise, we'd have to implement a second type wrapper at some point.
| @@ -3,9 +3,9 @@ enable_language(CUDA) | |||
| # | |||
| # Architecture options: | |||
There was a problem hiding this comment.
I'm not sure if this is related to this PR, but I bumped into the following issue when tested it:
57 - cub.cpp17.test.device_radix_sort.cdp_1.bytes_2.pairs_3 (SEGFAULT)
When I launched the test separately, there were no issue.
There was a problem hiding this comment.
I haven't seen this, and it hasn't popped up on CI. Still worrying though...
When this failed, were you running the tests in parallel (ctest -j XX)? Maybe there was a spurious OOM -> failed malloc -> nullptr -> segfault?
There was a problem hiding this comment.
I haven't run tests in parallel.
| #elif defined(NV_TARGET_SM_INTEGER_LIST) | ||
|
|
||
| // clang-format off | ||
| #define CUB_DETAIL_PTX_TARGETS_NAME1(P1) \ |
There was a problem hiding this comment.
optional: we might potentially abstract this pattern by providing suffix and separator parameters.
Ack. I had an ugly WAR for these, but ended up upstreaming the fix to nvcc (NVBug 2431416). You're right, though, we still need it for older CTK -- I'll put the WAR back in. |
1181cd6 to
6ce9b78
Compare
This can be used to restrict the number of kernel instantations until `__CUDA_ARCH_LIST__` is available.
127c7ad to
65e803f
Compare
65e803f to
0fe282e
Compare
0fe282e to
8ee124c
Compare
gevtushenko
left a comment
There was a problem hiding this comment.
I've built our tests to compare new codegen with the previous one. There's quite a difference there:
:wc -l asm_old/cub.cpp17.test.device_reduce.cdp_0.types_0.asm
3389546 asm_old/cub.cpp17.test.device_reduce.cdp_0.types_0.asm
:wc -l asm_new/cub.cpp17.test.device_reduce.cdp_0.types_0.asm
34674 asm_new/cub.cpp17.test.device_reduce.cdp_0.types_0.asmAm I missing something or there was some sort of a bug there? The build is for all supported architectures. Then:
for f in $(ls bin); do cuobjdump --dump-sass bin/$f > asm/$f.asm &; doneCould you take a look on your side?
| CUB_HOST_COMPILER == CUB_HOST_COMPILER_CLANG | ||
|
|
||
| // Clang honors GCC pragmas | ||
| #define CUB_KERNEL_BEGIN \ |
There was a problem hiding this comment.
Do you intend these macro set as a public API? Otherwise we'd have to name them as CUB_DETAIL_KERNEL_*. Also, if the issue was fixed in 11.4, I think there's a value in defining these macro only for CTK < 11.4.
miscco
left a comment
There was a problem hiding this comment.
So my knowledge about the dispatch mechanisms is limited, so everything here is with a grain of salt.
I believe the new implementation manages to be less eldritchy than the previous. one.
I am fine with not trying to do ADL isolation right now, as that adds quite a bit to compile times due to the additional instantiations required. It is only a problem when the target functions are overloaded, which might be a problem for copy(in, in , out) but I would wager we are fine here.
I am fine with being strict about the ordering and uniqueness of the archs, that is on our plate and we should take care there.
| #include <cub/thread/thread_search.cuh> | ||
| #include <cub/util_type.cuh> | ||
|
|
||
| #include <nv/target> |
There was a problem hiding this comment.
Is there a certain order this include must go in? Should we add <nv/ as another include block in the clang-format file?
| // clang-format off | ||
| NV_IF_TARGET(NV_PROVIDES_SM_52, | ||
| ( | ||
| auto a = wd_values + tile_start_coord.y + nonzero_idx; |
There was a problem hiding this comment.
Is there a reason we need those computations outside of the if?
and obligatory hiss at one letter variable names
| { | ||
| this->impl(exec_space_tag<ExecSpace>{}, | ||
| policy_wrapper, | ||
| std::forward<DeviceAlgorithmDispatch>(dispatch), |
There was a problem hiding this comment.
Should those be cuda::std::forward? Because I am not sure whether std::forward has __host__ __device__ on it
| * using FooList = cub::detail::type_list<Foo800, Foo600>; | ||
| * ``` | ||
| * | ||
| * \tparam PtxArch 3-digit PTX architecture version (e.g. 800 for Ampere) |
There was a problem hiding this comment.
That comment might become stale quickly should we drop the "3-digit"
| template <typename Functor, typename... Args> | ||
| __host__ __forceinline__ static void exec(int /* target_ptx_arch */, Functor &&, Args &&...) | ||
| { | ||
| // Didn't find a matching arch. |
There was a problem hiding this comment.
should there be an assert here or something?
|
|
||
| #include <cuda/std/type_traits> | ||
|
|
||
| #include <iterator> |
There was a problem hiding this comment.
Should that be
| #include <iterator> | |
| #include <cuda/std/iterator> |
| using policies_t = typename DispatchAlgorithm::Policies; | ||
|
|
||
| // The execution spaces supported by the invokable | ||
| // (ie. host/device/host_device). `runtime_exec_space` is `host_device` when |
There was a problem hiding this comment.
Could we move the second sentence to its own line
`CUB_RUNTIME_FUNCTION` will always include `__host__`, no need to specify it explicitly.
8ee124c to
685e87c
Compare
|
@allisonvacanti and I talked and we agreed to close this PR for now as this work has been de-prioritized. We will pick it back up if/when it becomes a priority again. |
No description provided.