Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,6 @@ MigrationBackup/

# End of https://www.toptal.com/developers/gitignore/api/clion,visualstudio
/CMakeSettings.json

# Build directory
build/
11 changes: 7 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[submodule "third_parties/googletest"]
path = third_parties/googletest
url = https://github.com/google/googletest.git
[submodule "third_parties/fmt"]
path = third_parties/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "third_parties/mp11"]
path = third_parties/mp11
url = git@github.com:mis-wut/mp11.git
url = https://github.com/boostorg/mp11.git
[submodule "third_parties/CLI11"]
path = third_parties/CLI11
url = https://github.com/CLIUtils/CLI11.git
[submodule "third_parties/googletest"]
path = third_parties/googletest
url = https://github.com/google/googletest
46 changes: 21 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@ set(CMAKE_VERBOSE_MAKEFILE ON)

project(meta-json-parser VERSION 0.1 LANGUAGES CXX CUDA)

find_package(CUDAToolkit 10.0 REQUIRED)
# As of now not using LIBCUDF throws
set(USE_LIBCUDF 1)

IF(NOT LOCAL_LIB)
find_package(Boost 1.75) # version 1.75 is required to use boost::mp11::mp_pairwise_fold_q
ENDIF()
find_package(CUDAToolkit EXACT 11.8 REQUIRED)

IF(NOT Boost_FOUND)
add_subdirectory(third_parties/mp11)
add_library(Boost::boost ALIAS boost_mp11)
ENDIF()

IF(NOT LOCAL_LIB)
find_package(GTest REQUIRED CONFIG)
ENDIF()

IF(NOT GTest_FOUND)
add_subdirectory(third_parties/googletest)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gmock ALIAS gmock)
ENDIF()
# Add Boost MP11 library
add_subdirectory(third_parties/mp11)
add_library(Boost::boost ALIAS boost_mp11)

# Add GoogleTest
add_subdirectory(third_parties/googletest)
include(GoogleTest)

#Add FMT library (as CUDA11.8 doesn't support gcc12)
add_subdirectory(third_parties/fmt)

add_library(lib-meta-json-parser INTERFACE)

target_compile_features(lib-meta-json-parser INTERFACE cxx_std_17 cuda_std_17)
Expand Down Expand Up @@ -113,6 +106,7 @@ target_link_libraries(meta-cudf-parser-1 PUBLIC lib-meta-json-parser)

target_include_directories(meta-cudf-parser-1 PUBLIC
"${PROJECT_SOURCE_DIR}/meta_cudf/opt1"
"$ENV{CONDA_PREFIX}/include"
)
target_compile_options(meta-cudf-parser-1 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr> $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)

Expand All @@ -129,6 +123,8 @@ target_sources(meta-json-parser-test PRIVATE
test/cut.cu
test/keywriter_tests.cu
test/main.cu
test/round.cu
test/to_bool.cu
test/minmax.cu
test/parse_dynamic_string.cu
test/parse_jarray.cu
Expand Down Expand Up @@ -182,7 +178,7 @@ add_subdirectory(third_parties/CLI11)
#add_executable(meta-json-parser-benchmark benchmark/checkpoint_results.cpp benchmark/checkpoint_results.h)
add_executable(meta-json-parser-benchmark)

target_link_libraries(meta-json-parser-benchmark PRIVATE lib-meta-json-parser CLI11)
target_link_libraries(meta-json-parser-benchmark PRIVATE lib-meta-json-parser fmt::fmt CLI11)

# libcudf is an optional dependency for meta-json-parser-benchmark
# run cmake with -DUSE_LIBCUDF=1 to enable it
Expand All @@ -192,33 +188,33 @@ if (USE_LIBCUDF)
# instead of hardcoding paths to includes and to libraries, like below
target_include_directories(meta-cudf-parser-1 PUBLIC
/usr/local/include
/usr/local/include/libcudf/libcudacxx
)
target_include_directories(meta-cudf-parser-1 AFTER PUBLIC
/opt/conda/envs/rapids/include
$ENV{CONDA_PREFIX}/include
)
target_link_libraries(meta-cudf-parser-1 PRIVATE
cudf
-L/usr/local/cuda/lib64 -L/usr/local/lib
-L/opt/conda/envs/rapids/lib
-L$ENV{CONDA_PREFIX}/lib
)
target_compile_definitions(meta-cudf-parser-1 PRIVATE
HAVE_LIBCUDF=1
)

target_include_directories(meta-json-parser-benchmark PUBLIC
/usr/local/include
/usr/local/include/libcudf/libcudacxx
$ENV{CONDA_PREFIX}/include
)

# NOTE: needs to be added as the last directory to be checked, because
# it can contain outdated Boost library (which in Ubuntu 20.04 is Boost 1.72)
target_include_directories(meta-json-parser-benchmark AFTER PUBLIC
/opt/conda/envs/rapids/include
$ENV{CONDA_PREFIX}/include
)
target_link_libraries(meta-json-parser-benchmark PRIVATE
cudf
-L/usr/local/cuda/lib64 -L/usr/local/lib
-L/opt/conda/envs/rapids/lib
-L$ENV{CONDA_PREFIX}/lib
)
target_compile_definitions(meta-json-parser-benchmark PRIVATE
HAVE_LIBCUDF=1
Expand Down
25 changes: 25 additions & 0 deletions include/meta_json_parser/action/number_functors/round.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef META_JSON_PARSER_ROUND_CUH
#define META_JSON_PARSER_ROUND_CUH
#include <type_traits>
#include <cmath>
#include <cuda_runtime_api.h>

/**
* @tparam Dec represents number of decimal places kept (non-negative integer)
* @tparam NumT must be a floating point type
*/
template <intmax_t Dec, class NumT = float>
struct RoundFunctor {
using Num = NumT;
static_assert(std::is_floating_point<Num>::value, "NumT must be a floating point type.");
static_assert(Dec >= 0, "Cannot round to negative decimal places");

template <class NumberT> inline __device__ Num operator()(NumberT c) const {
Num val = static_cast<Num>(c);
Num div = static_cast<Num>(pow(10.0, Dec));
val = trunc(val*div)/div;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiply by a power of 10, truncate to the nearest integer to cut the remaining decimal places and divide to revert to the original value.

return val;
}
};

#endif //META_JSON_PARSER_ROUND_CUH
24 changes: 24 additions & 0 deletions include/meta_json_parser/action/number_functors/to_bool.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef META_JSON_PARSER_TO_BOOL_CUH
#define META_JSON_PARSER_TO_BOOL_CUH
#include <type_traits>
#include <cuda_runtime_api.h>

/**
* @tparam InT must be an arithmetic type
* @tparam OuT must be an integral type (default bool)
*/
template <class InT>
struct ToBoolFunctor {
using In = InT;

static_assert(std::is_arithmetic<In>::value, "InT must be an arithmetic type.");

constexpr static In Zero = static_cast<In>(0);

template <class NumberT> inline __device__ bool operator()(NumberT c) const {
In val = static_cast<In>(c);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple cast depending on the sign of the input value

return val > Zero;
}
};

#endif //META_JSON_PARSER_TO_BOOL_CUH
2 changes: 1 addition & 1 deletion include/meta_json_parser/debug_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void describe_table(cudf::io::table_with_metadata& table_with_metadata, bool dum
printf("table (with metadata) has %d columns\n", n_cols);
for (int col_idx = 0; col_idx < n_cols; col_idx++) {
printf("column(%d) name is \"%s\":\n", col_idx,
table_with_metadata.metadata.column_names[col_idx].c_str());
table_with_metadata.metadata.schema_info[col_idx].name.c_str());
describe_column(table.column(col_idx), dump_data);
}
}
Expand Down
1 change: 0 additions & 1 deletion include/meta_json_parser/parser_output_host.cuh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <cuda_runtime_api.h>
#include <thrust/host_vector.h>
#include <thrust/system/cuda/experimental/pinned_allocator.h>
#include <boost/mp11/list.hpp>
#include <fstream>
#include <meta_json_parser/config.h>
Expand Down
3 changes: 2 additions & 1 deletion meta_cudf/parser.cu
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ cudf::io::table_with_metadata generate_example_metadata(const char* filename, in
return "Column " + to_string(i++);
});

cudf::io::table_metadata metadata{column_names};
cudf::io::table_metadata metadata;
std::for_each(begin(column_names), end(column_names), [&](auto& elem){metadata.schema_info.push_back({elem});});

return cudf::io::table_with_metadata{
make_unique<cudf::table>(cudf_table),
Expand Down
52 changes: 52 additions & 0 deletions test/round.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <gtest/gtest.h>
#include <meta_json_parser/action/jrealnumber.cuh>
#include <meta_json_parser/action/number_functors/round.cuh>
#include "test_helper.h"
#include "test_configuration.h"
#include "test_utility/contexts/number_test_context.cuh"
#include "test_utility/test_launcher.cuh"

class RoundTest : public ::testing::Test { };

template <intmax_t Dec, class NumT>
class RoundTestContext : public NumberTestContext<NumT> {
using Base = NumberTestContext<NumT>;
using Calculation = typename Base::Calculation;
public:
RoundTestContext(size_t testSize, size_t groupSize, unsigned long seed)
: NumberTestContext<NumT>(testSize, groupSize, seed) { }

void InsertedNumberCallback(size_t index, Calculation value) override {
Calculation val = static_cast<Calculation>(value);
Calculation div = static_cast<Calculation>(pow(10.0, Dec));
val = trunc(val*div)/div;
(Base::m_h_correct)[index] = val;
}
};

template<class OutTypeT, intmax_t DecT, int GroupSizeT>
void templated_Round()
{
constexpr OutTypeT MinGenerate = -1000.0;
constexpr OutTypeT MaxGenerate = 1000.0;
using Functor = RoundFunctor<DecT, OutTypeT>;
RoundTestContext<DecT, typename Functor::Num> context(TEST_SIZE, GroupSizeT, SEED);
context.SetMinimumValue(MinGenerate);
context.SetMaximumValue(MaxGenerate);
context.Initialize();
using Options = boost::mp11::mp_list<
boost::mp11::mp_list<JRealNumberOptions::JRealNumberTransformer, Functor>
>;
using BA = JRealNumber<OutTypeT, void, Options>;
LaunchTest<BA, boost::mp11::mp_int<GroupSizeT>>(context);
}

#define META_ParseJRealNumberTests(WS)\
TEST_F(RoundTest, float_W##WS) {\
templated_Round<float, 1, WS>();\
}\
TEST_F(RoundTest, double_W##WS) {\
templated_Round<double, 1, WS>();\
}\

META_WS_4(META_ParseJRealNumberTests)
2 changes: 1 addition & 1 deletion test/test_utility/contexts/number_test_context.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public:
: TestContext(testSize, groupSize, seed),
m_min_val(std::numeric_limits<Generate>::min()),
m_max_val(std::numeric_limits<Generate>::max()),
m_max_precision(3) { }
m_max_precision(10) { }

void Initialize() override {
const auto maxLog = std::max(
Expand Down
47 changes: 47 additions & 0 deletions test/to_bool.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <gtest/gtest.h>
#include <meta_json_parser/action/jnumber.cuh>
#include <meta_json_parser/action/number_functors/to_bool.cuh>
#include "test_helper.h"
#include "test_configuration.h"
#include "test_utility/contexts/number_test_context.cuh"
#include "test_utility/test_launcher.cuh"

class ToBoolTest : public ::testing::Test { };

template <class InT>
class ToBoolTestContext : public NumberTestContext<InT> {
using Base = NumberTestContext<InT>;
using Calculation = typename Base::Calculation;
constexpr static InT Zero = static_cast<InT>(0);
public:
ToBoolTestContext(size_t testSize, size_t groupSize, unsigned long seed)
: NumberTestContext<InT>(testSize, groupSize, seed) { }

void InsertedNumberCallback(size_t index, Calculation value) override {
Calculation result = static_cast<Calculation>(value > Zero);
(Base::m_h_correct)[index] = result;
}
};

template<class OutTypeT, int GroupSizeT>
void templated_ToBool()
{
constexpr OutTypeT MinGenerate = -1000;
constexpr OutTypeT MaxGenerate = 1000;
using Functor = ToBoolFunctor<OutTypeT>;
ToBoolTestContext<typename Functor::In> context(TEST_SIZE, GroupSizeT, SEED);
context.SetMinimumValue(MinGenerate);
context.SetMaximumValue(MaxGenerate);
context.Initialize();
using Options = boost::mp11::mp_list<
boost::mp11::mp_list<JNumberOptions::JNumberTransformer, Functor>
>;
using BA = JNumber<OutTypeT, void, Options>;
LaunchTest<BA, boost::mp11::mp_int<GroupSizeT>>(context);
}

#define META_ParseJBooleanTests(WS)\
TEST_F(ToBoolTest, int32_W##WS) {\
templated_ToBool<int32_t, WS>();\
}\
META_WS_4(META_ParseJBooleanTests)
2 changes: 1 addition & 1 deletion third_parties/CLI11
Submodule CLI11 updated 162 files
1 change: 1 addition & 0 deletions third_parties/fmt
Submodule fmt added at 02cae7
2 changes: 1 addition & 1 deletion third_parties/googletest
Submodule googletest updated 245 files
2 changes: 1 addition & 1 deletion third_parties/mp11
Submodule mp11 updated from 19c1a9 to 773ec9