Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
EXLAでcudaが動作する環境の構築と実際にNxで動かしたデモ
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
GeekMasahiro
November 10, 2022
Programming
320
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
EXLAでcudaが動作する環境の構築と実際にNxで動かしたデモ
Nxバックエンド勉強会#7
EXLAでcudaが動作する環境の構築と実際にNxで動かしたデモ
GeekMasahiro
November 10, 2022
Transcript
15 slides
EXLAでcudaが動作する 環境の構築と実際にNx で動かしたデモ @GeekMasahiro
自己紹介 Twitter/Qiita @GeekMasahiro 会社員 自社サービスのソフトウエア開発、運営( AWS, Python, vue.js等) 趣味 Elixir、電子工作全般、ソーラー発電、 3DPrinter Elixirを2022年7月に出会って、趣味に追加。楽しいので本業にも活用したい。
2
今回の目標 目標 • NxにEXLAを導入してGPUで演算を行えるようにする 環境 • nvidiaのGPU(RTX3060)を使用 • Windows11のWSL環境で使用する 3
GPU購入 NxでGPUを使ってみたい! Ethereumのマイニングが終わって価格 も戻ってきた 買いしました。 4
GPU取り付け 大きさ的に、内蔵できなかったので、 PCIeの延長 ケーブルを購入して外置き GPU用の電源も購入 PCの電源と連動する仕組みは電子工作。 5
ドライバーインストール(Windows側) https://developer.nvidia.com/cuda/wsl 6
WSL側の環境構築 nvidia社のドキュメントにWSL環境についての記述がある。この通りで動作する。 https://docs.nvidia.com/cuda/wsl-user-guide/index.html#getting-started-with-cuda-on-wsl CUDA Toolkit 11.8 Downloads(内容は同じ) https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distri bution=WSL-Ubuntu&target_version=2.0&target_type=deb_network 7
EXLAで使う場合の注意 sudo apt-key del 7fa2af80 wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin sudo mv cuda-wsl-ubuntu.pin
/etc/apt/preferences.d/cuda-repository-pin-600 sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/3bf863cc.pub sudo add-apt-repository 'deb https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/ /' sudo apt-get update sudo apt-get -y install cuda=11.1.0-1 #バージョン指定する 最新のバージョン(1.1.8だとうまく動作しない)ので、 11.1.0-1を指定 xlaのissue報告中。https://github.com/elixir-nx/xla/issues/23 8
動作確認 Mix.install([ {:nx, "~> 0.3.0"}, {:exla, "~> 0.3.0"}, ], config:
[ nx: [ default_backend: EXLA.Backend, default_defn_options: [compiler: EXLA], ] ], system_env: [ XLA_TARGET: "cuda111" ], force: false, ) Nx.add(Nx.tensor([1]), Nx.tensor([1])) iexのプロンプトで実行 9
実行結果 cudaで作成されている 10
デモ • Config.exsの働き • cpu/cudaでの速度比較 • GPUが動いている様子を観察 11
EXLAを使用する設定 import Config config :nx, :default_backend, EXLA.Backend config :nx, :default_defn_options,
compiler: EXLA 12
XLA_TARGETの指定 export XLA_TARGET=cuda111 mix deps.clean --all rm -Rf ~/.cache/xla/ mix
deps.get iex -S mix cpuを使う場合は、XLA_TARGET=cpu ※変更した場合、deps.cleanが必要。~/.cache/xla/を削除しないとEXLAのコンパイルエラーになる。 13
GPU動作状況の確認(nvidia-smi) 14
速度比較 200x200,2000x2000の単位行列の内積の演算時間を比較 条件 200x200 Exla使用しない 2.03sec cpu 0.0752sec rate 26倍
条件 2000x2000 cpu 12.4sec cuda 0.911us rate 13.6倍 15
More Decks by GeekMasahiro
See All by GeekMasahiro
FPGA と CPU のシステムを まるごと Elixir で
geekmasahiro
0
98
Other Decks in Programming
See All in Programming
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
300
あなたはMCPの機能を、まだ知らない。
4geru
1
740
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
190
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
170
Agentic AI with the Power of Jakarta EE
ivargrimstad
0
220
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
410
How SRE Grew Out of Server-Side Work and Became the Team's Own / サーバサイドから始まったSREを チームに渡すまで
maaaato
1
260
はじめてのPLATEAU
nokonoko1203
1
670
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
640
祈るテストから、探索するテストへ 〜Lincheckではじめる並行処理テスト〜
yyh_gl
0
430
Math.sumPreciseから学ぶ、ECMAScript仕様の数値の種類
syumai
0
350
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
410
Marketing to machines
jonoalderson
1
6k
Practical Orchestrator
shlominoach
192
12k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Google's AI Overviews - The New Search
badams
0
1.7k
Amusing Abliteration
ianozsvald
1
400
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Paper Plane (Part 1)
katiecoart
PRO
3
12k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
850
Ethics towards AI in product and experience design
skipperchong
2
470
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k