CUDA tutorial: Difference between revisions

Jump to navigation Jump to search
Line 8: Line 8:
$ module load cuda
$ module load cuda
</source>
</source>
As a first step we will add two numbers together. Save the below file as <code>add.cu</code>. '''The <code>cu</code> file extension is important!'''.  
As a first step we will add two numbers together on a GPU. Save the below file as <code>add.cu</code>. '''The <code>cu</code> file extension is important!'''.  
{{File   
{{File   
   |name=add.cu
   |name=add.cu
Line 44: Line 44:
}
}
}}
}}
To build the program use the command below.
To build the program use the command below which will create an executable named <code>add</code>.
<source lang="console">
<source lang="console">
$ nvcc add.cu -o add
$ nvcc add.cu -o add
</source>
</source>
To run the program first create a GPU job script called gpu_job.sh
To run the program first create a Slurm job script called gpu_job.sh.
{{File
{{File
   |name=gpu_job.sh
   |name=gpu_job.sh
Line 59: Line 59:
#SBATCH --time=0-00:10            # time (DD-HH:MM)
#SBATCH --time=0-00:10            # time (DD-HH:MM)
./add #name of your program
./add #name of your program
}}
}}For information about GPU job scripts see [[Using GPUs with Slurm|using GPUs with Slurm]].
Then submit your GPU job to the scheduler with following command
 
Submit your GPU job to the scheduler with this command.
<source lang="console">
<source lang="console">
$ sbatch gpu_job.sh
$ sbatch gpu_job.sh
</source>
Submitted batch job 3127733
Once your job has finished you should see an output file like:
</source>For information about the <code>sbatch</code> command and running and monitoring jobs see [[Running jobs|running jobs]].
 
Once your job has finished you should see an output file similar to this.
<source lang="console">
<source lang="console">
$ cat slurm-3127733.out
$ cat slurm-3127733.out
2+7=9
2+7=9
</source>
</source>
If you run this where a GPU isn't present you might see output something like <code>2+7=0</code>.
If you run this without a GPU present you might see output like <code>2+7=0</code>.


=Introduction= <!--T:1-->
=Introduction= <!--T:1-->
cc_staff
1,486

edits

Navigation menu