From f77445b54258998ea703cd7b9f90ca520d2cd32b Mon Sep 17 00:00:00 2001 From: Vukasin Milovanovic Date: Mon, 25 Feb 2019 14:24:06 -0800 Subject: [PATCH 1/4] Remove the extra byte added to chunks to acount for \r\n. The byte is not needed to correctly parse with this terminator. Fixes a segfault when map size alignes with a page. --- cpp/src/io/csv/csv_reader.cu | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/cpp/src/io/csv/csv_reader.cu b/cpp/src/io/csv/csv_reader.cu index 4fdeddd67d62..31f93b0a8688 100644 --- a/cpp/src/io/csv/csv_reader.cu +++ b/cpp/src/io/csv/csv_reader.cu @@ -432,10 +432,12 @@ gdf_error read_csv(csv_read_arg *args) if (raw_csv->byte_range_size != 0 && padded_byte_range_size < map_size) { // Need to make sure that w/ padding we don't overshoot the end of file map_size = min(padded_byte_range_size + calculateMaxRowSize(args->num_cols), map_size); - // Ignore page padding for parsing purposes - raw_csv->num_bytes = map_size - page_padding; + } + // Ignore page padding for parsing purposes + raw_csv->num_bytes = map_size - page_padding; + map_data = mmap(0, map_size, PROT_READ, MAP_PRIVATE, fd, map_offset); if (map_data == MAP_FAILED || map_size==0) { close(fd); checkError(GDF_C_ERROR, "Error mapping file"); } @@ -1185,17 +1187,11 @@ __global__ void countRecords(char *data, const char terminator, const char quote // process the data cu_reccnt_t tokenCount = 0; for (long x = 0; x < byteToProcess; x++) { - // Scan and log records. If quotations are enabled, then also log quotes // for a postprocess ignore, as the chunk here has limited visibility. if ((raw[x] == terminator) || (quotechar != '\0' && raw[x] == quotechar)) { tokenCount++; - } else if (terminator == '\n' && (x + 1L) < byteToProcess && - raw[x] == '\r' && raw[x + 1L] == '\n') { - x++; - tokenCount++; } - } atomicAdd(num_records, tokenCount); } @@ -1244,8 +1240,8 @@ gdf_error launch_storeRecordStart(const char *h_data, size_t h_size, // include_first_row should only apply to the first chunk const bool cu_include_first_row = (ci == 0) && (csvData->byte_range_offset == 0); - // Copy chunk to device. Copy extra byte if not last chunk - CUDA_TRY(cudaMemcpy(d_chunk, h_chunk, ci < (chunk_count - 1)?chunk_bytes:chunk_bytes + 1, cudaMemcpyDefault)); + // Copy chunk to device + CUDA_TRY(cudaMemcpy(d_chunk, h_chunk, chunk_bytes, cudaMemcpyDefault)); const int gridSize = (chunk_bits + blockSize - 1) / blockSize; storeRecordStart <<< gridSize, blockSize >>> ( @@ -1309,22 +1305,12 @@ __global__ void storeRecordStart(char *data, size_t chunk_offset, // process the data for (long x = 0; x < byteToProcess; x++) { - // Scan and log records. If quotations are enabled, then also log quotes // for a postprocess ignore, as the chunk here has limited visibility. if ((raw[x] == terminator) || (quotechar != '\0' && raw[x] == quotechar)) { - - const auto pos = atomicAdd(num_records, 1ull); - recStart[pos] = did + chunk_offset + x + 1; - - } else if (terminator == '\n' && (x + 1L) < byteToProcess && - raw[x] == '\r' && raw[x + 1L] == '\n') { - - x++; const auto pos = atomicAdd(num_records, 1ull); recStart[pos] = did + chunk_offset + x + 1; } - } } From 66a2d14c663cf45a733f82e6973f5d02a785074e Mon Sep 17 00:00:00 2001 From: Vukasin Milovanovic Date: Tue, 26 Feb 2019 09:57:42 -0800 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8700e033df..6d08c081256f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,7 @@ - PR #1001 CSV Reader: Fix a memory access error when reading a large (>2GB) file with date columns - PR #1019 Binary Ops: Fix error when one input column has null mask but other doesn't - PR #1014 CSV Reader: Fix false positives in bool value detection +- PR #1044 CSV Reader: Fix a segfault when byte range alings with a page # cuDF 0.5.1 (05 Feb 2019) From 817ec3596a2ec9047884aa07b8dcf79ba300b1f6 Mon Sep 17 00:00:00 2001 From: Vukasin Milovanovic Date: Tue, 26 Feb 2019 12:57:15 -0800 Subject: [PATCH 3/4] Add test for the page aligned byte_range use. --- python/cudf/tests/test_csvreader.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/cudf/tests/test_csvreader.py b/python/cudf/tests/test_csvreader.py index 9786e62e2f04..66a3f4abe317 100644 --- a/python/cudf/tests/test_csvreader.py +++ b/python/cudf/tests/test_csvreader.py @@ -903,3 +903,16 @@ def test_csv_reader_bools_false_positives(tmpdir): header=None, dtype=["int32"]) np.testing.assert_array_equal(items, df['0']) + + +def test_csv_reader_aligned_byte_range(tmpdir): + fname = tmpdir.mkdir("gdf_csv").join("tmp_csvreader_file19.csv") + nelem = 1000 + + input_df = pd.DataFrame({'key': np.arange(0, nelem), + 'zeros': np.zeros(nelem)}) + input_df.to_csv(fname) + + df = cudf.read_csv(str(fname), byte_range=(0, 4096)) + # read_csv call above used to crash; the assert below is not crucial + assert(np.count_nonzero(df['zeros']) == 0) From a8d2c328ad72040f1132e8c6d4817ce9f000ce12 Mon Sep 17 00:00:00 2001 From: Jaime Ieong <45218324+j-ieong@users.noreply.github.com> Date: Tue, 26 Feb 2019 15:09:06 -0800 Subject: [PATCH 4/4] Update CHANGELOG.md Co-Authored-By: vuule --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71a90b15f6b7..5c6c3e7b9852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,7 +95,7 @@ - PR #1019 Binary Ops: Fix error when one input column has null mask but other doesn't - PR #1014 CSV Reader: Fix false positives in bool value detection - PR #1034 CSV Reader: Fix parsing floating point precision and leading zero exponents -- PR #1044 CSV Reader: Fix a segfault when byte range alings with a page +- PR #1044 CSV Reader: Fix a segfault when byte range aligns with a page # cuDF 0.5.1 (05 Feb 2019)