Difference between revisions of "Streams and Multi-GPU using CUVI"
Line 28: | Line 28: | ||
===Same example with Streams=== | ===Same example with Streams=== | ||
Streams greatly improve performance of your application by hiding data processing time in data copying time. Instead of waiting for the complete image to be copied on GPU before processing, streaming enables processing the data as it arrives on GPU. Here's how you can use streaming in your application using CUVI: | Streams greatly improve performance of your application by hiding data processing time in data copying time. Instead of waiting for the complete image to be copied on GPU before processing, streaming enables processing the data as it arrives on GPU. Here's how you can use streaming in your application using CUVI: | ||
{| | |||
|style="font-size:130%;"| | |||
<syntaxhighlight lang="cpp"> | |||
//Number of data chunks | |||
int streamCount = 1; | |||
//Size of the image | |||
CuviSize size = cuviSize(img->width,img->height); | |||
//Creating a 3-channel Image container on GPU | |||
CuviImage* gimg = new CuviImage(size,img->depth,3); | |||
//Creating a sing channel Image container for output on GPU | |||
CuviImage* gout = new CuviImage(size,img->depth,1); | |||
//Chunk Size | |||
gimg->height = gimg->height / streamCount; | |||
gout->height = gout->height / streamCount; | |||
CuviStream **streams = new CuviStream*[streamCount]; | |||
for(int i=0; i<streamCount; i++) | |||
cuviCreateStream(&streams[i]); | |||
timer.Start(); | |||
char* ptr_in = NULL; | |||
const char* start_ptr_in = (char*)inputImage->data; | |||
size_t gpuChunk = gimg->height * gimg->pitch, | |||
gpuOutChunk = gimg->height * gout->pitch, | |||
hostChunk = gimg->height * host_img->widthStep; | |||
hostOutChunk = gimg->height * host_out->widthStep; | |||
for(int i=0; i<streamCount; i++) | |||
inputImage->upload(gimg->data + i*gpuChunk, cpu_ptr + i*hostChunk, host_img->widthStep,streams[i]); | |||
for(int i=0; i<streamCount; i++) | |||
cuvi::colorOperations::RGB2Gray(gimg + i*gpuChunk, gout + i*gpuOutChunk, streams[i]); | |||
for(int i=0; i<streamCount; i++) | |||
gout->download(cpu_out_ptr + i*hostOutChunk , gout + i*gpuOutChunk, host_out->widthStep, streams[i]); | |||
for(int i=0; i<streamCount; i++) | |||
cuviDestroyStream(&(streams[i])); | |||
delete gimg; | |||
delete gout; | |||
delete[] streams; | |||
</syntaxhighlight> | |||
|} |
Revision as of 15:28, 4 May 2012
Using Streams with CUVI
CUVI framework provides a way to use streams with minimal coding effort. Each function call in CUVI takes an optional parameter to specify the stream on which it should run. The code below shows how a simple function call of CUVI can be divided into streaming calls on GPU. For most of the cases this will result in better performance as copying image data to GPU and processing that data on GPU happens simultaneously.
CUVI example
In this example we use CUVI's RGB2Gray function from Color Operations module on a full HD input image
|
Same example with Streams
Streams greatly improve performance of your application by hiding data processing time in data copying time. Instead of waiting for the complete image to be copied on GPU before processing, streaming enables processing the data as it arrives on GPU. Here's how you can use streaming in your application using CUVI:
|