Something More for Research

Explorer of Research #HEMBAD

Posts Tagged ‘GPU’

OpenCV CUDA Sample Program

Posted by Hemprasad Y. Badgujar on July 17, 2015


Design considerations

OpenCV GPU module is written using CUDA, therefore it benefits from the CUDA ecosystem. There is a large community, conferences, publications, many tools and libraries developed such as NVIDIA NPP, CUFFT, Thrust.

The GPU module is designed as host API extension. This design provides the user an explicit control on how data is moved between CPU and GPU memory. Although the user has to write some additional code to start using the GPU, this approach is both flexible and allows more efficient computations.

GPU modules includes class cv::gpu::GpuMat which is a primary container for data kept in GPU memory. It’s interface is very similar with cv::Mat, its CPU counterpart. All GPU functions receive GpuMat as input and output arguments. This allows to invoke several GPU algorithms without downloading data. GPU module API interface is also kept similar with CPU interface where possible. So developers who are familiar with Opencv on CPU could start using GPU straightaway.

Short sample

In the sample below an image is loaded from png0file, next it is uploaded to GPU, thresholded, downloaded and displayed.

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"

int main (int argc, char* argv[])
{
    try
    {
        cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE);
        cv::gpu::GpuMat dst, src;
        src.upload(src_host);

        cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);

        cv::Mat result_host = dst;
        cv::imshow("Result", result_host);
        cv::waitKey();
    }
    catch(const cv::Exception& ex)
    {
        std::cout << "Error: " << ex.what() << std::endl;
    }
    return 0;
}

Posted in Mixed | Tagged: , , , | Leave a Comment »

Professional ways of tracking GPU memory leakage

Posted by Hemprasad Y. Badgujar on January 25, 2015


Depending on what I am doing and what I need to track/trace and profile I utilise all 4 packages above. They also have the added benefit of being a: free; b: well maintained; c: free; d: regularly updated; e: free.

In case you hadn’t guessed I like the free part:)

In regards of object management, I would recommend an old C++ coding principle: as soon as you create an object, add the line that deletes it, every new should always (eventually) have a delete. That way you know that you are destroying the objects you create, however it will not save you from orphaned memory block memory leaks, where you change where pointers are pointing, for example:

myclass* firstInstance = new myclass();
myclass* secondInstance = new myclass();
firstInstance = secondInstance;
delete firstInstance;
delete secondInstance;

You will now have created a small memory leak where the data for the real firstInstance is now not being pointed at by any pointer. Very hard to detect when this happens in a large code-base, and more common that it should be.

generally these are the pairings you need to be aware of to ensure you properly dispose of all your objects:

new -> delete
new[] -> delete[]
malloc() -> free() // or you can use realloc(0) instead of free()
calloc() -> free() // or you can use realloc(0) instead of free()
realloc(nonzero) -> free() // or you can use realloc(0) instead of free()

If you are coming from a language with garbage collection to C++ it can take a while to get used to, but it quickly becomes habit:)

Posted in C, Computer Languages, Computer Vision, Computing Technology, CUDA | Tagged: , , , , , | Leave a Comment »

Installing CUDA Toolkit 5.5 on Ubuntu 12.10 Linux

Posted by Hemprasad Y. Badgujar on January 3, 2014


Installing CUDA Toolkit 5.5 on Ubuntu 12.10 Linux

The following explains how to install CUDA Toolkit 5.5 on 64-bit Ubuntu 12.10 Linux. I have tested it on a self-assembled desktop with AMD Phenom II X4 CPU, 4GB RAM, 500GB hard drive, 650W power supply, and NVIDIA GeForce GTX 550 Ti graphics card. The instruction assumes you have the necessary CUDA compatible hardware support. Depending on your system configuration, your mileage may vary.

 

CUDA Repository

Retrieve the CUDA repository package for Ubuntu 12.10 from the CUDA download site and install it in a terminal.

$ sudo dpkg –i cuda-repo-ubuntu1210_5.5-0_amd64.deb
$ sudo apt-get update

 

Linux Kernel Header

Then you need to install the necessary Linux kernel headers.

$ sudo apt-get install linux-headers-‘uname -r‘

 

Proprietary Video Driver

The built-in nouveau video driver in Ubuntu is incompatible with the CUDA Toolkit, and you have to replace it with the proprietary NVIDIA driver.

$ sudo apt-get remove –purge \
    xserver-xorg-video-nouveau

$ sudo apt-get install nvidia-settings \
    nvidia-current-dev nvidiamodprobe

You can reboot the system afterwards and verify the driver installation with the nvidia-settings utility.

 

CUDA Toolkit

Then you can install the CUDA Toolkit using apt-get.

$ sudo apt-get install cuda

 

Environment Variables

As part of the CUDA environment, you should add the following in the .bashrc file of your home folder.

export CUDA_HOME=/usr/local/cuda-5.5
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64

PATH=${CUDA_HOME}/bin:${PATH}
export PATH

 

CUDA SDK Samples

Now you can copy the SDK samples into your home directory, and proceed with the build process.

cuda-install-samples-5.5.sh  ~
cd ~/NVIDIA_CUDA-5.5_Samples
$ make

If everything goes well, you should be able to verify your CUDA installation by running thedeviceQuery sample in bin/linux/release.

Posted in Computer Languages, Computing Technology, CUDA, GPU (CUDA), PARALLEL | Tagged: , , , , , | Leave a Comment »

Installing CUDA 5 on Ubuntu 12.04

Posted by Hemprasad Y. Badgujar on January 3, 2014


This guide is based on Ubuntu 12.04 LTS, but the same principles apply in newer versions of Ubuntu. Let’s begin.

nvidia-cuda

1. Make sure you have a CUDA supported GPU

You must have a nVIDIA GPU that supports CUDA, otherwise you can’t program in CUDA code. Here’s a list with the CUDA supported GPU models.

2. Install nVIDIA proprietary drivers

Use Jockey (additional drivers) or just pick the driver you want from the NVIDIA official website.

3. Download CUDA Toolkit 5.0 for Ubuntu

I used the Ubuntu 11.10 32bit version. It’s the latest version so far, but it currently works fine. So please download.

4. Fix the libglut.so error

There will be an error when you’ll try to install the CUDA 5.0 examples. The driver is trying to find the libglut.so file and it doesn’t look for other versions, such as so.1so.2 etc.

First confirm that you have a libglut file:

$ sudo find /usr -name libglut\*

If you do, symlink that file to libglut.so.

For 64bit:

$ sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so.3 /usr/lib/libglut.so

For 32bit:

$ sudo ln -s /usr/lib/i386-linux-gnu/libglut.so.3 /usr/lib/libglut.so

5. Install the CUDA Toolkit and Samples

Press CTRL+ALT+F1 to open a shell — yeah, we’re going to do this in old (yet powerful) command-line way, but there’s no need to be afraid of the black and white terminal with a blinking cursor. After all you know what they say, once you go black…

5.1 Shutdown the all the graphics

Ubuntu uses LightDM, so you need to stop this service:

$ sudo service lightdm stop

5.2 Run the installer

Go to (using cd) the directory where you have the CUDA installer (a file with *.run extension) and type the following:

$ sudo chmod +x *.run
$ sudo ./*.run

Accept the License and install only the CUDA 5 Toolkit and the Samples. DO NOT install the drivers because we have already done that.

6. Enable the nvcc compiler

In order to compile CUDA code you have to use the nvcc compile. In that so you have to tweak some environment variables into your ~/.bashrc file:

For 32bit:

export PATH=$PATH:/usr/local/cuda-5.0/bin
export LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib

For 64bit:

export PATH=$PATH:/usr/local/cuda-5.0/bin
export LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib64:/lib

If you want to compile a CUDA file (*.cu extension) you can use the following command:

nvcc -o file file.cu

./file

Or use the NSight Eclipse Edition.

– See more at: http://www.unixmen.com/how-to-install-cuda-5-0-toolkit-in-ubuntu/#sthash.IScUBu1O.dpuf

Posted in Computer Softwares, Computing Technology, CUDA, GPU (CUDA), GPU Accelareted, Installation, PARALLEL, Project Related, Research Menu, UNIX OS | Tagged: , , , , , , | Leave a Comment »

GPU Acceleration In Multilayer Parallel User Authentication Schemes By Optimizing Hardware Use

Posted by Hemprasad Y. Badgujar on May 29, 2013


GPU Acceleration In Multilayer Parallel User Authentication Schemes By Optimizing Hardware Use

P0212 GPU Acceleration In Multilayer Parallel User Authentication Schemes By Optimizing Hardware Use
Hemprasad Badgujar (Hardsoft)

Posted in Mixed | Tagged: , , , , | 1 Comment »

 
Extracts from a Personal Diary

dedicated to the life of a silent girl who eventually learnt to open up

Num3ri v 2.0

I miei numeri - seconda versione

ThuyDX

Just another WordPress.com site

Algunos Intereses de Abraham Zamudio Chauca

Matematica, Linux , Programacion Serial , Programacion Paralela (CPU - GPU) , Cluster de Computadores , Software Cientifico

josephdung

thoughts...

Tech_Raj

A great WordPress.com site

Travel tips

Travel tips

Experience the real life.....!!!

Shurwaat achi honi chahiye ...

Ronzii's Blog

Just your average geek's blog

Karan Jitendra Thakkar

Everything I think. Everything I do. Right here.

VentureBeat

News About Tech, Money and Innovation

Chetan Solanki

Helpful to u, if u need it.....

ScreenCrush

Explorer of Research #HEMBAD

managedCUDA

Explorer of Research #HEMBAD

siddheshsathe

A great WordPress.com site

Ari's

This is My Space so Dont Mess With IT !!

%d bloggers like this: