このセクションでは、main()
とアクセラレーション関数を含む単純な
SDSoC™
プログラムを参照し、変更が必要な要素を特定します。アプリケーションとハードウェア関数を Vitis 環境プラットフォームおよびツールに移行するプロセスを開始するには、まず main 関数とハードウェア関数のコードを調べます。ここに示すコードは、mmult
サンプル アプリケーションのものです。
次のコードは、元の開発アプリケーション プロジェクトの main()
関数の例です。
#include <stdlib.h>
#include <iostream>
#include "mmult.h"
#include "sds_lib.h"
#define NUM_TESTS 5
void printMatrix(int *mat, int col, int row) {
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
std::cout << mat[i*row+j] << "\t";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
int main() {
int col = BUFFER_SIZE;
int row = BUFFER_SIZE;
int *matA = (int*)sds_alloc(col*row*sizeof(int));
int *matB = (int*)sds_alloc(col*row*sizeof(int));
int *matC = (int*)sds_alloc(col*row*sizeof(int));
std::cout << "Mat A" << std::endl;
printMatrix(matA, col, row);
std::cout << "Mat B" << std::endl;
printMatrix(matB, col, row);
//Run the hardware function multiple times
for(int i = 0; i < NUM_TESTS; i++) {
std::cout << "Test #: " << i << std::endl;
// Populate matA and matB
srand(time(NULL));
for (int i = 0; i < col*row; i++) {
matA[i] = rand()%10;
matB[i] = rand()%10;
}
std::cout << "MatA * MatB" << std::endl;
mmult(matA, matB, matC, col, row);
}
printMatrix(matC, col, row);
return 0;
このコードは、1 次元配列として格納されている 3 つの 2 次元行列にメモリを割り当て、matA
および matB
にランダムな値を挿入し、matA
と matB
を乗算して結果 matC
を算出します。結果は画面に表示し、テストを 10 回実行します。
Vitis 環境に移行する際、sds++
コンパイラおよびランタイムで自動的に処理されていたいくつかのタスクを、アプリケーション開発者が管理する必要があります。