Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
00c29307
Commit
00c29307
authored
Sep 24, 2015
by
Dan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved comments.
parent
23fc5930
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
main.cu
samples/cpp/tutorial_code/gpu/gpu-thrust-interop/main.cu
+16
-10
No files found.
samples/cpp/tutorial_code/gpu/gpu-thrust-interop/main.cu
View file @
00c29307
...
...
@@ -45,19 +45,21 @@ int main(void)
// generated value. Sort by the randomly generated value while maintaining index association.
//! [sort]
{
cv::cuda::GpuMat d_
idx
(1, 100, CV_32SC2);
auto keyBegin = GpuMatBeginItr<int>(d_
idx
, 1);
auto keyEnd = GpuMatEndItr<int>(d_
idx
, 1);
auto idxBegin = GpuMatBeginItr<int>(d_
idx
, 0);
auto idxEnd = GpuMatEndItr<int>(d_
idx
, 0);
cv::cuda::GpuMat d_
data
(1, 100, CV_32SC2);
// Thrust compatible begin and end iterators to channel 1 of this matrix
auto keyBegin = GpuMatBeginItr<int>(d_
data
, 1);
auto keyEnd = GpuMatEndItr<int>(d_
data
, 1);
// Thrust compatible begin and end iterators to channel 0 of this matrix
auto idxBegin = GpuMatBeginItr<int>(d_
data
, 0);
auto idxEnd = GpuMatEndItr<int>(d_
data
, 0);
// Fill the index channel with a sequence of numbers from 0 to 100
thrust::sequence(idxBegin, idxEnd);
thrust::transform(idxBegin, idxEnd, keyBegin, prg(0, 10));
// Fill the key channel with random numbers between 0 and 10. A counting iterator is used here to give an integer value for each location as an input to prg::operator()
thrust::transform(thrust::make_counting_iterator(0), thrust::make_counting_iterator(d_data.cols), keyBegin, prg(0, 10));
// Sort the key channel and index channel such that the keys and indecies stay together
thrust::sort_by_key(keyBegin, keyEnd, idxBegin);
cv::Mat h_idx(d_
idx
);
cv::Mat h_idx(d_
data
);
}
//! [sort]
...
...
@@ -92,10 +94,14 @@ int main(void)
auto valueEnd = GpuMatEndItr<float>(d_value);
cv::cuda::Stream stream;
//! [random_gen_stream]
// Same as the random generation code from before except now the transformation is being performed on a stream
thrust::transform(thrust::system::cuda::par.on(cv::cuda::StreamAccessor::getStream(stream)), thrust::make_counting_iterator(0), thrust::make_counting_iterator(d_value.cols), valueBegin, prg(-1, 1));
//! [random_gen_stream]
// Count the number of values we are going to copy
int count = thrust::count_if(thrust::system::cuda::par.on(cv::cuda::StreamAccessor::getStream(stream)), valueBegin, valueEnd, pred_greater<float>(0.0));
// Allocate a destination for copied values
cv::cuda::GpuMat d_valueGreater(1, count, CV_32F);
// Copy values that satisfy the predicate.
thrust::copy_if(thrust::system::cuda::par.on(cv::cuda::StreamAccessor::getStream(stream)), valueBegin, valueEnd, GpuMatBeginItr<float>(d_valueGreater), pred_greater<float>(0.0));
cv::Mat h_greater(d_valueGreater);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment