Mercurial > hg > Members > yuuhi > slide
view s6/blank.html @ 2:105ba499ae40
commit
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 24 Jun 2014 18:07:06 +0900 |
parents | 3488934d6d23 |
children | 3d5fd010131d |
line wrap: on
line source
<!DOCTYPE html> <html> <head> <meta charset='utf-8'> <title>Seminar</title> <!-- Notes on CSS media types used: 1) projection -> slideshow mode (display one slide at-a-time; hide all others) 2) screen -> outline mode (display all slides-at-once on screen) 3) print -> print (and print preview) Note: toggle between projection/screen (that is, slideshow/outline) mode using t-key Questions, comments? - send them along to the mailinglist/forum online @ http://groups.google.com/group/webslideshow --> <!-- style sheet links --> <link rel="stylesheet/less" href="themes/blank/projection.css.less" media="screen,projection"> <link rel="stylesheet/less" href="themes/blank/screen.css.less" media="screen"> <link rel="stylesheet/less" href="themes/blank/print.css.less" media="print"> <link rel="stylesheet/less" href="blank.css.less" media="screen,projection"> <!-- Notes about less css support - all less stylesheets (*.css.less) need to get listed/loaded first (before the less.js script) - find more info about less.js online @ http://lesscss.org ***** NOTE: less.js browser script currently won’t work if you’re using Google Chrome and the path to your page starts with "file:///" due to a known Chrome issue. (In the developer/js console you will see: XMLHttpRequest cannot load file:///../s6/shared/projection.css.less. Cross origin requests are only supported for HTTP.) --> <!-- add js libs (less, jquery) --> <script src="js/less-1.1.4.min.js"></script> <script src="js/jquery-1.7.min.js"></script> <!-- S6 JS --> <script src="js/jquery.slideshow.js"></script> <script src="js/jquery.slideshow.counter.js"></script> <script src="js/jquery.slideshow.controls.js"></script> <script src="js/jquery.slideshow.footer.js"></script> <script src="js/jquery.slideshow.autoplay.js"></script> <script> $(document).ready( function() { Slideshow.init(); // Example 2: Start Off in Outline Mode // Slideshow.init( { mode: 'outline' } ); // Example 3: Use Custom Transition // Slideshow.transition = transitionScrollUp; // Slideshow.init(); // Example 4: Start Off in Autoplay Mode with Custom Transition // Slideshow.transition = transitionScrollUp; // Slideshow.init( { mode: 'autoplay' } ); } ); </script> <!-- Better Browser Banner for Microsoft Internet Explorer (IE) --> <!--[if IE]> <script src="js/jquery.microsoft.js"></script> <![endif]--> </head> <body> <div class="layout"> <div id="header"></div> <div id="footer"> <div align="right"> <img src="images/concurrency.png" width="200"> </div> </div> </div> <div class="presentation"> <!-- add slides here; example --> <div class='slide cover'> <table width="90%" height="90%" border="0" align="center"> <tr> <td><div align="center"> <h1><font color="#808db5">CeriumにおけるGPUとMultiCore CPUの同時実行</font></h1> </div></td> </tr> <tr> <td><div align="left"> Yuhi TOMARI <script> var date = new Date(); var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); var monthList = new Array("January","February","March","April","May","June", "July","August","September","October","November","December"); document.write(monthList[month]+" "+day+", "+year); </script> <hr style="color:#ffcc00;background-color:#ffcc00;text-align:left;border:none;width:300%;height:0.2em;"> </div></td> </tr> </table> </div> <div class='slide'> <h2>研究目的</h2> <p> 当研究室ではCellおよびLinux、 Mac OSX上で動く並列プログラミングフレームワーク、 Ceriumの開発・改良を行っている。 </p> <p>本研究では新たにGPU上での並列実行に対応し、 ヘテロジニアス(異種混合)環境下でのプログラミングをサポートする </p> <p> GPGPUでは通常のマルチコア<font color="red">CPUとは異なる並列プログラミング</font> と<font color="red">特別なチューニング</font>が必要となる。 そこでCeriumを用いてその差を吸収し、自動的なチューニングを可能にする。 </p> <p> しかし、GPUのみで並列計算を行った場合、Taskによっては並列度が出ない場合がある。 そこでチューニングの一環として、MultiCoreとGPU上での同時実行を可能にする。 </p> </div> <!-- h1.hidden => use heading just for table of contents (toc) --> <div class='slide'> <h2>進捗</h2> <dl> <dt>Scalaで遊んでた</dt> <dt>mallocのお勉強</dt> <dd>kernel reading party(小崎さん)</dd> <dd><a href="http://shelby.tv/video/youtube/0-vWT-t0UHg/the-67th-yokohama-kernel-reading-party">動画</a></dd> <dd><a href="http://www.slideshare.net/kosaki55tea/glibc-malloc">資料</a></dd> </div> <div class='slide'> <h2>mallocってなんだっけ……?</h2> <pre class="code"> void *malloc(size_t size);</pre> <img src="images/malloc.png" width="500"> <ul> <li>mallocはsizeバイト分のメモリを割り当て、ポインタを返す</li> <li>返ってくるのはvoidのポインタなので、戻り値を型でキャストする必要がある</li> <li>中身は初期化されていない</li> <li>確保した領域はfreeを忘れずに</li> </ul> <pre class="code"> char *str = (char*)malloc(length); // 使う型でキャストする</pre> </div> <div class='slide'> <h2>古典的malloc(K&R malloc)</h2> <img src="images/heap.png" width="700"> <ul> <li>使用可能なブロックを繋げたリスト構造、free list (freeされているブロックのlist?) <li>listを使ってメモリを管理 <li>管理領域(header)分だけ多くallocateして、先頭に管理領域を付加 <li>first fit </ul> <hr> <pre class="code"> union header { struct { union header *ptr; // 空きリストの上なら次のブロック unsigned size; // このブロックの大きさ } s; };</pre> </div> <div class='slide'> <h2>First Fit</h2> <p> リストを頭から見ていって、最初に見つけたものを使用するというすごいシンプルな方法。 </p> <img src="images/firstfit.png" width="500"> </div> <div class='slide'> <h2>First Fit</h2> <img src="images/firstfit2.png" width="500"> <p>実は、もう一個先にもっと適切なブロックがあった。こんな場合に対応できない…というか、対応しないのがfirst fit。</p> <p>あまりよくない……</p> </div> <div class='slide'> <h2>free</h2> <pre class="code"> void free(void *ptr);</pre> <p> メモリの開放自体は、使用中のブロックをfree listに追加するだけで良い。 引数で受け取ったポインタ部分を開放したら良い……かに思える。 でもそれだけじゃダメで、開放したい領域と隣接しているブロックが空きブロックなら併合しないといけない。 </p> <img src="images/free_merge.png" width="700"> </div> <div class='slide'> <h2>free</h2> <img src="images/free1.png" width="700"> <p> listから最初のポインタと、その次のポインタを取得。prev < p < nextを満たすまで走査していく </p> </div> <div class='slide'> <h2>free</h2> <img src="images/free2.png" width="700"> <p>あった!!</p> <p> 開放後に前後のメモリと併合する必要がある場合があるので、prevとp・pとnextが隣接してるか判定する。 </p> <ul> <li>(prev+prev-> size) != p なので、隣接していない </li> <li>(p+p-> size) = next なので、隣接している</li> <p>ブロックが隣接している場合は併合する。</p> </div> <div class='slide'> <h2>free</h2> <img src="images/free_after.png" width="700"> <p>チェックに引っかかったところをマージする。</p> </div> <div class='slide'> <h2>古典的malloc & freeまとめ</h2> <p>フラグメンテーションが頻発する。</p> <ul> <li>このmallocが主流だった時は「メモリはプログラムの最初に一気に確保するもの」だった</li> <li>メモリが充分に空いている状態で、 必要なメモリを一気に確保するならフラグメンテーションは起きにくい</li> <li>今はJava・C++のようなオブジェクト指向言語、 Rubyのようなスクリプト言語等、小さいmallocが頻発するものが多い</li> <li>それをfirst fitでやるのはよくない</li> </ul> </div> <div class='slide'> <h2>mallocの改良</h2> <p>そもそも、一つのfree listで管理することが無理がある</p> <p>サイズ16Byte用のリスト、サイズ24Byte用のリスト……というようにリストを複数作ってやる</p> <table border="0"> <tr> <th> <img src="images/free_list_list.png" width="400"> </th> <th valign="top" align="left"> <ul> <li>mallocで要求されたsizeを8で割れば自分が使用するindexとなる</li> <li>無限にリストを増やすわけにはいかないので、このリストを使うのは512バイト以下の場合のみ</li> <li>512バイト以上の大きいデータの場合は、特殊な管理を行う</li> <li>大きいデータと小さいデータを一緒に管理するからフラグメンテーションが進むんだ<br> →大きいデータ用の領域がもう一個欲しい<br>→そうだ、mmapを使おう</li> </th> </tr> </table> </div> <div class='slide'> <h2>mmapってなんだっけ……?</h2> <ul> <li>ファイル(fdで指定したもの)をメモリにマップする</li> <li>fdで"/dev/zero"を指定することでmmapをメモリ確保APIとして使用</li> <li>このAPIを使ってHuge Blockはmmapで直接kernelから取得する</li> </ul> <pre class="code"> void *alloc_mmap(size_t size) { int fd = open("/dev/zero", O_RDONLY); void *ret = mmap(addr, length, prot, flags, fd, offset); return ret; }</pre> <table border="1" > <tr bgcolor="dbffa3"> <th align="left" style="margin:10px 10px 10px;">addr</th><th align="left">mapするメモリアドレス。NULLを渡せばkernelがアドレスを選択する。</th> </tr> <tr bgcolor="palegreen"> <th align="left">length</th><th align="left">addrから何バイトマッピングするか。</th> </tr> <tr bgcolor="dbffa3"> <th align="left" >prot</th><th align="left">マッピングのメモリ保護の指定。Read Write Exec None等がある。</th> </tr> <tr bgcolor="palegreen"> <th align="left">flags</th><th align="left">マップを要求された時、共有するかコピーを渡すか。</th> </tr> <tr bgcolor="dbffa3"> <th align="left">offset</th><th align="left">ファイルの何バイト目からをメモリにマップするか。</th> </tr> </table> </div> <div class='slide'> <h2>Huge Block</h2> <p>mmapで確保するので、free listからは独立している。 <table> <tr> <th> <img src="images/huge_block.png" width="500"> </th> <th valign="top" align="left"> <p> listを使って管理しているわけではないので、listをたどったりしなくて良い。</p> <p> ほしかったらmmapして、いらなくなったらmunmapすればよい。 </p> </th> </tr> </table> <ul> <li>free list上でフラグメンテーションが起きにくくなった(当たり前)</li> <li>メモリの無駄が少ない<br> 大きなメモリは同じサイズでもう一度mallocされる可能性は低いので、 使わなくなったらすぐOSに返却するのは正しい</li> </ul> </div> <div class='slide'> <h2>まとめ</h2> <ul> <li>一見危なそうに見える処理が……</li> <li>HugeBlockをmmapで管理すれば確かに手っ取り早いではあるが、何バイトからをHugeBlockとするかをちゃんと考えないとだめ</li> </ul> <h2>次やること?</h2> <ul> <li>AVLTree</li> <li>2-2n allocator</li> <li>mallocのソースを読む</li> </ul> </div> </div> <!-- presentation --> </body> </html>