CUDA (General)
Step 1: Prepare CUDA Program Source Code
Section titled “Step 1: Prepare CUDA Program Source Code”Example source code path -> /home/$USER/job_template/C/cuda_hello_world.cu
#include <stdio.h>#include <cuda_runtime.h>
// CUDA kernel to print Hello World__global__ void helloWorldKernel() { printf("Hello World from thread %d, block %d\n", threadIdx.x, blockIdx.x);}
int main() { // Launch the kernel with 1 block of 10 threads helloWorldKernel<<<1, 10>>>();
// Synchronize to ensure all printf calls are completed cudaDeviceSynchronize();
// Check for any CUDA errors cudaError_t err = cudaGetLastError(); if (err != cudaSuccess) { fprintf(stderr, "CUDA Error: %s\n", cudaGetErrorString(err)); return 1; }
return 0;}Step 2: Prepare job template script
Section titled “Step 2: Prepare job template script”Pre-configured template script path -> /home/$USER/job_template/slurm_job
#!/bin/bash#SBATCH --job-name=cuda_hello_world ## Job Name#SBATCH --partition=shared_gpu_l40 ## Partition for Running Job#SBATCH --nodes=1 ## Number of Compute Node#SBATCH --ntasks-per-node=1 # Number of Task per Compute Node#SBATCH --cpus-per-task=2 ## Number of CPU per task#SBATCH --time=60:00 ## Job Time Limit (i.e. 60 Minutes)#SBATCH --mem=10GB ## Total Memory for Job#SBATCH --gres=gpu:l40:2 # Number of GPUs per node (i.e. 1 x L40 GPU)#SBATCH --output=./%x%j.out ## Output File Path#SBATCH --error=./%x%j.err ## Error Log Path
## Initiate Environment Modulesource /usr/share/modules/init/profile.sh
## Reset the Environment Module componentsmodule purge
## Load Modulemodule load cuda/12.6
## Run user commandnvcc -o ./cuda_hw /home/${USER}/job_template/C/cuda_hello_world.cu./cuda_hw
## Clean uprm cuda_hw
## Clear Environment Module Componentsmodule purgeStep 3: Create Template (Web Interface Feature)
Section titled “Step 3: Create Template (Web Interface Feature)”To submit HPC via web interface a job template is required, details please refer to: Create Template (Web Interface Feature)
For Job submission via CLI Terminal, please skip this step.
Step 4: Submit HPC Job
Section titled “Step 4: Submit HPC Job”Guides for submitting HPC job, please refer to: HPC Job Submission