-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Support v3 cuda array interface. #6776
Merged
trivialfis
merged 7 commits into
dmlc:master
from
trivialfis:array-interface-cuda-stream
Mar 25, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca024b0
Sync stream.
trivialfis ab91df4
Check version.
trivialfis 335ba12
Add test.
trivialfis 457704a
Lint.
trivialfis 287503c
cpu build.
trivialfis 80f79dc
Avoid adding an attribute.
trivialfis f3fe1d9
Check.
trivialfis File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*! | ||
* Copyright 2021 by Contributors | ||
*/ | ||
#include "array_interface.h" | ||
#include "../common/common.h" | ||
|
||
namespace xgboost { | ||
void ArrayInterfaceHandler::SyncCudaStream(int64_t stream) { | ||
switch (stream) { | ||
case 0: | ||
LOG(FATAL) << "Invalid stream ID in array interface: " << stream; | ||
case 1: | ||
// default legacy stream | ||
break; | ||
case 2: | ||
// default per-thread stream | ||
default: | ||
dh::safe_cuda(cudaStreamSynchronize(reinterpret_cast<cudaStream_t>(stream))); | ||
} | ||
} | ||
} // namespace xgboost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*! | ||
* Copyright 2021 by Contributors | ||
*/ | ||
#include <gtest/gtest.h> | ||
#include <xgboost/host_device_vector.h> | ||
#include "../helpers.h" | ||
#include "../../../src/data/array_interface.h" | ||
|
||
namespace xgboost { | ||
|
||
__global__ void SleepForTest(uint64_t *out, uint64_t duration) { | ||
auto start = clock64(); | ||
auto t = 0; | ||
while (t < duration) { | ||
t = clock64() - start; | ||
} | ||
out[0] = t; | ||
} | ||
|
||
TEST(ArrayInterface, Stream) { | ||
size_t constexpr kRows = 10, kCols = 10; | ||
HostDeviceVector<float> storage; | ||
auto arr_str = RandomDataGenerator{kRows, kCols, 0}.GenerateArrayInterface(&storage); | ||
|
||
cudaStream_t stream; | ||
cudaStreamCreate(&stream); | ||
|
||
auto j_arr =Json::Load(StringView{arr_str}); | ||
j_arr["stream"] = Integer(reinterpret_cast<int64_t>(stream)); | ||
Json::Dump(j_arr, &arr_str); | ||
|
||
dh::caching_device_vector<uint64_t> out(1, 0); | ||
uint64_t dur = 1e9; | ||
dh::LaunchKernel{1, 1, 0, stream}(SleepForTest, out.data().get(), dur); | ||
ArrayInterface arr(arr_str); | ||
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. This is a nice test to test whether |
||
|
||
auto t = out[0]; | ||
CHECK_GE(t, dur); | ||
|
||
cudaStreamDestroy(stream); | ||
} | ||
} // namespace xgboost |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this a safe cast?
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.
When you start reinterpreting bits,it's hard to argue what's safe ..
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.
Is the stream a memory address, or is it something else, like a struct?
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.
It's an opaque pointer.
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.
Got it. Then casting it to an integer should be safe.