-
Notifications
You must be signed in to change notification settings - Fork 58
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
Unify batch and stream API check #271
Changes from 1 commit
1febfb3
4dc2cee
1c65524
5358b35
28f6dee
aed889d
0bec44f
5e8c697
1c3eda9
10f7b0f
b57a6b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,31 +200,30 @@ int main() | |
cout << "stream : " << kvikio::is_stream_available() << endl; | ||
if (kvikio::is_stream_available()) { | ||
{ | ||
cout << "Performing stream I/O using file handle" << endl; | ||
off_t f_off = 0, d_off = 0; | ||
ssize_t bytes_done; | ||
CUstream stream; | ||
cout << "Performing async I/O using file handle" << endl; | ||
off_t f_off{0}; | ||
off_t d_off{0}; | ||
ssize_t bytes_done{0}; | ||
CUstream stream{}; | ||
check(cudaStreamCreate(&stream) == cudaSuccess); | ||
kvikio::FileHandle f_handle("/data/test-file", "w+", kvikio::FileHandle::m644, false); | ||
check(cudaMemcpy(a_dev, a, SIZE, cudaMemcpyHostToDevice) == cudaSuccess); | ||
|
||
/* | ||
* For stream based I/Os, buffer registration is not mandatory. However, | ||
* it gives a better performance. | ||
*/ | ||
|
||
kvikio::buffer_register(a_dev, SIZE); | ||
check(cudaMemcpyAsync(a_dev, a, SIZE, cudaMemcpyHostToDevice, stream) == cudaSuccess); | ||
f_handle.write_async(a_dev, &io_size, &f_off, &d_off, &bytes_done, stream); | ||
|
||
// After synchronizing `stream`, we can read the number of bytes written | ||
check(cudaStreamSynchronize(stream) == cudaSuccess); | ||
// Note, `bytes_done` might be negative, which indicate an IO error thus we | ||
// use `CUFILE_CHECK_STREAM_IO` to check for errors. | ||
CUFILE_CHECK_STREAM_IO(bytes_done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, this is a garbage error reporting api. |
||
check(bytes_done == SIZE); | ||
cout << "File stream Write : " << bytes_done << endl; | ||
kvikio::buffer_deregister(a_dev); | ||
cout << "File async write : " << bytes_done << endl; | ||
|
||
/* Read */ | ||
bytes_done = 0; | ||
kvikio::buffer_register(c_dev, SIZE); | ||
f_handle.read_async(c_dev, &io_size, &f_off, &d_off, &bytes_done, stream); | ||
check(cudaStreamSynchronize(stream) == cudaSuccess); | ||
CUFILE_CHECK_STREAM_IO(bytes_done); | ||
check(bytes_done == SIZE); | ||
cout << "File stream Read : " << bytes_done << endl; | ||
kvikio::buffer_deregister(c_dev); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ struct CUfileException : public std::runtime_error { | |
std::string(err_str) + ")"}; \ | ||
} \ | ||
} while (0) | ||
#define CUDA_DRIVER_TRY_1(_call) CUDA_DRIVER_TRY_2(_call, CUfileException) | ||
#define CUDA_DRIVER_TRY_1(_call) CUDA_DRIVER_TRY_2(_call, kvikio::CUfileException) | ||
#endif | ||
|
||
#ifdef KVIKIO_CUFILE_FOUND | ||
|
@@ -75,7 +75,27 @@ struct CUfileException : public std::runtime_error { | |
cufileop_status_error(error.err)}; \ | ||
} \ | ||
} while (0) | ||
#define CUFILE_TRY_1(_call) CUFILE_TRY_2(_call, CUfileException) | ||
#define CUFILE_TRY_1(_call) CUFILE_TRY_2(_call, kvikio::CUfileException) | ||
#endif | ||
#endif | ||
|
||
#ifdef KVIKIO_CUFILE_FOUND | ||
#ifndef CUFILE_CHECK_STREAM_IO | ||
#define CUFILE_CHECK_STREAM_IO(...) \ | ||
wence- marked this conversation as resolved.
Show resolved
Hide resolved
|
||
GET_CUFILE_CHECK_STREAM_IO_MACRO( \ | ||
__VA_ARGS__, CUFILE_CHECK_STREAM_IO_2, CUFILE_CHECK_STREAM_IO_1) \ | ||
(__VA_ARGS__) | ||
#define GET_CUFILE_CHECK_STREAM_IO_MACRO(_1, _2, NAME, ...) NAME | ||
#define CUFILE_CHECK_STREAM_IO_2(_nbytes_done, _exception_type) \ | ||
do { \ | ||
int const _nbytes = (_nbytes_done); \ | ||
if (_nbytes < 0) { \ | ||
throw(_exception_type){std::string{"cuFile error at: "} + __FILE__ + ":" + \ | ||
KVIKIO_STRINGIFY(__LINE__) + ": " + \ | ||
cufileop_status_error((CUfileOpError)(CUFILEOP_BASE_ERR - _nbytes))}; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the documentation says that this returns:
But this code suggests that it returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the docs are correct. I now just print the raw value of |
||
} \ | ||
} while (0) | ||
#define CUFILE_CHECK_STREAM_IO_1(_call) CUFILE_CHECK_STREAM_IO_2(_call, kvikio::CUfileException) | ||
#endif | ||
#endif | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is incorrect, per the documentation for
cuFileWriteAsync
:Which we are not doing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed