Skip to content

Instantly share code, notes, and snippets.

@Macorreag
Last active October 1, 2020 15:59
Show Gist options
  • Save Macorreag/d07cb8937884eea99919751ab56c9d7c to your computer and use it in GitHub Desktop.
Save Macorreag/d07cb8937884eea99919751ab56c9d7c to your computer and use it in GitHub Desktop.
Pi with Cuda.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Pi with Cuda.ipynb",
"provenance": [],
"collapsed_sections": [],
"toc_visible": true,
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/Macorreag/d07cb8937884eea99919751ab56c9d7c/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zZdlR3b2u9fY"
},
"source": [
"## Instalacion de CUDA en Colaboratory\n",
"\n",
"Pasos para ejecutar el codigo en Colab\n",
"\n",
"\n",
"1. Habilitar GPU de Colab y Python 3\n",
"\n",
"\n",
">* Entorno de Ejecucion->Cambiar tipo de entorno de Ejecucion **Python 3**\n",
"\n",
">* Entorno de Ejecucion->Cambiar tipo de entorno de Ejecucion -> Aceleración por hardware **GPU**\n",
"\n",
"\n",
"2. Realizar la instalación de CUDA en Colab \n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "VOUV19BEulRg"
},
"source": [
"!echo CUDA AND NVIDIA INSTALLATION\n",
"!echo NOTE: THERE IS A QUESTION IN THE INSTALLATION, PLEASE DO NOT FORGET TO ANSWER IT (YOU CAN CHOOSE Y)\n",
"!wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb;\n",
"!dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb;\n",
"!apt-get update -qq;\n",
"!apt-get install cuda-8.0;\n",
"!ln -sf /usr/local/cuda-8.0 /usr/local/cuda\n",
"import os\n",
"os.environ['PATH'] += ':/usr/local/cuda/bin'\n",
"os.environ['LD_LIBRARY_PATH'] += ':/usr/local/cuda/lib'\n",
"\n",
"!apt-get install gcc-5 g++-5 -y -qq;\n",
"!ln -s /usr/bin/gcc-5 /usr/local/cuda/bin/gcc;\n",
"!ln -s /usr/bin/g++-5 /usr/local/cuda/bin/g++;\n",
"!pip install git+git://github.com/andreinechaev/nvcc4jupyter.git\n",
"%load_ext nvcc_plugin"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "vwCwGkoGyzIi"
},
"source": [
"## Montar la unidad de Google Drive para almacernar archivos\n",
"\n",
">* Ejecute la siguiente celda, de click en el enlace generado.\n",
">* En la nueva pagina autorice a Colab y copie el codigo y peguelo en la celda que surgio.\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "ptKICgesvkKA"
},
"source": [
"from google.colab import drive\n",
"drive.mount('/content/gdrive')"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Cq0cbWGDzj-j"
},
"source": [
"## Detecte el archivo que desea compilar y coloque la ruta"
]
},
{
"cell_type": "code",
"metadata": {
"id": "68sKvDyBzzKD"
},
"source": [
"!nvcc /content/gdrive/My\\ Drive/INGENIERIA\\ DE\\ SISTEMAS\\ DOC/Decimo\\ Semestre/Paralela\\ Y\\ Distribuida/Files/CUDA/pi/piCUDA.cu -o result"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "e0d1i85t26im"
},
"source": [
"## Ejecute el compilado que genero"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Vol_gkxd2-jw"
},
"source": [
"!./result 1000"
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment