{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":35332,"databundleVersionId":3723648,"sourceType":"competition"},{"sourceId":2378330,"sourceType":"datasetVersion","datasetId":492658},{"sourceId":3739819,"sourceType":"datasetVersion","datasetId":2231132},{"sourceId":3992728,"sourceType":"datasetVersion","datasetId":2369246}],"dockerImageVersionId":30204,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Imports","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom time import time\nfrom sklearn.model_selection import StratifiedKFold\nimport random\nimport joblib\nimport gc #Coletor de lixo\nfrom itertools import combinations as combi\nimport cudf\nimport cupy as cp\nfrom cuml.metrics import roc_auc_score, log_loss\nfrom cuml.model_selection import train_test_split\nimport lightgbm as lgb\nimport matplotlib.pyplot as plt\nimport matplotlib.style as mplstyle #https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html\nfrom matplotlib.lines import Line2D  # for legend handl\nfrom IPython.display import FileLink\nplt.rcParams['agg.path.chunksize'] = 20000\n%matplotlib inline\n\ngc.enable()\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from time import time","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm import tqdm\nt_cpu_list = []\nt_gpu_list = []\nn_min = 10\nn_max = 20000\nlist_samples = [int(x) for x in np.linspace(n_min, n_max, 51)]\nt00 = time()\nfor n_samples in tqdm(list_samples):\n    #print(n_samples)\n    t0 = time()\n    gpu_matrix = cp.random.randn(n_samples, n_samples)\n    out_gpu = cp.linalg.inv(gpu_matrix)\n    t1 = time()\n    t_gpu_list.append(t1-t0)\n\n    t0 = time()\n    cpu_matrix = np.random.randn(n_samples, n_samples)\n    out_cpu = np.linalg.inv(cpu_matrix)\n    t1 = time()\n    t_cpu_list.append(t1-t0)\n\nt11 = time()\nprint(f\"Total Elapsed time: {t11-t00}\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n_samples","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots()\nt_efetivo = [x**2 for x in list_samples]\nax.plot(t_efetivo, t_cpu_list, label = 'CPU')\nax.plot(t_efetivo, t_gpu_list, label = 'GPU')\nax.set_ylabel('Tempo de execução (em segundos)')\nax.set_xlabel('Tamanho efetivo da base')\nax.set_title('Inversão de matriz N x N')\nax.set_yscale('log')\nax.set_xscale('log')\nax.legend()\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}