Last active
June 25, 2020 05:34
-
-
Save mdouze/0d68439ec56fe504cdfa4635e3816da4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import numpy as np\n", | |
| "import os" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "fd = os.open('/tmp/block', os.O_RDWR|os.O_CREAT)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# allocate 60 G of file initialized to 0\n", | |
| "# 60 G should be larger than the amount of RAM but smaller than the available disk space on /tmp\n", | |
| "os.ftruncate(fd, 60 * (1<<30))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "-rwxr-xr-x. 1 matthijs users 64424509440 Jun 24 22:25 /tmp/block\r\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "! ls -la /tmp/block" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "m = np.memmap('/tmp/block', mode='r+')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 12, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "64424509440" | |
| ] | |
| }, | |
| "execution_count": 12, | |
| "metadata": { | |
| "bento_obj_id": "140113145606000" | |
| }, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "m.size" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 13, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "memmap([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", | |
| " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", | |
| " 0, 0, 0, 0, 0, 0], dtype=uint8)" | |
| ] | |
| }, | |
| "execution_count": 13, | |
| "metadata": { | |
| "bento_obj_id": "140112944691280" | |
| }, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "m[:50]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 14, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "step = 1 << 20" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "47565504512 / 64424509440\r" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "for i in range(0, m.size, step): \n", | |
| " print(f'{i} / {m.size}', end='\\r', flush=True)\n", | |
| " m[i:i+step] = 123" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "bento_stylesheets": { | |
| "bento/extensions/flow/main.css": true, | |
| "bento/extensions/kernel_selector/main.css": true, | |
| "bento/extensions/kernel_ui/main.css": true, | |
| "bento/extensions/new_kernel/main.css": true, | |
| "bento/extensions/system_usage/main.css": true, | |
| "bento/extensions/theme/main.css": true | |
| }, | |
| "kernelspec": { | |
| "display_name": "faiss", | |
| "language": "python", | |
| "name": "bento_kernel_faiss" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.7.5+" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment