SlideShare a Scribd company logo
1 of 31
Intel®HLS Compilerで
SHA256アクセラレータを
作ったら微妙に失敗した
竹村 幸尚
Intel®HLS Compilerで
SHA256アクセラレータを
作ったら微妙に失敗した
竹村 幸尚
がっかりポイント
• VivadoHLS使ったこと無いです
• なので両ツールの比較、的な視点では喋れません
• まあ仮に使ったことあったとしても喋れないわけですが…
背景
• 今PACが熱い!(局所的に)
• PAC(Programmable Acceleration Card)とは
• Intel®ブランドで提供されるアクセラレーション向け量産カード
• 例えばデルでサーバ買うとオプションでFPGAカードをつけられる未来がすぐ
そこに
• チップビジネスから
ボードビジネスへ?
NVIDIA
に!!
と言ったとか言わなかったとか(言ってない)
背景
• PACで動くデザインサンプル作ったろ
• 前にSHA-1とかやったし、次はSHA-256あたりが良いんじゃ
ね?(適当)
• まあOpenSSLあたりからコード引っ張ってくればいいし、簡単
だろ(適当)
• 回路がんがんパラ化すれば超速いんじゃね?(適当)
本題
• Intel® HLS Compilerとは
• Quartus®Prime Pro/Standard/Lite 17.1から標準添付
• 追加ライセンス不要
• Lite EditionももちろんOK
• クォータスと呼んでくださいね
• untimedのC/C++コードをRTLに高位合成
• 最適化・高速化は以下で行う
• コード自体の修正
• #pragma
• attribute
• 入出力最適化
• コマンドラインオプション
• Quartus®のGUIとは連携なし
• Platform Designer(旧Qsys)は使います
思想
• コンパイル時のコマンドをg++からi++に変えるだけでHWが出
来る!
• なのでコマンド名はi++
• なのでコマンドラインオプションも割と共通
• 開発ツールもg++用のを使えば良いじゃん!
• gdbとか
• Valgrindとか
余談
• SHA256について
• メッセージダイジェスト・暗号学的ハッシュ関数の一種
• MD5とかSHA-1とかの仲間
• ロイヤルティフリー
• Federal Information Processing Standards Publication 180-2なるドキュメントを見
るべし
• 計算方法が割とそのまんま書いてある
• OpenSSLとかの実装をそのまま使うのはかえって面倒くさいかも
• 権利関係とかさ
• 512bitのチャンクに分割して計算していく
• Paddingが重要
• 単にzero paddingとかしちゃうとハッシュじゃなくなるもんね
続き
• 関数(FIPS180-2より)
続き
• Hash計算(FIPS180-2より)
For i = 1 to N(ブロック数)
{
<処理1>
For t = 0 to 63
{
<処理2>
<処理3>
}
<処理4>
}
続き
• 処理1
• ワーク変数初期化
• Hは最初に決められた初期値で初期化
For i = 1 to N(ブロック数)
{
<処理1>
For t = 0 to 63
{
<処理2>
<処理3>
}
<処理4>
}
続き
• 処理4
• ワーク変数書き戻し
For i = 1 to N(ブロック数)
{
<処理1>
For t = 0 to 63
{
<処理2>
<処理3>
}
<処理4>
}
続き
• 処理2
• W設定
For i = 1 to N(ブロック数)
{
<処理1>
For t = 0 to 63
{
<処理2>
<処理3>
}
<処理4>
}
続き
• 処理3
• メインの計算処理
For i = 1 to N(ブロック数)
{
<処理1>
For t = 0 to 63
{
<処理2>
<処理3>
}
<処理4>
}
方針
• 入出力データはストリーミング式にする
• いつだってストリーミングが性能上有利(自分調べ)
• 入力幅はチャンクサイズと同じ512bitとする
• CCI-Pバスと同じ幅
• 超高速になる予感…
• Paddingがちょっとややこしそうなので、別モジュールに切り出し
• ややこしい処理はパイプライン化を阻害しがち
• 初段のモジュールでPaddingし、(512bitブロック×N個)化する
• 次段のモジュールでHash計算
• とりあえずはこの程度の工夫で、後はスペックのまま実装してみる
デモ
結果
• レポートを見てみる
• Initiation Interval (II)は全て1!
• んん??
結果
• レポート曰く
Iteration executed serially across calc_hash.B3. Only a single loop
iteration will execute inside this region due to data dependency on
variable(s)
• これはSerial region…
解説
• Serial regionとは
• ネストされたループで発生
• 内側のループの実行が完了しないと、次の外側のループのイタレーションが回せ
ない状態
• 内側ループのパイプラインのフラッシュを待たなければいけない
• フラッシュ待ち時間が無視出来れば性能上問題ない
• フラッシュ待ちが無視できる状態
• パイプラインのレイテンシが短い
• 内側ループの回数が多い
kernel void test() {
int a[1024];
while (i<M) {
for ( j=0; j<N; j++) {
a[X] = b[X];
process(a);
}
}
}
a[]へのアクセスは、
一つ前の外側ループ
の実行が終わってか
らでないと出来ない
(例)
解説
• Serial regionとは
• ネストされたループで発生
• 内側のループの実行が完了しないと、次の外側のループのイタレーションが回せ
ない状態
• 内側ループのパイプラインのフラッシュを待たなければいけない
• フラッシュ待ち時間が無視出来れば性能上問題ない
• フラッシュ待ちが無視できる状態
• パイプラインのレイテンシが短い (今回は10クロック)
• 内側ループの回数が多い (今回は64回)
今回の実装ではイマイチ
(512bit処理に64+10サイクルかかる & パラ化は無理)
考察
• そりゃそうだよね。暗号だもんね。
• 簡単に高速化されたらあっという間にクラックされちゃうよね
• 工夫の余地があるのか??世間はもっとうまいことやっている
のか?
• 世間のSHA-256実装の工夫は、もっぱらCPUの命令にうまく当たるよ
うに分解しているだけの話のような…
• HW化の際はあまりそこ関係ない
• CPUの命令に綺麗に当たるように書いてもFPGAは知らんがなという話
世間
• 見つけた
• IP屋さんと言えばCAST
世間
世間
世間
=7bit/clk
世間
=7bit/clk
73.14clock/512bit…
理想
• 理想
$ time sha256sum hogehoge
real 0m10.000ms
$ time sha256sum_fpga hogehoge
real 0m1.000ms
• FPGA早い!
• 現実
• CPUよりかなり遅い
• 最後まで実装する気失せた
反省
• じゃあFPGAでSHA-256は意味がないのか??
反省
• じゃあFPGAでSHA-256は意味がないのか??
• そんなことはない!
• 1ファイルのハッシュ値取得レイテンシをCPUと競っても負ける
• 複数のファイルを同時に扱えばよい
• 回路のパラレル化が有効になる
• 今回の回路はとても小さい
• Arria10の1%以下
• PCIEボトルネックまで持っていけるはず
• パイプラインも詰められる
締め
• ちゃんと考えてから設計しよう
• CPUアクセラレーションは簡単ではないです!
• Intel® HLS Compilerをどうぞよろしく
• 既にRTLに性能ポータビリティなんぞ無いですよ!!
• untimedだからこその性能ポータビリティ

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Intel®HLS CompilerでSHA256アクセラレータを作ったら微妙に失敗した

Editor's Notes

  1. 好きなIDEを使おう