Saturday 3 October 2015

Installation of CUDA Toolkit on Ubuntu 20.04 LTS

About this tutorial

This tutorial will guide you about installation steps for CUDA parallel programming
architecture.

Introduction

CUDA (Compute Unified Device Architecture) is technology developed by NVIDIA Inc. 
The purpose of CUDA is to execute the programs and instructions in parallel manner on 
the processor. 

Prerequisites

Installation

After completing download and installation of Ubuntu, follow the next steps.
1. Log in as root user
2. Update Ubuntu for latest packages

# apt-get update

3. To install compiler, essential for CUDA toolkit, run following command:

# apt-get install build-essential

Some desktop version of Linux might cause problems such as slow response, 
unresponsive GUI. In order to avoid such problems, we need to switch to text mode.

4. To switch to text mode, use keyboard shortcut:  Alt+Ctrl+F1
5. Login as root.
6. Stop GUI service, use following command:
# service lightdm stop
7. Go to folder location of CUDA toolkit file
# cd /home/user_name/Downloads/

8. Download CUDA toolkit
# wget https://developer.download.nvidia.com/compute/cuda/11.4.0/local_installers/cuda_11.4.0_470.42.01_linux.run

9. Change the permission of file and run following command
# sudo sh cuda_11.4.0_470.42.01_linux.run

If file is not executable, try to run it with following command:
# ./cuda_11.4.0_470.42.01_linux.run

10. If prompt of absolute path of CUDA toolkit appear on screen, press Y
11. For /home/<user_name> option, where <user_name> will be your current name, press 'Enter'.

You'll see installation skipped then reboot with
# reboot -h

After restart, Linux will automatically switch to GUI mode. 
Repeat the steps from 4 to 9 to switch back from GUI to text mode. Now reboot system manually.

After system will start, enter two commands as general user:

# export PATH=/usr/local/cuda-11.4/bin:$PATH
# export LD_LIBRARY=/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH

Now we are ready to run our hello world program for Nvidia CUDA.

Copy and paste Hello World example in gedit.
.cu is the extension of our program.
Save to current directory.
To compile:  
# nvcc -cuda hello.cu
To run:      
# ./a.out

If you can see Hello World as output, you've successfully installed CUDA toolkit on Ubuntu.

Installing FreeGLUT in CodeBlock



Install FreeGLUT (Be Careful )

1.       Download : http://www.transmissionzero.co.uk/software/freeglut-devel/
From above location, download freeglut-mingw.zip
Extract the file in any folder.

2.       Now create two copies of GNU GCC Compiler.

a.       First is 32 bits and copy following files as directed:
        
File
From (FreeGLUT\)
To(MinGW32\)
freeglut.dll
bin
bin and C:\Windows\System32\
Freeglut.h
Freeglut_ext.h
Freeglut_std.h
glut.h  (optional as in previous step)
include\GL
include\GL
libfreeglut.a
libfreeglut_static.a
lib
lib

b.      Second one, 64 bits is other copy for it do as follows:

      File
From (FreeGLUT\)
To(MinGW64\)
freeglut.dll
bin\x64
bin and C:\Windows\SysWOW64\
Freeglut.h
Freeglut_ext.h
Freeglut_std.h
glut.h
include\GL
include\GL
libfreeglut.a
libfreeglut_static.a
lib\x64
lib

3.       Now move to settings of Compiler in CB.
a.  For 32 bits Compiler version,

Don’t forget to update Toolchain Executables as per need ,here, C:\TDM-GCC-32

Linker Settings =>Link Libraries
C:\TDM-GCC-32\lib\libfreeglut.a
C:\TDM-GCC-32\lib\libfreeglut_static.a

In “Other Linker Options”
-lOpenGL32 -lglu32 –lfreeglut

Search Directories Tab => Compiler
C:\TDM-GCC-32\include
Search Directories Tab => Linker
C:\TDM-GCC-32\lib

b.  For 64 bits Compiler version,
Don’t forget to update Toolchain Executables as per need ,here, C:\TDM-GCC-64

For toolchain Executables (in order of appearance)
gcc.exe
g++.exe
g++.exe
ar.exe
windres.exe
mingw32-make.exe

Linker Settings =>Link Libraries
C:\TDM-GCC-64\lib\libfreeglut.a
C:\TDM-GCC-64\lib\libfreeglut_static.a

In “Other Linker Options”
-lOpenGL32 -lglu32 –lfreeglut

Search Directories Tab => Compiler
C:\TDM-GCC-64\include
Search Directories Tab => Linker
                  C:\TDM-GCC-64\lib

4.       Now, create empty project with choosing compiler suitable to your OS. Right click on Project and go to the project properites and Build Targets => build type => GUI application
5.       Now download and extract this zip file:
6.       And place *.h and *.cpp files into CB project locations.
7.       Now again confirm Compiler from Rt Click on project => Build options.
8.       Now rebuild => build => run.

                You will get this output:

Installing GLUT in CodeBlock



For GLUT:
Considering we are having Codeblock and MinGW compiler,
      1.      Download this file: http://www.deannicholls.co.uk/site/files/glut.zip
      2.      Now perform following steps:
Extract the 'Glut.zip' file you downloaded and do the following:-

Copy glut32.dll into your 'C:\Windows\System32' folder (If you're using Windows 7 64-bit, you'll need to copy this file into 'C:\Windows\sysWOW64').

Copy glut.h into the ‘include\GL’ folder in the MinGW compiler folder.This folder will be 'C:\MinGW\include\GL'.

Copy libglut32.a into the 'MinGW\lib' folder. If you installed CodeBlocks and MinGW to the default directory in Step 3, this folder will be 'C:\Program Files\CodeBlocks\MinGW\lib'.

      3.      Go to CB=>Settings=> Compiler => Copy your “GNU GCC Compiler”
      4.      Rename your new compiler.
      5.      In Linker Settings => Link Libraries, add the following lines:
opengl32
glu32
glut32

      6.      Your GLUT compiler is ready and its time to execute program:


 // Created by: Dean Nicholls  
 // Date: 18th June 2010  
 // Created For: http://www.levelbylevel.com  
 //  
 // This is a small OpenGL application which will display a  
 // blue sphere on a black background.  
 //  
 // This Program was created to acompany the tutorial  
 // for setting up CodeBlocks, MinGW, OpenGL and GLUT.  
 // Found at: http://www.levelbylevel.com  
 //  
 // It is not intended to be a guide or even a good  
 // template for building a graphic application. It is  
 // therefore not properly commented or efficient.  
 // However feel free to use this code in any way you wish.  
 #include <iostream>  
 #include <GL/glut.h>  
 using namespace std;  
 GLfloat mat_ambient[] = {0.5, 0.5, 0.5, 1.0};  
 GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};  
 GLfloat mat_shininess[] = {50.0};  
 GLfloat light_position[] = {10.0, 10.0, 10.0, 0.0};  
 GLfloat model_ambient[] = {1.0, 0.5, 0.5, 1.0};  
 void setupMaterials() {  
      glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);  
      glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);  
      glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);  
      glLightfv(GL_LIGHT0, GL_POSITION, light_position);  
      glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);  
 }  
 void changeColour(GLfloat r, GLfloat g, GLfloat b, GLfloat A) {  
      model_ambient[0] = r;  
      model_ambient[1] = g;  
      model_ambient[2] = b;  
      model_ambient[3] = A;  
      glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);  
 }  
 void init(void) {  
      glClearColor(0.0, 0.0, 0.0, 1.0);  
      setupMaterials();  
      glEnable(GL_LIGHTING);  
      glEnable(GL_LIGHT0);  
      glEnable(GL_DEPTH_TEST);  
      glEnable(GL_CULL_FACE);  
      glFrontFace(GL_CCW);  
      glShadeModel(GL_SMOOTH);  
 }  
 void reshape(int w, int h) {  
      GLfloat fAspect;  
      if(h==0) h=1;  
      glViewport(0,0,w,h);  
      fAspect = (GLfloat)w / (GLfloat)h;  
      glMatrixMode(GL_PROJECTION);  
      glLoadIdentity();  
      gluPerspective(60, fAspect, 0.5, 100.0);  
      glTranslatef(0,0,-1);  
      glMatrixMode(GL_MODELVIEW);  
      glLoadIdentity();  
 }  
 void display(void) {  
      int slices = 30;  
      int stacks = 30;  
      float radius = 0.2;  
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
   glPushMatrix();  
     changeColour(0.0, 0.0, 1.0, 1.0);  
     glTranslatef(0.0, 0.0, 0.1);  
     glutSolidSphere(radius, slices, stacks);  
   glPopMatrix();  
      glFlush();  
   glutSwapBuffers();  
 }  
 void keyboard(unsigned char key, int x, int y) {  
      switch (key) {  
           case 27:  
                exit(0); // Exit the application if 'Esc' key is pressed  
      }  
 }  
 void animate() {  
      glutPostRedisplay();  
 }  
 int main(int argc, char * argv[]) {  
   glutInit(&argc, argv);  
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);  
   glutInitWindowSize (800, 600);  
   glutCreateWindow (argv[0]);  init();  
   glutKeyboardFunc (keyboard);  
   glutDisplayFunc (display);  
   glutReshapeFunc (reshape);  
   glutIdleFunc(animate);  
   glutMainLoop();  
   return 0;  
 }  

7.       Create empty project with new compiler as its current compiler.
8.       Now extract  deannicholls_glut_tutorial_main.zip and paste main.cpp inside the location of CB project.
9.       Now, confirm again by setting compiler from Build Options.
10.   After that, rebuild => build => run.

Sunday 6 September 2015

Running Graphics Program of C on Windows 7 64 bits In CodeBlocks IDE 13.12


Today we are going to see how to run C graphics program on 64 bits Windows 7 using CodeBlocks 13.12. 

It will require only 12 steps. Follow with caution and you are done.

These are the instructions I have tried for 64 bits windows 7:
  1. Download zip file from this repository: https://github.com/stahta01/windows-games
    This one is having latest files of Graphics Libraries.

  2. Now either you are using external GCC compiler or internal GCC compiler doesn’t matter, just follow the universal procedure recommended for this.
  3. Copy the following files 
From(windows-games-master\WinBGIm)
To (MinGW)
include folder  => graphics.h
Include
src folder => Winbgim.h
Include
lib folder => libbgi.a
Lib

           If any of the files are already at destination, please overwrite as these are going to work for 64
           bits versions.

4.  Now, go to Setting => Compile and Debugger => Selected Compiler => GNU GCC Compiler.
           -  I will recommend to make copy of existing compiler and rename it. So that any kind of mess will not
           disturb other type of program execution. 



     5.    Now in Linker settings => Add => File => C:\MinGW32\lib\libbgi.a
      
     6.    Go to right part, other settings paste these parameters:
           -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
       
     7. Now half of the configuration has been done.

          
     8. Create simple empty project using codeblocks and add file with extension .cpp.
  
     9.     Most IMPORTANT part is now:

      
Now, right click on Project Name => Build Options => selected Compiler.

       You have to select the compiler which you have configured.
       Otherwise you will get:
       i. Memory access violation error "Process-returned-1073741819-0xc0000005" 
               or 
      ii. Segmentation fault.
  
     After successfully completing above steps, try the following program with Hello.cpp   
  
     This is my sample program to print name of screen:

 #include<graphics.h>  
 #include<conio.h>  
 main()  
 {  
   int gd = DETECT,gm,left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;  
   initgraph(&gd, &gm, "C:\\TC\\BGI");  
   rectangle(left, top, right, bottom);  
   circle(x, y, radius);  
   bar(left + 300, top, right + 300, bottom);  
   line(left - 10, top + 150, left + 410, top + 150);  
   ellipse(x, y + 200, 0, 360, 100, 50);  
   outtextxy(left + 100, top + 325, "My First C Graphics Program");  
   getch();  
   closegraph();  
   return 0;  
 }  


    10.  Now, rebuild the project.

    11.  After that, compile and run.

    12.  You will definitely see such message printed,



Thursday 25 June 2015

Wireless Connectivity in CentOS 6.x

Hi,

Banging your head on wall for not able to connect with Free wifi in campus or coffee shop?

Its time to end it.

Just two commands and you are done.


For CentOS 6/RedHat 6:

# rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

Then install Ralink NIC adapter:

# yum install kmod-r8168

It will take sometime to show its action (even for 8GB RAM & 1TB system ;)

After some installation instructions, I hope you will see wireless connection in Linux !!

#CentOS6 #CentOS7 #Redhat #Ralink #Wireless #Wifi

Installation of Linux Kernel and Run Hello World module in Easy Steps

I have observed people like me struggled very much while writing their first Linux kernel module. Most of them leave in the middle due to a lot of hectic. For them, I am writing in simple English how to write you first LKM i.e. Linux Kernel Module.

Following is the prerequisite of  LKM:

For Fedora/CentOS:

Before starting the kernel compilation, just make sure the kernel version you are having. 
 
# uname -r
 
3.17.4-301.fc21.x86_64

Now, with the same result append it with following command like:
 
# yum install kernel-devel-3.17.4-301.fc21.x86_64

and this will install the package for your current kernel version.

For Ubuntu/Debian (On experimentation basis):

# apt-get install build-essential linux-headers-$(uname -r)


additional packages, you require:

For Fedora/Redhat/CentOS

# yum install gcc           -  To  compile the make file
# yum install rsyslog     -  To see logs of result

For Ubuntu/Debian
# apt-get install gcc          
# apt-get install rsyslog

Remember to do Kernel related operation most possibly as non-root user.

Create a directory, say, LKP

$ cd Documents/LKP/

$ touch hello.c

The hello.c should be like this:

 #include <linux/module.h>    /* Needed by all modules */  
 #include <linux/kernel.h>    /* Needed for KERN_LOGLEVEL_MESSAGES */  
 #include <linux/init.h>     /* Needed for the macros */  
 MODULE_LICENSE("GPL");  
 MODULE_AUTHOR("Mayur Patil");  
 MODULE_DESCRIPTION("Hello World module");  
 MODULE_VERSION("v0.1");  
 static int __init hello_start(void){  
 printk(KERN_INFO "Loading hello module...\n");  
 printk(KERN_INFO "Hello world\n");  
 return 0;  
 }  
 static void __exit hello_end(void){  
 printk(KERN_DEBUG "End of Hello World Kernel Module\n");  
 printk(KERN_DEBUG "DEBUG IS SUCCESSFUL\n");  
 }  
 module_init(hello_start);  
 module_exit(hello_end);  



Be careful regarding the "Makefile" (yes, the name must be as it is as I typed)

Next Important thing is give tabs rather than spaces.

ifneq ($(KERNELRELEASE),) 
obj-m := hello.o
else
<tab>KERNEL_SOURCE := /usr/src/kernels/3.17.4-301.fc21.x86_64 
<tab>PWD := $(shell pwd)

default: 
<tab>${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) modules  
clean:
<tab>${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) clean

endif


and its contents should be copy paste from here and only change the path of Linux Kernel source tree.

Now to see kernel messages we need the log levels.

KERN_INFO       "6"      Informational message
                                    e.g. startup information at driver initialization    




KERN_DEBUG    "7"     Debug messages



Now login as root user, give following command:

# echo "7" > /proc/sys/kernel/printk
 
# cat /proc/sys/kernel/printk
7          4         1                7

Meaning of it is:

7                 4                   1                7
current    default       minimum    boot-time-default

Insert module

# insmod hello.ko

Whether module loaded or not check with:

# lsmod | less

Now check in logs whether message is appeared,

# cat /var/log/messages
or

# tail -f /var/log/messages

If you want to only debug related messages;

# dmesg

To clear,

# dmesg -c


Now, time to remove your module i.e. unloading

# rmmod hello


Check again for message

# dmesg

In this tutorial, we've completed building Linux kernel from source and loading of first "Hello World!" module.

Friday 2 January 2015

Mozilla Firefox More than A Web Browser: Getting Started

Hi All,

This is to inform you that in my college we are organizing a mozilla oriented event known as

                   "Mozilla Firefox More than A Web Browser: Getting Started"
 
Only thing I feel sorry is that if public outside the college reading this, they won't be able to participate.
This time our college students only.  :)

We are having with us:

1. Ankit Gadgil:           Reps Mentor for Mozilla Firefox Pune
2. Diwanshi Pandey:    Reps for Pune Area, Lead Speaker of WOMOZ.
3. Siddharatha Rao:    Customization of Mozilla Firefox
4. Ankit Mehta:         

Please note:
1. Only 60 registrations are allowed.  (We will try to increase number a/c to your response).
2. It is on FCFS basis.
3. As this is free to attend hands on event, things you have to come with are:
    - Laptop
    - Installed with Latest Firefox: https://www.mozilla.org/en-US/firefox/all/ having language of your choice.

Date & Time:   17 Jan 2015 ,Saturday, 10:00 am to 4:00 pm
Venue:              Project Lab, 3rd Floor,
                        Dept of Computer Engineering,
                        MITAOE, Alandi,
                        Pune.

If you are going to establish new Firefox club and while doing event if you need job roles for Committee members for organizing event, Here is a sample draft I have made.

You can download it from:    http://goo.gl/qLtsDb