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

Adding kernel to add parse_uri support for protocol extraction #1502

Merged
2 changes: 2 additions & 0 deletions src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ add_library(
src/HashJni.cpp
src/MapUtilsJni.cpp
src/NativeParquetJni.cpp
src/ParseURIJni.cpp
src/RowConversionJni.cpp
src/SparkResourceAdaptorJni.cpp
src/ZOrderJni.cpp
Expand All @@ -167,6 +168,7 @@ add_library(
src/decimal_utils.cu
src/map_utils.cu
src/murmur_hash.cu
src/parse_uri.cu
src/row_conversion.cu
src/utilities.cu
src/xxhash64.cu
Expand Down
9 changes: 6 additions & 3 deletions src/main/cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@ target_compile_options(
)

target_link_libraries(
spark_rapids_jni_datagen PUBLIC cudf::cudf
spark_rapids_jni_datagen PUBLIC cudf::cudf
)

target_include_directories(
Expand Down Expand Up @@ -56,7 +56,7 @@ function(ConfigureBench CMAKE_BENCH_NAME)
CUDA_STANDARD_REQUIRED ON
)
target_link_libraries(${CMAKE_BENCH_NAME} nvbench::main spark_rapids_jni_datagen ${CUDF_BENCHMARK_COMMON}
cudf::cudf spark_rapids_jni Threads::Threads)
cudf::cudf spark_rapids_jni Threads::Threads cudf::cudftestutil)
install(
TARGETS ${CMAKE_BENCH_NAME}
COMPONENT testing
Expand All @@ -77,3 +77,6 @@ ConfigureBench(STRING_TO_FLOAT_BENCH

ConfigureBench(BLOOM_FILTER_BENCH
bloom_filter.cu)

ConfigureBench(PARSE_URI_BENCH
parse_uri.cpp)
145 changes: 145 additions & 0 deletions src/main/cpp/benchmarks/parse_uri.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright (c) 2023, 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.
*/

#include <parse_uri.hpp>

#include <benchmarks/common/generate_input.hpp>

#include <nvbench/nvbench.cuh>

#include <cudf/filling.hpp>
#include <cudf/strings/strings_column_view.hpp>
#include <cudf_test/column_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>

static void bench_random_parse_uri(nvbench::state& state)
{
cudf::size_type const n_rows{(cudf::size_type)state.get_int64("num_rows")};

auto const table = create_random_table({cudf::type_id::STRING}, row_count{n_rows});

state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
auto out =
spark_rapids_jni::parse_uri_to_protocol(cudf::strings_column_view{table->get_column(0)});
});

state.add_buffer_size(n_rows, "trc", "Total Rows");
}

static void bench_parse_uri(nvbench::state& state)
{
auto const n_rows = static_cast<cudf::size_type>(state.get_int64("num_rows"));
auto const hit_rate = static_cast<cudf::size_type>(state.get_int64("hit_rate"));

// build input table using the following data
auto raw_data =
cudf::test::strings_column_wrapper(
{
"https://www.google.com/s/"
"query?parameternumber0=0&parameternumber1=1&parameternumber2=2parameternumber2="
"2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2="
"2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2="
"2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2="
"2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2=2parameternumber2="
"2parameternumber2=2parameternumber2=2parameternumber2=2", // valid uri
"abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz "
"01234abcdefghijklmnopqrstuvwxyz 01234abcdefghijklmnopqrstuvwxyz 01234", // the rest are
// invalid
"",
"AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ "
"01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ "
"01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ "
"01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ "
"01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ "
"01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ "
"01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01AbcéDEFGHIJKLMNOPQRSTUVWXYZ 01",
"9876543210,abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU",
"9876543210,abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU9876543210,"
"abcdefghijklmnopqrstU9876543210,abcdefghijklmnopqrstU",
"123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 "
"édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf "
"4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf "
"4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf "
"4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf "
"4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf "
"4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf "
"4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5123 édf "
"4567890 DéFG 0987 X5123 édf 4567890 DéFG 0987 X5",
"1",
})
.release();

auto data_view = raw_data->view();

// compute number of rows in n_rows that should match
auto const matches = static_cast<cudf::size_type>(n_rows * hit_rate) / 100;

// Create a randomized gather-map to build a column out of the strings in data.
data_profile gather_profile =
data_profile_builder().cardinality(0).null_probability(0.0).distribution(
cudf::type_id::INT32, distribution_id::UNIFORM, 1, data_view.size() - 1);
auto gather_table =
create_random_table({cudf::type_id::INT32}, row_count{n_rows}, gather_profile);
gather_table->get_column(0).set_null_mask(rmm::device_buffer{}, 0);

// Create scatter map by placing 0-index values throughout the gather-map
auto scatter_data = cudf::sequence(
matches, cudf::numeric_scalar<int32_t>(0), cudf::numeric_scalar<int32_t>(n_rows / matches));
auto zero_scalar = cudf::numeric_scalar<int32_t>(0);
auto table = cudf::scatter({zero_scalar}, scatter_data->view(), gather_table->view());
auto gather_map = table->view().column(0);
table = cudf::gather(cudf::table_view({data_view}), gather_map);

state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) {
auto out =
spark_rapids_jni::parse_uri_to_protocol(cudf::strings_column_view{table->get_column(0)});
});

state.add_buffer_size(n_rows, "trc", "Total Rows");
}

NVBENCH_BENCH(bench_random_parse_uri)
.set_name("Strings")
.add_int64_axis("num_rows", {512 * 1024, 1 * 1024 * 1024});

NVBENCH_BENCH(bench_parse_uri)
.set_name("URIStringMix")
.add_int64_axis("num_rows", {512 * 1024, 1 * 1024 * 1024})
.add_int64_axis("hit_rate", {5, 50, 100});
36 changes: 36 additions & 0 deletions src/main/cpp/src/ParseURIJni.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023, 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.
*/

#include "cudf_jni_apis.hpp"
#include "dtype_utils.hpp"
#include "parse_uri.hpp"

extern "C" {

JNIEXPORT jlong JNICALL Java_com_nvidia_spark_rapids_jni_ParseURI_parseProtocol(JNIEnv* env,
jclass,
jlong input_column)
{
JNI_NULL_CHECK(env, input_column, "input column is null", 0);

try {
cudf::jni::auto_set_device(env);
auto const input = reinterpret_cast<cudf::column_view const*>(input_column);
return cudf::jni::ptr_as_jlong(spark_rapids_jni::parse_uri_to_protocol(*input).release());
}
CATCH_STD(env, 0);
}
}
Loading