Skip to content

Commit

Permalink
Add float to string kernel
Browse files Browse the repository at this point in the history
Signed-off-by: Haoyang Li <[email protected]>
  • Loading branch information
thirtiseven committed Oct 18, 2023
1 parent 6883988 commit cbce724
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/main/cpp/src/cast_float_to_string.cu
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ struct ftos_converter {
static constexpr unsigned int significant_digits = 17;
// maximum power-of-10 that will fit in 32-bits
// static constexpr unsigned long long nine_digits = 1000000000; // 1x10^9
static constexpr unsigned long long fifteen_digits = 1000000000000000;
// static constexpr unsigned long long fifteen_digits = 1000000000000000;
static constexpr unsigned long long sixteen_digits = 10000000000000000;
// Range of numbers here is for normalizing the value.
// If the value is above or below the following limits, the output is converted to
// scientific notation in order to show (at most) the number of significant digits.
static constexpr double upper_limit = 1000000000; // max is 1x10^9
static constexpr double lower_limit = 0.0001; // printf uses scientific notation below this
static constexpr double upper_limit = 10000000; // max is 1x10^7
static constexpr double lower_limit = 0.001; // printf uses scientific notation below this
// Tables for doing normalization: converting to exponent form
// IEEE double float has maximum exponent of 305 so these should cover everything
double const upper10[9] = {10, 100, 10000, 1e8, 1e16, 1e32, 1e64, 1e128, 1e256};
Expand Down Expand Up @@ -119,8 +119,16 @@ struct ftos_converter {
}
}
//
int decimal_places = significant_digits - (exp10? 2 : 1);
unsigned long long max_digits = (exp10? fifteen_digits : sixteen_digits);
// int decimal_places = significant_digits - (exp10? 2 : 1);
// unsigned long long max_digits = (exp10? fifteen_digits : sixteen_digits);
int decimal_places = significant_digits - 1;
unsigned long long max_digits = sixteen_digits;
double temp_value = value;
while (temp_value < 1.0 && temp_value > 0.0) {
max_digits *= 10;
temp_value *= 10.0;
decimal_places++;
}
integer = (unsigned int)value;
for (unsigned int i = integer; i >= 10; i /= 10) {
--decimal_places;
Expand Down Expand Up @@ -194,7 +202,7 @@ struct ftos_converter {
// decimal
*ptr++ = '.';
if (decimal_places) {
char buffer[17];
char buffer[18];
char* pb = buffer;
while (decimal_places--) {
*pb++ = (char)('0' + (decimal % 10));
Expand Down Expand Up @@ -232,7 +240,7 @@ struct ftos_converter {
value = -value;
bneg = true;
}
if (std::isinf(value)) return 3 + (int)bneg; // Inf
if (std::isinf(value)) return 8 + (int)bneg; // Inf

// dissect float into parts
unsigned int integer = 0;
Expand Down Expand Up @@ -261,7 +269,6 @@ struct ftos_converter {
count ++;
exp10 = -exp10;
}
count += (int)(exp10 < 10); // padding
while (exp10 > 0) {
exp10 /= 10;
++count;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/nvidia/spark/rapids/jni/CastStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ public static ColumnVector fromFloat(ColumnView cv) {
return new ColumnVector(fromFloat(cv.getNativeView()));
}

/**
* Convert a decimal column to a string column.
*
* @param cv the column data to process
* @return the converted column
*/
public static ColumnVector fromDecimal(ColumnView cv) {
return new ColumnVector(fromDecimal(cv.getNativeView()));
}

/**
* Convert a string column to a given floating-point type column.
*
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/cudf
Submodule cudf updated 52 files
+5 −13 cpp/cmake/thirdparty/get_arrow.cmake
+2 −2 cpp/cmake/thirdparty/get_cufile.cmake
+2 −2 cpp/cmake/thirdparty/get_gtest.cmake
+5 −7 cpp/cmake/thirdparty/get_kvikio.cmake
+10 −8 cpp/cmake/thirdparty/get_libcudacxx.cmake
+1 −3 cpp/cmake/thirdparty/get_spdlog.cmake
+8 −7 cpp/cmake/thirdparty/get_thrust.cmake
+9 −31 cpp/include/cudf/detail/normalizing_iterator.cuh
+1 −5 cpp/include/cudf/lists/extract.hpp
+0 −6 cpp/include/cudf/lists/filling.hpp
+0 −2 cpp/include/cudf/lists/gather.hpp
+1 −3 cpp/include/cudf/lists/reverse.hpp
+1 −4 cpp/include/cudf/lists/sorting.hpp
+1 −5 cpp/include/cudf/lists/stream_compaction.hpp
+14 −18 cpp/include/cudf/strings/convert/convert_booleans.hpp
+14 −20 cpp/include/cudf/strings/convert/convert_datetime.hpp
+11 −15 cpp/include/cudf/strings/convert/convert_durations.hpp
+12 −18 cpp/include/cudf/strings/convert/convert_fixed_point.hpp
+12 −18 cpp/include/cudf/strings/convert/convert_floats.hpp
+31 −45 cpp/include/cudf/strings/convert/convert_integers.hpp
+12 −18 cpp/include/cudf/strings/convert/convert_ipv4.hpp
+6 −8 cpp/include/cudf/strings/convert/convert_lists.hpp
+9 −13 cpp/include/cudf/strings/convert/convert_urls.hpp
+0 −24 cpp/include/cudf/utilities/traits.hpp
+2 −2 cpp/src/lists/copying/segmented_gather.cu
+2 −4 cpp/src/lists/extract.cu
+2 −4 cpp/src/lists/reverse.cu
+3 −4 cpp/src/lists/segmented_sort.cu
+2 −4 cpp/src/lists/sequences.cu
+1 −2 cpp/src/lists/stream_compaction/apply_boolean_mask.cu
+1 −2 cpp/src/lists/stream_compaction/distinct.cu
+9 −11 cpp/src/strings/convert/convert_booleans.cu
+3 −6 cpp/src/strings/convert/convert_datetime.cu
+9 −11 cpp/src/strings/convert/convert_durations.cu
+4 −7 cpp/src/strings/convert/convert_fixed_point.cu
+19 −23 cpp/src/strings/convert/convert_floats.cu
+19 −17 cpp/src/strings/convert/convert_hex.cu
+56 −46 cpp/src/strings/convert/convert_integers.cu
+18 −21 cpp/src/strings/convert/convert_ipv4.cu
+1 −2 cpp/src/strings/convert/convert_lists.cu
+4 −6 cpp/src/strings/convert/convert_urls.cu
+1 −1 cpp/src/text/edit_distance.cu
+1 −14 cpp/src/utilities/traits.cpp
+0 −1 cpp/tests/CMakeLists.txt
+0 −1 cpp/tests/groupby/histogram_tests.cpp
+0 −100 cpp/tests/iterator/indexalator_test.cu
+0 −81 cpp/tests/streams/lists_test.cpp
+0 −146 cpp/tests/streams/strings/convert_test.cpp
+6 −27 cpp/tests/strings/booleans_tests.cpp
+3 −6 cpp/tests/strings/format_lists_tests.cpp
+0 −26 cpp/tests/strings/integers_tests.cpp
+2 −9 java/src/main/native/src/ColumnViewJni.cpp

0 comments on commit cbce724

Please sign in to comment.