2023年4月26日に開催した、「実践的!FPGA開発セミナーvol.21」の当日資料です。
Copyright© Fixstars Group実践的!FPGA開発セミナーvol.212023/04/26 18:00~1
View Slide
Copyright© Fixstars GroupAI Engine によるテンプレートマッチング高速化手法の解説2
Copyright© Fixstars GroupWho I am写真HirokiNISHIMOTO西本 宏樹ソリューション第四事業部 エンジニア3
Copyright© Fixstars Groupアウトライン- AI Engineとは?- テンプレートマッチングの紹介- 実装にあたっての7つのステップ- まとめ4
Copyright© Fixstars Groupアウトライン- AI Engineとは?- テンプレートマッチングの紹介- 実装にあたっての7つのステップ- まとめ5
Copyright© Fixstars GroupAI Engineとは?- AMD社によって開発されたプロセッサ- 電力効率が良い & 演算処理が高速- PL(FPGA)とAXI4-Streamで接続されている6※ https://japan.xilinx.com/products/technology/ai-engine.htmlより引用※ ACAP概要図→ FPGA + AI Engineでより高速に演算が可能に
Copyright© Fixstars Groupどんなアーキテクチャか- 強力なベクトル演算ユニットを搭載- 沢山のAI Engineコアが接続されたAIE Arrayで構成されている- データ処理→次のコアへ流す→ マルチコアの並列性とパイプラインを兼ね備えたアーキテクチャ応用範囲はAIだけではない7※ https://japan.xilinx.com/products/technology/ai-engine.htmlより引用※※
Copyright© Fixstars Groupどういう構成なのか- ホストからメモリを介してPL→AIE Arrayに送る- PL->AIE Arrayの送信方法はAXI4-Stream8AIE Array ※※ https://japan.xilinx.com/products/technology/ai-engine.htmlより引用
Copyright© Fixstars Groupアウトライン- AI Engineとは?- テンプレートマッチングの紹介- 実装にあたっての7つのステップ- まとめ9
Copyright© Fixstars Groupテンプレートマッチングとは?画像の一部を切り出したものから、その一部が切り出し元の画像のどの位置かを探索するタスクテンプレート画像元画像10応用事例)- 深度推定- 物体追跡
Copyright© Fixstars Groupどういうアルゴリズムを使用する?色々あるが、今回はSAD(Sum of Absolute Difference)を採用テンプレートのサイズと同じ枠を走査し、画素間の差異が最小の位置を探索する。元画像11
Copyright© Fixstars Groupアウトライン- AI Engineとは?- テンプレートマッチングの紹介- 実装にあたっての7つのステップ- まとめ12
Copyright© Fixstars GroupテンプレートマッチングのAI Engineへの落とし込みAI Engine① テンプレート画像のAIEへのロード② 検証対象データのAIEへのロード③ AIE内部でSADを計算結果をホストへ送信④13
Copyright© Fixstars Group実装にあたっての7つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation or 実機での動作確認14
Copyright© Fixstars Group実装にあたっての7つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation8. 実機での動作確認15
Copyright© Fixstars Groupリファレンスプログラムの実装16元・テンプレート画像読み込みグレースケール化SAD計算終了for( int hi = 0 ; hi < SRC_H - TMP_H ; ++hi ){for( int wi = 0 ; wi < SRC_W - TMP_W ; ++wi ){// 検証範囲を切り出しuint8_t *ins_img_gray = cut_img();// sad score計算関数実行uint32_t score = sad_part(ins_img_gray,tmp_img_gray,TMP_SIZE)best_score = max(score, best_score);}}
Copyright© Fixstars GroupSAD値計算部分概要uint32_t sad_part(const uint8_t *src, const uint8_t *tmp, const uint32_t TMP_SIZE){uint32_t score = 0;for( uint32_t idx = 0 ; idx < TMP_SIZE ; ++idx ){const uint8_t comp_src_val = src[ idx ];const uint8_t comp_tmp_val = tmp[ idx ];if( comp_src_val >= comp_tmp_val )score += (comp_src_val - comp_tmp_val);elsescore += (comp_tmp_val - comp_src_val);}return score;}元画像とテンプレート画像の全ピクセルを走査し、2つの画像の差異を取得17
Copyright© Fixstars Group実装にあたっての8つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation or 実機での動作確認18
Copyright© Fixstars GroupテンプレートマッチングのAI Engineへの落とし込みAI Engine① テンプレート画像のAIEへのロード② 検証対象データのAIEへのロード③ AIE内部でSADを計算結果をホストへ送信④19
Copyright© Fixstars GroupAIEへの落とし込み(入力部分)void compute_krnl( input_stream* dat, output_stream* out){aie::vector tmp_vecs[READ_NUM];for ( itr_t i = 0 ; i < READ_NUM ; ++i )tmp_vecs[i] = readincr_v(dat);while(true){uint32_t sad_val = 0;for( itr_t bi = 0 ; bi < READ_NUM ; bi++ ){aie::vector src_vec = readincr_v(dat);const uint32_t score = compute_score( src_vec, tmp_vecs[bi]);sad_val += score;}writeincr(out, sad_val);}}20テンプレートデータを入力切り出した元画像を入力し、差異を計算テンプレートサイズ画像と同ピクセル計算した後、出力
Copyright© Fixstars GroupSADカーネルの実装 -aie::vectorをフル活用する-……検証対象画像テンプレート…大小マスク……大きい方のベクタ小さい方のベクタ…絶対値差分のベクタ絶対値差分の総和aie::vector関数を活用して高速化21
Copyright© Fixstars GroupAIEへの落とし込み(画素の差異の計算)uint32_t compute_score(aie::vector src_vec,aie::vector tmp_vec){auto msk_lt = aie::lt( src_vec, tmp_vec );aie::vector grt_vec = aie::select(src_vec, tmp_vec, msk_lt );aie::vector les_vec = aie::select(tmp_vec, src_vec, msk_lt );uint32_t score = 0;aie::vector sub_vec = aie::sub(grt_vec, les_vec);aie::vector red_vec; // reduce用の配列. 16bitfor( itr_t wi = 0; wi < READ_BYTE_SIZE/2; ++wi )red_vec[wi] = sub_vec[wi] + sub_vec[wi + READ_BYTE_SIZE / 2];score = aie::reduce_add(red_vec);return score;}大小のマスクを取得対応ピクセルごとに大小を分ける大きい方から小さい方を引いた値を取得差をreduceで計算22
Copyright© Fixstars Group実装にあたっての8つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation or 実機での動作確認23
Copyright© Fixstars GroupAI Engine Graphでカーネル同士を繋ぎフローを作成2入力を受け取り、その和を出力するカーネルを作成し先ほどのカーネルを並列化24
Copyright© Fixstars GroupAI Engine Graphでカーネル同士を繋ぎフローを作成class compute_graph : public adf::graph {private :adf::kernel krnl;public :adf::port dat_in;adf::port res_out;compute_graph(){krnl = adf::kernel::create(compute_krnl);adf::source(krnl) = "../src/compute_krnl.cpp"; // カーネル読み込みadf::connect(dat_in, krnl.in[0]);adf::connect(krnl.out[0], res_out);adf::runtime(krnl) = 1.0;};};25入出力ポートカーネル入力→カーネル→出力
Copyright© Fixstars GroupAI Engine Graphでカーネル同士を繋ぎフローを作成// 0段目for( itr_t ii = 0 ; ii < PARALLEL_NUM / 2 ; ++ii ){adf::connect( reduce_in[ii * 2 ] , krnl[ii].in[0]);adf::connect( reduce_in[ii * 2 + 1 ], krnl[ii].in[1]);}// 中段uint32_t ofs = 0;for( itr_t pi = PARALLEL_NUM / 2; pi > 1; pi = pi >> 1 ){for( itr_t ii = 0 ; ii < pi; ++ii)adf::connect( krnl[ ii + ofs ].out[0], krnl[ ii / 2 + ofs + pi].in[ ii % 2 ]);ofs += pi;}// 最終段adf::connect( krnl[ PARALLEL_NUM - 1 - 1 ].out[0] , reduce_out );26
Copyright© Fixstars Group実装にあたっての8つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation8. 実機での動作確認27
Copyright© Fixstars GroupAI Engine『だけ』のシミュレーション各ポートへの入力ファイルを用意するだけで、AI Engine部分だけのシミュレーションが可能!ここだけ!ここでテストを通しておけば安心して以降の実装に進める19232019773648631153301556321629314034433535452630135262715415996238161095908160……input_0.txt8bit × 4 = 3228
Copyright© Fixstars Groupシミュレーションの出力?=ホストプログラムなしで出来るので、問題の切り分けが楽期待値 シミュレーション出力29
Copyright© Fixstars Group実装にあたっての8つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation or 実機での動作確認30
Copyright© Fixstars GroupAI Engineとホストを繋ぐ、PLの実装31
Copyright© Fixstars GroupAI Engineとホストを繋ぐ、PLの実装void mm2s( ap_uint<32>* mem, hls::stream>& str, int size ) {for (int i = 0; i < size; i++) {ap_axiu<32, 0, 0, 0> x;x.data = mem[i];x.keep = -1; // バイトイネーブルのフラグをすべて立てるstr.write(x);}}void s2mm( ap_uint<32>* mem, hls::stream>& str, int size) {for (int i = 0; i < size; i++){auto x = str.read();mem[i] = x.data;}}32
Copyright© Fixstars Group実装にあたっての7つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation or 実機での動作確認33
Copyright© Fixstars GroupリファレンスのC++実装に何を足せばAI Engineを使えるのか1. デバイスオープン2. xclbinをデバイスに書き込み3. カーネルの作成4. バッファオブジェクトの作成5. ホスト側のバッファポインタをユーザー空間にマップ6. バッファへのデータ書き込み&ホストからデバイスバッファへの内容の同期7. カーネルの起動&完了待機8. デバイスからホストへバッファの内容を同期34
Copyright© Fixstars Group1&2. デバイスオープン&xclbinの書き込み35const int device_index = 0;const std::string xclbin_file = argv[1];auto device = xrt::device(device_index); // デバイスのオープンauto uuid = device.load_xclbin(xclbin_file); // xcl_binのデバイスの書き込み用意されている関数に渡すだけです
Copyright© Fixstars Group3. カーネル作成36// PARALLEL_NUM 並列でのカーネル送信作成std::vector< xrt::kernel > mm2s_krnls;for(itr_t pi = 0; pi < PARALLEL_NUM ; pi++ ){mm2s_krnls.push_back(xrt::kernel(device, uuid, "mm2s:{mm2s_" + std::to_string(pi + 1) + "}"));}// 受信カーネルの作成auto s2mm_krnl = xrt::kernel(device, uuid, "s2mm:{s2mm_1}");用意されている関数をほぼ叩くだけでできます
Copyright© Fixstars Group4. バッファオブジェクト作成37// PARALLEL_NUM並列での送信用バッファの作成std::vector< xrt::bo > mm2s_bos;for(itr_t pi = 0; pi < PARALLEL_NUM ; pi++ ){mm2s_bos.push_back( xrt::bo(device, sizeof(uint8_t) * IMG_SIZE / PARALLEL_NUM, mm2s_krnls[pi].group_id(0)) );}// 受信用バッファオブジェクトの作成auto s2mm_bo = xrt::bo(device, sizeof(uint32_t) * TRIAL_CNT, \s2mm_krnl.group_id(0));欲しいサイズをbyte単位で指定するだけでできます
Copyright© Fixstars Group5. ホスト側のバッファポインタをユーザー空間にマップする38// PARALLEL_NUM並列での送信用バッファの作成std::vector mm2s_mapd_bufs;for(itr_t pi = 0; pi < PARALLEL_NUM ; pi++ ){mm2s_mapd_bufs.push_back( mm2s_bos[pi].map() );}// 受信用バッファオブジェクトのマップauto s2mm_mapd_buf = s2mm_bo.map();バッファオブジェクトのmap関数を叩くだけです
Copyright© Fixstars Group6. バッファへのデータ書き込み&ホストからデバイスバッファへの内容の同期39// マップした送信用バッファへのデータを書き込みfor ( itr_t pi = 0 ; pi < PARALLEL_NUM ; pi++ ){const uint32_t SIZE_PER_UNIT = IMG_SIZE / PARALLEL_NUM;const uint32_t OFS = SIZE_PER_UNIT * pi;for( int bi = 0; bi < SIZE_PER_UNIT ; bi++ ){mm2s_mapd_bufs[pi][bi] = tmp_img_gray[ bi + OFS ];}}for ( itr_t pi = 0 ; pi < PARALLEL_NUM ; pi++ )mm2s_bos[pi].sync(XCL_BO_SYNC_BO_TO_DEVICE); // 同期書き込んで同期関数を叩くだけです
Copyright© Fixstars Group7. カーネルの起動&完了待機40std::vector< xrt::run > mm2s_runs;for ( itr_t pi = 0 ; pi < PARALLEL_NUM ; pi++ ){mm2s_runs.push_back (mm2s_krnls[pi]( mm2s_bos[pi], nullptr, sizeof(uint8_t)* IMG_SIZE / PARALLEL_NUM / 4) );}for ( itr_t pi = 0 ; pi < PARALLEL_NUM ; pi++ )mm2s_runs[pi].wait(); // カーネル終了の待機3で作ったカーネルにbuffer objectと『何回実行してほしいか』を渡すだけです
Copyright© Fixstars GroupリファレンスプログラムのAIE 対応41元・テンプレート画像読み込みグレースケール化SAD計算終了[AIE 準備][テンプレート画像送信][s2mm 受信開始]for( int hi = 0 ; hi < SRC_H - TMP_H ; ++hi ){for( int wi = 0 ; wi < SRC_W - TMP_W ; ++wi ){[ mm2s送信処理(一枚ずつ) ]}}[s2mm 受信待機]
Copyright© Fixstars Group実装にあたっての7つのステップ1. リファレンスプログラムの実装2. AI Engine上で動作するカーネルの実装3. AI Engine Graphの実装4. AI Engineのシミュレーション5. AI Engineとホストを繋ぐ、PLの実装6. ホストプログラムを書く7. HW Emulation or 実機での動作確認42
Copyright© Fixstars Groupホストを含めたHW Emulation実機で動かないときも波形で確認できる合成後、ホストで先に実行したが期待値一致しなかったためHW Emulationで波形で確認した43
Copyright© Fixstars Group動作確認- 期待値との一致を確認44元画像 テンプレート画像 出力画像- 速度検証CPU : 600 msAIE : 7000ms
Copyright© Fixstars Group改良 ホスト→AIE の送信を減らす45元・テンプレート画像読み込みグレースケール化SAD計算終了[AIE 準備][テンプレート画像送信]for( int hi = 0 ; hi < SRC_H - TMP_H ; ++hi ){for( int wi = 0 ; wi < SRC_W - TMP_W ; ++wi ){[検証用元画像格納]}}[s2mm 受信開始][mm2s送信処理 (全部) ][s2mm 受信待機]AIE : 650 ms
Copyright© Fixstars Groupアウトライン- AI Engineとは?- テンプレートマッチングの紹介- 実装にあたっての7つのステップ- まとめ46
Copyright© Fixstars Groupまとめ- AI Engineでテンプレートマッチングを実装- 実機で動かすまでの7ステップの解説- 動かなかった際のデバッグは大変ですが、シミュレーションが充実しているので追える- 今後、カーネルの変更含め、最適化します47
Copyright© Fixstars GroupLightning Talk!48
Copyright© Fixstars GroupAI Engine 適用例の解説~FFT 演算の実装~49
Copyright© Fixstars GroupWho I am写真RyujiNISHIDA西田 竜之ソリューション第四事業部 シニアエンジニア50
Copyright© Fixstars Group自己紹介● 西田竜之○ FPGAを用いたシステム開発に従事○ ハードウェア開発をメインに担当○ 略歴■ 半導体ベンダ● サーバー向けASIC開発■ 映像事務機メーカー● 高画質エンジンLSI 映像機器向けFPGA開発■ フィックスターズ● FPGAを用いた高速取引金融システム● OpenCLによるアプリの高速化51
Copyright© Fixstars Groupアジェンダ● AI Engine FFT 演算 背景&目的● 単一カーネルでの FFT の実装● 複数カーネルを用いた FFT の実装● 参考:AMD 提供サンプルデザイン(XAPP1356)の実装● まとめ52
Copyright© Fixstars GroupAI Engine FFT 演算 背景&目的● Versal AI Engine○ 演算負荷の高いアプリケーションに有用○ 性能を発揮するには・・・■ AI Engine に適したアルゴリズムとプログラミングが必要■ AI Engine のアーキテクチャ、特徴の把握が必要● FFT 演算○ 演算負荷の高い代表的なアプリケーションの1つ■ AI Engine FFT 演算は、DSP Library を用いてすでに利用可能今回、AI Engine の理解を深めるために、なじみのある FFT 実装を題材に試行した結果を共有する53
Copyright© Fixstars GroupAI Engine FFT 演算 背景&目的● FFT 演算(図:時間間引き16点)○ 演算(複素数の加算、乗算)⇒ メモリ保持(データ並び替え)⇒ … の繰り返し○ 演算全体を時間的、空間的にどう割り付けるかによって構成が変わる54データ数分繰り返しO(N)stage 数分繰り返し O(logN)
Copyright© Fixstars Group単一カーネルでの FFT 実装● データ型:単精度複素数○ cfloat 型を使用する ⇒ 複素数演算の記述が容易に可能■ .real, .imag で実部、虚部にアクセスする● AI Engine メモリ容量○ 1コア辺りのデータメモリ 32KByte○ 隣接する4コアのメモリを共有可能 Total 128KByte● FFT データ点数 1024点○ 入出力、中間のバッファが必要(4 ケ程度)○ 8Byte (=sizeof(cfloat)) x 1024 点 x ~4ケ < 32KByte※ 隣接コアのメモリを使用すれば、これより大きな点数も実現できる可能性はある(未試行)55参照URLhttps://docs.xilinx.com/r/ja-JP/am009-versal-ai-engine/AI-%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3%E3%81%AE%E3%83%A1%E3%83%A2%E3%83%AA-%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB
Copyright© Fixstars Group単一カーネルでの FFT 実装● カーネルコード56← Butterfly演算 &並び替え10 stage分繰り返しWindowアクセス(=共有メモリを介した転送)● グラフコード外部 I/F からWindowアクセスするための接続
Copyright© Fixstars Group単一カーネルでの FFT 実装● 演算機能(バタフライ演算)の記述○ AI Engine Intrinsicsより高速、効率的な動作をさせるには、Intrinsics を利用するhttps://www.xilinx.com/htmldocs/xilinx2022_2/aiengine_intrinsics/intrinsics/index.html■ ベクタ演算エンジンの利用、パイプライン動作など■ FFT 用の Intrinsics も存在ただし、cfloat 対応の FFT 演算が見当たらない、仕様理解に時間がかかる(難解)ため、今回未適用○ AI Engine APIIntrinsics よりも抽象度の高い C++ ヘッダライブラリhttps://www.xilinx.com/htmldocs/xilinx2022_2/aiengine_api/aie_api/doc/index.html■ fft_dit も使用可能適用を試みたが期待通りの演算ができず適用断念パラメータ、入出力データ設定を探ったものの、適切な使い方がつかめなかった57参照URLhttps://japan.xilinx.com/developer/articles/aie-kernel-programming-vitis-aie-api.html
Copyright© Fixstars Group単一カーネルでの FFT 実装● FFT 1000 point プロファイル結果 (aiesimulator 実行)○ 演算実行サイクルで埋まっている 効率的に演算を実行させる工夫が必要58Total 5,720,000 cycle= 5.72msec @ 1GHz(拡大)
Copyright© Fixstars Group複数カーネルでの FFT 実装● カーネル分割○ 共有メモリを介してカーネルを直列に接続○ 連続したデータ投入でもスループットを確保できる構成59データ数分繰り返しO(N)stage 数分カーネルを直列に配置参照URLhttps://docs.xilinx.com/r/ja-JP/am009-versal-ai-engine/%E5%85%B1%E6%9C%89%E3%83%A1%E3%83%A2%E3%83%AA%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%9F-AI-%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3%E3%81%8B%E3%82%89-AI-%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3%E3%81%B8%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E9%80%9A%E4%BF%A1
Copyright© Fixstars Group● カーネルコード複数カーネルでの FFT 実装60← Butterfly演算 &並び替え2 stageずつ5 ケのカーネルに分割
Copyright© Fixstars Group複数カーネルでの FFT 実装61● グラフコードカーネル間をWindowアクセスするための接続5 カーネル分を作成
Copyright© Fixstars Group複数カーネルでの FFT 実装62● コンパイル結果○ グラフ接続○ タイル配置■ 配置指定はせず、自動で配置
Copyright© Fixstars Group複数カーネルでの FFT 実装63● FFT 1000 point プロファイル結果 (aiesimulator 実行) Total 5,714,000 cycle= 5.71msec @ 1GHzカーネル間で順番に処理している自動で同期をとりながら動作できている(カーネルコードは独立に記述し、グラフ接続しているだけ)※単一カーネルと同じ連続したデータ投入ができていないため、カーネル分割した利点が見えていない ↓スループットの改善効果は実機で確認する必要がある
Copyright© Fixstars Group● FFT カーネル並列化方式の検討○ 試行した構成○ 別構成案■ スループットは同等、カーネルはシンプル、タイル配置の自由度も高い(これでよかったのでは?)■ AI Engine は比較的新しいデバイスなので、最適構成を探る余地は大きい複数カーネルでの FFT 実装64
Copyright© Fixstars Group参考:AMD 提供サンプルデザイン(XAPP1356)の実装65● ブロックごとにコンフィギュレーション可能な高速フーリエ変換の AI エンジンでの実装○ 1024 point FFT x4 カーネルから共有メモリを介して結果を集約する構成参照URLhttps://docs.xilinx.com/r/ja-JP/xapp1356-fft-ai-engine/%E8%A4%87%E6%95%B0%E3%81%AE-AI-%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3%E3%81%AB%E3%82%88%E3%82%8B-FFT
Copyright© Fixstars Group参考:AMD 提供サンプルデザイン(XAPP1356)の実装66● 演算処理○ Intrinsics を駆使して作り込んでいる● プロファイル結果○ 効率的にすき間なく演算が行われている様子が見える
Copyright© Fixstars Groupまとめ67● AI Engine を用いた FFT 演算の実装を通して、AI Engine の構成、特徴の共有を行った○ 演算機能の最適化方法○ メモリ構成、共有メモリを介したカーネル間接続方法● 比較的簡単な方法で、複数のカーネルが連携して動作することを示した● 演算処理の最適化が不足しており、AI Engine API や Intrinsics を用いた高速化が必須であることが明らかになった
Copyright© Fixstars GroupGenerative AI を活用したFPGA 開発談68
Copyright© Fixstars GroupWho I am写真Shinya KAJI梶 信也ソリューション第四事業部 事業部長69
Copyright© Fixstars Group 70今日の LT でお話しすることGenerative AI の代表的なサービスの 1 つである『ChatGPT』をFPGA 開発に活かそうという話引用元 : https://investingnews.com/invest-in-openai-chatgpt/
Copyright© Fixstars Group注意事項● ChatGPT の使用を推奨するものではありません● ChatGPT を使用する際には重要情報の流出には十分注意してください71
Copyright© Fixstars Group 72ChatGPT とは?ChatGPT(チャットジーピーティー、英語: Chat Generative Pre-trainedTransformer)は、OpenAIが2022年11月に公開した人工知能チャットボット。原語のGenerative Pre-trained Transformerとは、「生成可能な事前学習済み変換器」という意味である。OpenAIのGPT-3ファミリーの言語モデルを基に構築されており、教師あり学習と強化学習の両方の手法で転移学習されている。Wikipedia より引用 : https://ja.wikipedia.org/wiki/ChatGPT
Copyright© Fixstars Group 73Google Trend より : https://trends.google.co.jp/home世界中?が熱狂した WBC とChatGPT は同程度の注目度!
Copyright© Fixstars GroupFPGA 開発における ChatGPT の活用どころは?74構想段階仕様検討段階設計/実装段階シミュレーションタイミング検証実機検証etc.上流工程で活用してみました!
Copyright© Fixstars Group①構想段階での活用:75Intel FPGA を使った SmartNIC を独自開発したいけど、オープンソースの TOE を活用できないだろうか?
Copyright© Fixstars Group①構想段階での活用: (cont.)76I want to find the TOE open source for Intel FPGA. Please let me know the best OSSand its reason.SHThe TOE (TCP Offload Engine) open source for Intel FPGA that I would recommend is the TOE project maintained by the OpenProgrammable Acceleration Engine (OPAE) community. This project provides a full-featured, high-performance TCP/IP stack forFPGA-based NICs (network interface cards) and is optimized for use with Intel FPGAs.The TOE project offers several benefits that make it a great choice for Intel FPGA users:1. High-performance: The TOE project is designed to offer high-performance TCP/IP offloading capabilities for FPGA-basedNICs, allowing for increased throughput and reduced CPU utilization.2. Open source: The TOE project is open source, which means that users can modify and customize the code to suit theirspecific needs. This also means that the project is constantly being improved and updated by a community ofcontributors.3. Easy to use: The TOE project is designed to be easy to use, with a straightforward API that allows developers to quicklyintegrate it into their applications.4. Compatibility: The TOE project is compatible with a wide range of Intel FPGA devices and development boards, making ita versatile option for developers working on FPGA-based networking projects.Overall, the TOE project is a solid choice for anyone looking to implement TCP/IP offloading on Intel FPGAs. Its high-performance,open-source nature, ease of use, and compatibility with a wide range of Intel FPGA devices make it a top contender in this space.
Copyright© Fixstars Group①構想段階での活用: (cont.)77Where can I find it? Give me the link to download the software.SHYou can find the TOE project on the Open Programmable Acceleration Engine (OPAE) GitHubrepository. Here's the link to the repository:https://github.com/OPAE/toeYou can download the latest version of the TOE project from the repository's releases page:https://github.com/OPAE/toe/releasesFrom there, you can download the source code or pre-built binaries for your platform. Therepository also contains documentation, examples, and other resources to help you get startedwith the project.
Copyright© Fixstars Group①構想段階での活用: (cont.)78Do you have any alternatives?SHYes, there are alternative TCP Offload Engine (TOE) open source projects available for IntelFPGAs. Here are a few options:1. DPDK: The Data Plane Development Kit (DPDK) is an open source set of libraries anddrivers for fast packet processing on Intel architectures, including FPGAs. DPDK providesa high-performance TCP/IP stack that can be used for TOE offloading.2. NetCOPE: NetCOPE is an open source framework for FPGA-based network processingthat includes a TCP/IP stack optimized for use with Intel FPGAs. NetCOPE offers a rangeof features, including support for multiple protocols and hardware acceleration.3. NetFPGA: NetFPGA is an open source platform for networking research and educationthat includes a TCP/IP stack optimized for FPGA-based NICs. NetFPGA offers a range offeatures, including support for multiple protocols and hardware acceleration.These alternative projects offer similar capabilities to the TOE project, but each has its ownstrengths and weaknesses. Ultimately, the best choice will depend on your specific needs andrequirements.
Copyright© Fixstars Group①構想段階での活用: (cont.)79人力でググって調べる作業はかなり代替できそう!(ChatGPT と数分対話するだけで OK)
Copyright© Fixstars Group②仕様検討段階での活用:80TOE は決めたけど、どの FPGAボードを採用したら良いだろうか?コストも限られているし…
Copyright© Fixstars Group②仕様検討段階での活用: (cont.)81Which FPGA board do you recommend to implement the TOE project on the OPAE,and why?SHThere are several FPGA boards that can be used to implement the TOE project on the OPAE, depending on yourspecific requirements and budget. Here are a few options that I would recommend:1. Intel PAC with Intel Arria 10 GX FPGA: This FPGA board is designed specifically for network acceleration andincludes an Arria 10 GX FPGA along with 8 GB of DDR4 memory and a 100 Gbps QSFP28 network interface.The board is well-suited for implementing the TOE project, as it provides high-speed networking capabilitiesand powerful FPGA resources.2. Terasic DE5a-Net FPGA Development Kit: This development kit includes a Stratix V GX FPGA along with 4 GBof DDR3 memory and multiple high-speed networking interfaces. The board is a good choice forimplementing the TOE project, as it provides a large FPGA with plenty of resources and support for multiplenetworking protocols.3. Intel FPGA Development Kit: This development kit includes a Cyclone V GX FPGA along with 1 GB of DDR3memory and multiple high-speed networking interfaces. The board is a more budget-friendly option forimplementing the TOE project, while still providing a powerful FPGA and networking capabilities.Ultimately, the choice of FPGA board will depend on your specific requirements, including performance, cost, anddevelopment environment. All of the boards listed above are compatible with the OPAE and provide a good startingpoint for implementing the TOE project.
Copyright© Fixstars Group②仕様検討段階での活用: (cont.)82The cost is limited to 10,000 USD, and higher performance is better. Which FPGAboard is your best choice?SHWith a budget of $10,000 and a requirement for higher performance, I would recommend the IntelPAC with Intel Arria 10 GX FPGA. This board is designed specifically for network acceleration andoffers a powerful Arria 10 GX FPGA, along with 8 GB of DDR4 memory and a 100 Gbps QSFP28network interface. The board is well-suited for implementing the TOE project and can provide thehigh performance you require.The Intel PAC with Intel Arria 10 GX FPGA has a list price of around $3,000, leaving plenty of roomin your budget for additional components, such as power supplies, cables, and development tools.The board is also well-supported by the OPAE community, which can help simplify thedevelopment process and provide access to a range of resources and examples.Overall, the Intel PAC with Intel Arria 10 GX FPGA is a great choice for implementing the TOEproject on a budget of $10,000 while still providing the high performance you require.
Copyright© Fixstars Group②仕様検討段階での活用: (cont.)83PM や PdM を助けてくれる良きパートナー!(ChatGPT と数分対話するだけで OK)
Copyright© Fixstars Group③設計/実装段階での活用:84非同期 FIFO を Verilog で実装したいけど誰かが実装してるはずだから流用したい…
Copyright© Fixstars Group③設計/実装段階での活用:85Write Verilog code for an asynchronous FIFO with parameterizable width and depth.SHHere's an example of an asynchronous FIFO with parameterizable width and depth in Verilog:module fifo #(parameter WIDTH = 8,parameter DEPTH = 16)(input clk,input rst,input wr_en,input rd_en,input [WIDTH-1:0] wr_data,output [WIDTH-1:0] rd_data,output full,output empty);reg [WIDTH-1:0] memory [0:DEPTH-1];reg [WIDTH-1:0] rd_data_reg;reg [WIDTH-1:0] wr_ptr;reg [WIDTH-1:0] rd_ptr;reg [DEPTH-1:0] occupancy;always @(posedge clk) beginif (rst) beginwr_ptr <= {WIDTH{1'b0}};rd_ptr <= {WIDTH{1'b0}};occupancy <= {DEPTH{1'b0}};rd_data_reg <= {WIDTH{1'b0}};endelse beginif (wr_en && !full) beginmemory[wr_ptr] <= wr_data;wr_ptr <= wr_ptr + 1;occupancy <= occupancy + 1;endif (rd_en && !empty) beginrd_data_reg <= memory[rd_ptr];rd_ptr <= rd_ptr + 1;occupancy <= occupancy - 1;endendendassign rd_data = rd_data_reg;assign full = (occupancy == DEPTH);assign empty = (occupancy == 0);endmodule
Copyright© Fixstars Group③設計/実装段階での活用: (cont.)86Write Verilog code for an asynchronous FIFO with parameterizable width and depth.SHThis module defines an asynchronous FIFO with a configurable WIDTH and DEPTH. The module hasinput ports for the clock signal (clk), reset signal (rst), write enable (wr_en), and read enable(rd_en). The module also has input ports for write data (wr_data) and output ports for read data(rd_data), full flag (full), and empty flag (empty).The module uses an array (memory) to store data in the FIFO, and read and write pointers (rd_ptrand wr_ptr) to keep track of the current positions in the FIFO. The module also uses anoccupancy counter (occupancy) to keep track of how many elements are currently in the FIFO.In the always block, the module checks for a reset signal and updates the read and write pointersand occupancy counter based on the write and read enable signals. The read data is stored in aregister (rd_data_reg) to avoid race conditions.The assign statements assign the read data, full flag, and empty flag based on the currentoccupancy of the FIFO.
Copyright© Fixstars Group③設計/実装段階での活用: (cont.)87簡単な FPGA 実装は任せられそう!(お願いすればテストベンチも作成してくれる)
Copyright© Fixstars GroupChatGPT で実現できないことはまだまだある!88Write the fastest TCP Offload Engine HDL code for Intel FPGA as detailed as possible.SHDesigning a TCP Offload Engine (TOE) is a complex task that requires a deep understanding of boththe TCP/IP protocol and FPGA architecture. Here are some general steps that may be involved inimplementing a TOE on an Intel FPGA, along with some tips for optimizing the HDL code formaximum performance:(snip)抽象度が高くかつ難易度の高い非機能要件を持つ要件から具体的な実装に落とし込むのはエンジニアの仕事!
Copyright© Fixstars GroupTakeaway89● ChatGPT と対話することで人力検索を効率化できる● 非エンジニア (PM/PdM) とエンジニアの溝が埋まる● ChatGPT に簡単なプログラミングを任せることができる● FPGA エンジニアの仕事がなくなることは (おそらく) ないHappy FPGA Life!
Copyright © Fixstars GroupThank you!お問い合わせ窓口 : [email protected]90