0% found this document useful (0 votes)
4 views2 pages

addition.ipynb - Colab

The document provides instructions for installing the CUDA toolkit version 11.2 on an Ubuntu system, including commands for updating the package list and installing the toolkit. It also includes a sample CUDA program for vector addition, demonstrating memory allocation, data transfer, and kernel execution. The document shows the output of the CUDA compiler and NVIDIA system management interface commands to verify the installation and configuration of CUDA.

Uploaded by

jshruti6896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

addition.ipynb - Colab

The document provides instructions for installing the CUDA toolkit version 11.2 on an Ubuntu system, including commands for updating the package list and installing the toolkit. It also includes a sample CUDA program for vector addition, demonstrating memory allocation, data transfer, and kernel execution. The document shows the output of the CUDA compiler and NVIDIA system management interface commands to verify the installation and configuration of CUDA.

Uploaded by

jshruti6896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# Install CUDA toolkit (example: CUDA 11.

2)
!apt-get update
!apt-get install -y cuda-toolkit-11-2

Get:1 https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/ InRelease [3,632 B]


Get:2 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 InRelease [1,581 B]
Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Get:5 http://security.ubuntu.com/ubuntu jammy-security InRelease [129 kB]
Get:6 https://r2u.stat.illinois.edu/ubuntu jammy InRelease [6,555 B]
Get:7 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [127 kB]
Get:8 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 Packages [1,607 kB]
Hit:9 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease
Get:10 https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy InRelease [24.3 kB]
Get:11 https://r2u.stat.illinois.edu/ubuntu jammy/main all Packages [8,863 kB]
Hit:12 https://ppa.launchpadcontent.net/ubuntugis/ppa/ubuntu jammy InRelease
Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1,543 kB]
Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [3,154 kB]
Get:15 https://r2u.stat.illinois.edu/ubuntu jammy/main amd64 Packages [2,700 kB]
Get:16 https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy/main amd64 Packages [47.4 kB]
Fetched 18.3 MB in 3s (5,951 kB/s)
Reading package lists... Done
W: Skipping acquire of configured file 'main/source/Sources' as repository 'https://r2u.stat.illinois.edu/ubuntu jammy InRelease' do
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package cuda-toolkit-11-2

 

!nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver


Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Jun__6_02:18:23_PDT_2024
Cuda compilation tools, release 12.5, V12.5.82
Build cuda_12.5.r12.5/compiler.34385749_0

!nvidia-smi

Mon Apr 28 03:19:35 2025


+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.15 Driver Version: 550.54.15 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |
| N/A 46C P8 13W / 70W | 0MiB / 15360MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+

%%writefile add.cu
#include <iostream>
#include <cuda_runtime.h>

__global__ void addVectors(int * A, int * B, int * C, int n) {


int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < n) {
C[i] = A[i] + B[i];
}
}

int main() {
int n;
std::cout << "Enter the number of elements: ";
std::cin >> n;

int * A = new int[n];


int * B = new int[n];
int * C = new int[n];

std::cout << "Enter elements for vector A:" << std::endl;


for (int i = 0; i < n; i++) {
std::cin >> A[i];
}

std::cout << "Enter elements for vector B:" << std::endl;


for (int i = 0; i < n; i++) {
std::cin >> B[i];
}

int size = n * sizeof(int);

int * dev_A, * dev_B, * dev_C;


cudaMalloc( & dev_A, size);
cudaMalloc( & dev_B, size);
cudaMalloc( & dev_C, size);

cudaMemcpy(dev_A, A, size, cudaMemcpyHostToDevice);


cudaMemcpy(dev_B, B, size, cudaMemcpyHostToDevice);

int blockSize = 256;


int numBlocks = (n + blockSize - 1) / blockSize;
addVectors << < numBlocks, blockSize >>> (dev_A, dev_B, dev_C, n);

cudaMemcpy(C, dev_C, size, cudaMemcpyDeviceToHost);

std::cout << "Vector Addition Results:" << std::endl;

for (int i = 0; i < n && i < 10; i++) { //print up to 10 results.


std::cout << C[i] << " ";
}
std::cout << std::endl;

cudaFree(dev_A);
cudaFree(dev_B);
cudaFree(dev_C);
delete[] A;
delete[] B;
delete[] C;

return 0;
}

Writing add.cu

!nvcc add.cu -o add -arch=sm_75

!./add

Enter the number of elements: ^C

58

Start coding or generate with AI.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy