{"id":20513453,"url":"https://github.com/slimani-dev/cuda","last_synced_at":"2026-04-21T04:32:02.839Z","repository":{"id":126700099,"uuid":"333953795","full_name":"slimani-dev/cuda","owner":"slimani-dev","description":null,"archived":false,"fork":false,"pushed_at":"2021-01-30T20:05:43.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T13:52:56.420Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Cuda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slimani-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-28T21:16:09.000Z","updated_at":"2021-01-30T20:05:45.000Z","dependencies_parsed_at":"2023-06-17T18:00:58.578Z","dependency_job_id":null,"html_url":"https://github.com/slimani-dev/cuda","commit_stats":null,"previous_names":["slimani-dev/cuda"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/slimani-dev/cuda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fcuda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fcuda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fcuda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fcuda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slimani-dev","download_url":"https://codeload.github.com/slimani-dev/cuda/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimani-dev%2Fcuda/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32076903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T02:38:07.213Z","status":"ssl_error","status_checked_at":"2026-04-21T02:38:06.559Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T21:11:09.955Z","updated_at":"2026-04-21T04:32:02.818Z","avatar_url":"https://github.com/slimani-dev.png","language":"Cuda","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CUDA installation\n\nThe Nvidia CUDA toolkit is an extension of the GPU parallel computing platform and programming model. The Nvidia CUDA installation consists of inclusion of the official Nvidia CUDA repository followed by the installation of relevant meta package and configuring path the the executable CUDA binaries. \n\n## Software Requirements and Conventions Used\n\n| Category | Requirements, Conventions or Software Version Used |\n|----------|----------------------------------------------------|\n| System   | Ubuntu 20.04   |\n| Hardware | Nvidia Graphic Card   |\n| Software | - Nvidia Drivers \u003cbr\u003e - CUDA |\n| Other    | Privileged access to your Linux system as root or via the sudo command. |\n|Conventions| **#** - requires given *linux commands* to be executed with root privileges either directly as a root user or by use of `sudo` command \u003cbr\u003e **$** - requires given *linux commands* to be executed as a regular non-privileged user  |\n\n## Nvidia Drivers installation\n\n**Step 1** : First, detect the model of your nvidia graphic card and the recommended driver. To do so execute the following command. Please note that your output and recommended driver will most likely be different: \n\n```text\n$ ubuntu-drivers devices\n== /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0 ==\nmodalias : pci:v000010DEd00001D10sv00001025sd0000119Abc03sc02i00\nvendor   : NVIDIA Corporation\nmodel    : GP108M [GeForce MX150]\ndriver   : nvidia-driver-460 - third-party non-free recommended\ndriver   : nvidia-driver-450-server - distro non-free\ndriver   : nvidia-driver-450 - distro non-free\ndriver   : nvidia-driver-418-server - distro non-free\ndriver   : nvidia-driver-390 - distro non-free\ndriver   : xserver-xorg-video-nouveau - distro free builtin\n\n```\n\nFrom the above output we can conclude that the current system has **NVIDIA GeForce MX150** graphic card installed and the recommend driver to install is **nvidia-driver-460**. \n\n**Step 2** :  use the ubuntu-drivers command again to install all recommended drivers: \n\n```bash\n$ sudo ubuntu-drivers autoinstall\n```\n\n**Step 3** : Once the installation is concluded, reboot your system and you are done.\n\n```bash\n$ reboot\n```\n\n## CUDA installation\n\n**Step 1** Although you might not end up witht he latest CUDA toolkit version, the easiest way to install CUDA on Ubuntu 20.04 is to perform the installation from Ubuntu's standard repositories.\n\nTo install CUDA execute the following commands: \n\n```bash\n$ sudo apt update\n$ sudo apt install nvidia-cuda-toolkit\n```\n\n**Step 2** All should be ready now. Check your CUDA version: \n```bash\n$ nvcc --version\nnvcc: NVIDIA (R) Cuda compiler driver\nCopyright (c) 2005-2019 NVIDIA Corporation\nBuilt on Sun_Jul_28_19:07:16_PDT_2019\nCuda compilation tools, release 10.1, V10.1.243\n```\nand to check the Nvidia drivers\n\n```bash\n$ nvidia-smi\nThu Jan 28 13:21:12 2021       \n+-----------------------------------------------------------------------------+\n| NVIDIA-SMI 460.39       Driver Version: 460.39       CUDA Version: 11.2     |\n|-------------------------------+----------------------+----------------------+\n| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |\n| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |\n|                               |                      |               MIG M. |\n|===============================+======================+======================|\n|   0  GeForce MX150       Off  | 00000000:01:00.0 Off |                  N/A |\n| N/A   51C    P3    N/A /  N/A |    361MiB /  2002MiB |      0%      Default |\n|                               |                      |                  N/A |\n+-------------------------------+----------------------+----------------------+\n                                                                               \n+-----------------------------------------------------------------------------+\n| Processes:                                                                  |\n|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |\n|        ID   ID                                                   Usage      |\n|=============================================================================|\n|    0   N/A  N/A      1159      G   /usr/lib/xorg/Xorg                 45MiB |\n|    0   N/A  N/A      2173      G   /usr/lib/xorg/Xorg                124MiB |\n|    0   N/A  N/A      2357      G   /usr/bin/gnome-shell              133MiB |\n|    0   N/A  N/A      5678      G   ...AAAAAAAAA= --shared-files       50MiB |\n+-----------------------------------------------------------------------------+\n```\n\n**commun problem**\nsometimes the default configurtion for the nvidia drivers is not setup properly to fix this i used the following commands\n\n```bash\n$ sudo mv /lib/modprobe.d/blacklist-nvidia.conf /lib/modprobe.d/blacklist-nvidia.conf.back\n$ sudo update-initramfs -u\n$ reboot\n```\n\n\n## Compile a Sample CUDA code\n\nConfirm the installation by compiling an example CUDA C code. Save the following code into a file named eg. hello.cu: \n\n```c\n#include \u003cstdio.h\u003e\n\n__global__\nvoid saxpy(int n, float a, float *x, float *y)\n{\n  int i = blockIdx.x*blockDim.x + threadIdx.x;\n  if (i \u003c n) y[i] = a*x[i] + y[i];\n}\n\nint main(void)\n{\n  int N = 1\u003c\u003c20;\n  float *x, *y, *d_x, *d_y;\n  x = (float*)malloc(N*sizeof(float));\n  y = (float*)malloc(N*sizeof(float));\n\n  cudaMalloc(\u0026d_x, N*sizeof(float)); \n  cudaMalloc(\u0026d_y, N*sizeof(float));\n\n  for (int i = 0; i \u003c N; i++) {\n    x[i] = 1.0f;\n    y[i] = 2.0f;\n  }\n\n  cudaMemcpy(d_x, x, N*sizeof(float), cudaMemcpyHostToDevice);\n  cudaMemcpy(d_y, y, N*sizeof(float), cudaMemcpyHostToDevice);\n\n  // Perform SAXPY on 1M elements\n  saxpy\u003c\u003c\u003c(N+255)/256, 256\u003e\u003e\u003e(N, 2.0f, d_x, d_y);\n\n  cudaMemcpy(y, d_y, N*sizeof(float), cudaMemcpyDeviceToHost);\n\n  float maxError = 0.0f;\n  for (int i = 0; i \u003c N; i++)\n    maxError = max(maxError, abs(y[i]-4.0f));\n  printf(\"Max error: %f\\n\", maxError);\n\n  cudaFree(d_x);\n  cudaFree(d_y);\n  free(x);\n  free(y);\n}\n```\n\n Next, use nvcc the Nvidia CUDA compiler to compile the code and run the newly compiled binary: \n\n ```bash\n$ nvcc -o hello hello.cu \n$ ./hello \nMax error: 0.000000\n```\n\n## Refrences\n\n - [How to install CUDA on Ubuntu 20.04 Focal Fossa Linux](https://linuxconfig.org/how-to-install-cuda-on-ubuntu-20-04-focal-fossa-linux)\n - [How to install the NVIDIA drivers on Ubuntu 20.04 Focal Fossa Linux](https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-20-04-focal-fossa-linux)\n - [An Easy Introduction to CUDA C and C++](https://developer.nvidia.com/blog/easy-introduction-cuda-c-and-c/)\n - [Bong-Soo Sohn](http://cau.ac.kr/~bongbong/cg14/)\n - [CUDA C/C++ Basics](https://www.nvidia.com/docs/IO/116711/sc11-cuda-c-basics.pdf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimani-dev%2Fcuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslimani-dev%2Fcuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimani-dev%2Fcuda/lists"}