# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="wniawHP7h34E"
# # Google Colab (GC) - Numba GPU
# -

# Código fonte: gc_nb_gpu.py

# + colab={"base_uri": "https://localhost:8080/"} executionInfo={"elapsed": 222, "status": "ok", "timestamp": 1632527588661, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14Ghzd7UO2EoPv4GHJ2AiwebDPC3evXCqxNZAD2FZ=s64", "userId": "04933934069991532991"}, "user_tz": 180} id="FisGDvbyOQ08" outputId="18348a80-333c-467b-afbe-ae2fa8dff470"
# ! nvidia-smi -L
# -

# ### roda pela primeira vez:

from gc_nb_gpu import stencil
result = stencil(2400)

# ### roda pela segunda vez (usa o que está no cache):

from gc_nb_gpu import stencil
result = stencil(2400)

# ### visualiza o resultado

# %matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(8,8))
plt.imshow(result[600:2200,600:2200], cmap='jet')

import numpy as np
a    = result[600:2200,600:2200]
t    = np.arange(a.shape[0])
x, y = np.meshgrid(t, t)
ax = plt.figure(figsize=(8, 8)).gca(projection='3d')
ax.plot_surface(x, y, a, cmap='jet', rcount=200, ccount=200)
plt.show()

# ---

# # Usando uma grade com 8 x 8 pontos

# + colab={"base_uri": "https://localhost:8080/"} executionInfo={"elapsed": 2460, "status": "ok", "timestamp": 1632515999169, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14Ghzd7UO2EoPv4GHJ2AiwebDPC3evXCqxNZAD2FZ=s64", "userId": "04933934069991532991"}, "user_tz": 180} id="3-JbWmKch34N" outputId="9223ea1d-fa76-47ce-8e5f-a800402d6c96"
from gc_nb_gpu import stencil
result = stencil(8)
# -

# %matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(8,8))
plt.imshow(result, cmap='jet')

t    = np.arange(result.shape[0])
x, y = np.meshgrid(t, t)
ax = plt.figure(figsize=(8, 8)).gca(projection='3d')
ax.plot_surface(x, y, result, cmap='jet')
plt.show()

# ---

# # Grade 24 x 24

# + colab={"base_uri": "https://localhost:8080/"} executionInfo={"elapsed": 2460, "status": "ok", "timestamp": 1632515999169, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14Ghzd7UO2EoPv4GHJ2AiwebDPC3evXCqxNZAD2FZ=s64", "userId": "04933934069991532991"}, "user_tz": 180} id="3-JbWmKch34N" outputId="9223ea1d-fa76-47ce-8e5f-a800402d6c96"
from gc_nb_gpu import stencil
result = stencil(24)
# -

# %matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(8,8))
plt.imshow(result, cmap='jet')

t    = np.arange(result.shape[0])
x, y = np.meshgrid(t, t)
ax = plt.figure(figsize=(8, 8)).gca(projection='3d')
ax.plot_surface(x, y, result, cmap='jet')
plt.show()

# ---

# # Grade 240 x 240

# + colab={"base_uri": "https://localhost:8080/"} executionInfo={"elapsed": 2460, "status": "ok", "timestamp": 1632515999169, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14Ghzd7UO2EoPv4GHJ2AiwebDPC3evXCqxNZAD2FZ=s64", "userId": "04933934069991532991"}, "user_tz": 180} id="3-JbWmKch34N" outputId="9223ea1d-fa76-47ce-8e5f-a800402d6c96"
from gc_nb_gpu import stencil
result = stencil(240)
# -

# %matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(8,8))
plt.imshow(result, cmap='jet')

t    = np.arange(result.shape[0])
x, y = np.meshgrid(t, t)
ax = plt.figure(figsize=(8, 8)).gca(projection='3d')
ax.plot_surface(x, y, result, cmap='jet')
plt.show()



StarcoderdataJupyterScriptsDedupFiltered