Skip to content

Instantly share code, notes, and snippets.

@Macorreag
Last active October 2, 2020 21:53
Show Gist options
  • Save Macorreag/376e4812b15eb2e8eb49b793a74e0120 to your computer and use it in GitHub Desktop.
Save Macorreag/376e4812b15eb2e8eb49b793a74e0120 to your computer and use it in GitHub Desktop.
GPU of Colab.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "GPU of Colab.ipynb",
"provenance": [],
"private_outputs": true,
"collapsed_sections": [],
"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/376e4812b15eb2e8eb49b793a74e0120/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": "QRc8eTEdvEYw"
},
"source": [
"## instalacion de CUDA en Colaboratory\n",
"\n",
"Puede instalar CUDA en su Notebook ejecutando la siguiente celda, tenga presente que la GPU debe estar en el Notebook."
]
},
{
"cell_type": "code",
"metadata": {
"id": "dHnDqdHRubZH"
},
"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",
"\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": "code",
"metadata": {
"id": "68V3Q7Gku_sg"
},
"source": [
"# Probar la instación y que GPU se tiene con el siguiente código:\n",
"\n",
"!echo NVIDIA CUDA AND DRIVES VERIFICATION\n",
"%cd /usr/local/cuda/samples/1_Utilities/deviceQuery/\n",
"!ls\n",
"!make\n",
"!./deviceQuery\n",
"!nvcc vectorAdd "
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "-ScXwjZ0N45x"
},
"source": [
"# Manejo de Archivos\n",
"## Uso de la unidad de Google Drive en Colab\n",
"\n",
"Puede conectar sus archivos de Google Drive en Colab para poder almacenar su código directamente en Google Drive editarlo ahí mismo y facilitar su trabajo."
]
},
{
"cell_type": "code",
"metadata": {
"id": "0UB2yOWOZSJS"
},
"source": [
"## Montaje de la unidad de Google Drive \n",
"from google.colab import drive\n",
"drive.mount('/content/gdrive')"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "7D7jM95QP62V"
},
"source": [
"Una vez este conectada su unidad de Google Drive puede acceder a los archivos de esta con la siguiente celda."
]
},
{
"cell_type": "code",
"metadata": {
"id": "Gr99OH8wVz1w"
},
"source": [
"!cd /content/gdrive\n",
"!ls"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "CdtmbNblQ3AG"
},
"source": [
"Para acceder a la ruta especifica de su código recuerde que debe reemplazar los espacios en la ruta con ```\\``` por ejemplo \n",
"\n",
"```\n",
"!cd /content/gdrive/My\\ Drive/Paralela\\ Codigo/\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "K4Ff0v68O2n-"
},
"source": [
"## Subiendo archivos manualmente\n",
"Si no desea conectar su unidad de Google Drive puede subir los archivos en el entorno con la siguiente celda."
]
},
{
"cell_type": "code",
"metadata": {
"id": "wLpwKJS6Vs7y"
},
"source": [
"from google.colab import files\n",
"\n",
"uploaded = files.upload()\n",
"\n",
"for fn in uploaded.keys():\n",
" print('User uploaded file \"{name}\" with length {length} bytes'.format(\n",
" name=fn, length=len(uploaded[fn])))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "nN-JNLGRQXyG"
},
"source": [
"# Ejecución de Código\n",
"Para ejecutar el codigo utilice el signo de admiración ```!``` al inicio de cada línea, esto indica que la secuencia sera ejecutada mediante el Bash.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xvqmxu9GRj1J"
},
"source": [
"## Compilación C++"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Rjt5VXlgc-T4"
},
"source": [
"!gcc /content/gdrive/My\\ Drive/Paralela\\ Codigo/deviceQuery.cpp -o deviceQuery"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "3v3PyKxqRnSG"
},
"source": [
"## Compilación CUDA"
]
},
{
"cell_type": "code",
"metadata": {
"id": "nBCZKcvzVzwE"
},
"source": [
"!nvcc /content/gdrive/My\\ Drive/Paralela\\ Codigo/vectorAdd.cu -o vectoradd"
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment