Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the Logical Stack algorithm #11078

Merged
merged 22 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7405aac
Squashed with initial test set
elstehle Mar 28, 2022
2fc22d0
style fix & additional test scenario
elstehle Mar 29, 2022
34df492
removed forceinline
elstehle Mar 29, 2022
4b5b917
tagging host device function
elstehle Mar 30, 2022
ac1e48c
Added utility to debug print & instrumented code to use it
elstehle Mar 31, 2022
053bb31
switched to using rmm also inside algorithm
elstehle Mar 31, 2022
6bbcd32
header include order & SFINAE macro
elstehle Mar 31, 2022
9af2138
debug print cleanups
elstehle Apr 4, 2022
1df7dcf
renaming key-value store op to stack_op
elstehle Apr 4, 2022
edb14e2
device_span
elstehle Apr 4, 2022
56f64cb
addressing review comments & minor cleanups
elstehle Apr 6, 2022
829ee1b
error on unsupported unsigned_t and fixed typos
elstehle Apr 7, 2022
5084974
minor style changes addressing review comments
elstehle Apr 13, 2022
8d98605
addresses review comments on print utils
elstehle Jun 8, 2022
f721b8c
addresses review comments on logical stack
elstehle Jun 8, 2022
461660b
adds empty line in doxygen after tparam
elstehle Jun 8, 2022
bd6fa96
addresses gh review comments
elstehle Jun 15, 2022
3d2ccea
Merge remote-tracking branch 'upstream/branch-22.08' into feature/log…
elstehle Jul 5, 2022
f5fb111
removes debug print and uses c++17 namespace style
elstehle Jul 5, 2022
583938c
Merge remote-tracking branch 'upstream/branch-22.08' into feature/log…
elstehle Jul 6, 2022
214deb3
Merge remote-tracking branch 'upstream/branch-22.08' into feature/log…
elstehle Jul 11, 2022
ac768b6
removes unused functions
elstehle Jul 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions cpp/include/cudf_test/print_utilities.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cudf/types.hpp>
#include <cudf/utilities/traits.hpp>

#include <rmm/cuda_stream_view.hpp>

#include <thrust/iterator/transform_iterator.h>

#include <type_traits>

namespace cudf {
namespace test {
namespace print {

constexpr int32_t hex_tag = 0;

template <int32_t TagT, typename T>
struct TaggedType {
T v;
};

template <typename T>
using hex_t = TaggedType<hex_tag, T>;

/**
* @brief Function object to transform a built-in type to a tagged type (e.g., in order to print
* values from an iterator returning uint32_t as hex values)
*
* @tparam TaggedTypeT A TaggedType template specialisation
*/
template <typename TaggedTypeT>
struct ToTaggedType {
template <typename T>
CUDF_HOST_DEVICE TaggedTypeT operator()(T const& v) const
{
return TaggedTypeT{v};
}
};

/**
* @brief Returns an iterator that causes the values from \p it to be printed as hex values.
*
* @tparam InItT A random-access input iterator type
* @param it A random-access input iterator t
* @return
*/
template <typename InItT>
auto hex(InItT it)
{
using value_t = typename std::iterator_traits<InItT>::value_type;
using tagged_t = hex_t<value_t>;
return thrust::make_transform_iterator(it, ToTaggedType<tagged_t>{});
}

template <typename T, CUDF_ENABLE_IF(std::is_integral_v<T>&& std::is_signed_v<T>)>
CUDF_HOST_DEVICE void print_value(int32_t width, T arg)
{
printf("%*d", width, arg);
}

template <typename T, CUDF_ENABLE_IF(std::is_integral_v<T>&& std::is_unsigned_v<T>)>
CUDF_HOST_DEVICE void print_value(int32_t width, T arg)
{
printf("%*d", width, arg);
}

CUDF_HOST_DEVICE void print_value(int32_t width, char arg) { printf("%*c", width, arg); }

template <typename T>
CUDF_HOST_DEVICE void print_value(int32_t width, hex_t<T> arg)
{
printf("%*X", width, arg.v);
}

namespace detail {
template <typename T>
CUDF_HOST_DEVICE void print_values(int32_t width, char delimiter, T arg)
{
print_value(width, arg);
}

template <typename T, typename... Ts>
CUDF_HOST_DEVICE void print_values(int32_t width, char delimiter, T arg, Ts... args)
{
print_value(width, arg);
if (delimiter) printf("%c", delimiter);
print_values(width, delimiter, args...);
}

template <typename... Ts>
__global__ void print_array_kernel(std::size_t count, int32_t width, char delimiter, Ts... args)
{
if (threadIdx.x == 0 && blockIdx.x == 0) {
for (std::size_t i = 0; i < count; i++) {
printf("%6lu: ", i);
print_values(width, delimiter, args[i]...);
printf("\n");
}
}
}
} // namespace detail

/**
* @brief Prints \p count elements from each of the given device-accessible iterators.
*
* @param count The number of items to print from each device-accessible iterator
* @param stream The cuda stream to which the printing kernel shall be dispatched
* @param args List of iterators to be printed
*/
template <typename... Ts>
void print_array(std::size_t count, rmm::cuda_stream_view stream, Ts... args)
{
// The width to pad printed numbers to
constexpr int32_t width = 6;

// Delimiter used for separating values from subsequent iterators
constexpr char delimiter = ',';

// TODO we want this to compile to nothing dependnig on compiler flag, rather than runtime
if (std::getenv("CUDA_DBG_DUMP") != nullptr) {
detail::print_array_kernel<<<1, 1, 0, stream.value()>>>(count, width, delimiter, args...);
}
}

} // namespace print
} // namespace test
} // namespace cudf
Loading