Live data from Hacker News

Show HN: Parsing CSV files with GPU

github.com

21–30 of 63 posts

Re: Show HN: Parsing CSV files with GPU

#21
post #18

In the real world... read the CSV into a database (doesn't really matter how fast or slow it is). Access the data from the database.

In the real world, sometimes you have an external data source, in csv (which you can't control), which is changing, which you want to reread as quickly as possible. :)

Re: Show HN: Parsing CSV files with GPU

#22

I'm skeptical of the 8x speedup for several reasons, the main one being that this particular problem does not fit the paradigm of problems that work well on the GPU; the GPU cache is not used at all, and there are also many branches. You need to be able to use the cache of the GPU in your application, otherwise your performance is guaranteed to be memory-bound. The reason you want to avoid branches is that there is o…

> Generally the only code that maps well to the GPU is that which contains large for loops and has good spacial locality (e.g. matrix multiplication). You also need high arithmetic intensity (the ratio of arithmetic/logical operations to memory loads). Of common CPU-bound tasks, CSV parsing has one of the lowest arithmetic intensities imaginable.

Right, maybe I should have said that instead. In my mind locality implies arithmetic intensity, but intensity may not necessarily imply locality.

Re: Show HN: Parsing CSV files with GPU

#23
post #18

In the real world... read the CSV into a database (doesn't really matter how fast or slow it is). Access the data from the database.

There are situations where CSV is the appropriate solution. Our applications read and write CSV data at 1-1.5 million cells per second, and the process can be scaled out at will (there is no central data server, all data is stored on Azure Blob Storage).

I'm not sure we could afford the skills and software to achieve these speeds with SQL.

Re: Show HN: Parsing CSV files with GPU

#24

For file sizes where parsing speed really makes a difference, loading the entire file into memory doesn't seem feasible. Maybe some sort of a hybrid approach (load chunks into memory and parse them via the GPU) would provide some real benefits though.

In a REPL environment, for a 1GB file, this can be the difference between "wait three seconds" and "let me get my coffee".

Re: Show HN: Parsing CSV files with GPU

#25
Very interesting. From my experience, the hard part about parsing CSV isn't to identify the individual cells, but rather parsing those cells afterwards (as numbers, dates, etc).

What is the performance of those operations (e.g. parsing YYYY-MM-DD dates to Unix timestamps) when performed on the GPU ?

My company actually picked another optimization strategy, by making the tokenization significantly longer, but it de-duplicates the tokenized cells so that each distinct cell value (a date, a number, a string) can be parsed exactly once. We have seen some fairly good results out of this, compared to the naive approach of stream-token-parse:

https://github.com/Lokad/lokad-flatfiles

Re: Show HN: Parsing CSV files with GPU

#26

For file sizes where parsing speed really makes a difference, loading the entire file into memory doesn't seem feasible. Maybe some sort of a hybrid approach (load chunks into memory and parse them via the GPU) would provide some real benefits though.

And if you're going to load it, you may as well parse it on the way in.

Re: Show HN: Parsing CSV files with GPU

#27
post #26

For file sizes where parsing speed really makes a difference, loading the entire file into memory doesn't seem feasible. Maybe some sort of a hybrid approach (load chunks into memory and parse them via the GPU) would provide some real benefits though.

And if you're going to load it, you may as well parse it on the way in.

A streaming CSV parser is very difficult to get right, once you get past a certain level of complexity.

Sometimes, you are not lucky enough to have perfect control over the encoding, number format and date format of the input, so you need to look ahead at a value sample to try and find out what those are.

Sometimes, you cannot even assume that the software that produced the file didn't mangle the quotes around fields, and you have to detect that you are 40960 bytes into a quoted field, decide that it's probably an error, and backtrack.

If you have enough memory to load the entire file, you will save a lot of time by giving up on streaming processing.

Re: Show HN: Parsing CSV files with GPU

#29
Though there is no standard definition of CSV, de facto processing it properly requires recognizing quotes, and also escapes of literal quotes using double quoting:

    this, "is, like, CSV", "with three so-called ""fields"""
Note that unquoted leading and trailing whitespace, and whitespace around the commas, is deleted, too.

(See CSV page in the Wikipedia)

A GPU-accelerated string split could be useful but it's not quite "parsing CSV".

Re: Show HN: Parsing CSV files with GPU

#30

Though there is no standard definition of CSV, de facto processing it properly requires recognizing quotes, and also escapes of literal quotes using double quoting: this, "is, like, CSV", "with three so-called ""fields""" Note that unquoted leading and trailing whitespace, and whitespace around the commas, is deleted, too. (See CSV page in the Wikipedia) A GPU-accelerated string split could be useful but it's not qui…

You forgot with fields with line-breaks, with non printrable characters and so on.
Post reply on HN