バースト データ転送モードの使用方法 - 2023.2 日本語

Vitis Model Composer ユーザー ガイド (UG1483)

Document ID
UG1483
Release Date
2023-11-15
Version
2023.2 日本語

バースト データ転送モードを開始するには、自動生成されたテストベンチ スクリプトを使用するのが最も簡単な方法です。上級ユーザーは、Model Composer に含まれている MATLAB Hwcosim オブジェクトを使用した HWCosim API を利用できます。

自動テストベンチ生成

テストベンチ生成は、ハードウェア協調シミュレーション コンパイル フローで実行されます。HDL Settings タブの下部にある Create Testbench チェック ボックスをオンにして、M-HWCosim テストベンチ スクリプトが自動的に生成されるようにできます。

図 1. テストベンチの作成

テスト ジェネレーターは次のターゲット ディレクトリに M スクリプトを生成します。

<design_name>_<sub_system>_hwcosim_test.m

MATLAB® コンソールでこのスクリプトを実行できます。このスクリプトは、ほかの Simulink ソース ブロックまたは MATLAB 変数から AMD Gateway In ブロックに駆動されるスティミュラス データを判断するため Simulink モデルも実行し、AMD ブロック デザイン (BD) により生成された予測される出力を取り込み、データを個別のデータ ファイルとしてターゲット ディレクトリ (Target directory で指定) にエクスポートします。

<design_name>_<sub_system>_<port_name>.dat

テストベンチを実行するには、MATLAB のコンソールを開き、HDL サブシステム ソースへのディレクトリ (<target_directory>/ip/<hdl_subystem>/src) に移動して、スクリプトの名前を指定して実行します。テストにエラーが発生すると、コンソールにエラーが出力され、次のファイルにエラーが発生した箇所が比較されて出力されます。

<design_name>_<sub_system>_hwcosim_test.result

バースト モードのテストベンチ スクリプト

次は、コンパイル フローの一部としてサンプル デザイン用に生成されたテストベンチです。

%% project3_burst_hwcosim_test
% project3_burst_hwcosim_test is an automatically generated example MCode
% function that can be used to open a hardware co-simulation (hwcosim) target,
% load the bitstream, write data to the hwcosim target's input blocks, fetch
% the returned data, and verify that the test passed. The returned value of
% the test is the amount of time required to run the test in seconds.
% Fail / Pass is indicated as an error or displayed in the command window.
 
%%
% PLEASE NOTE that this file is automatically generated and gets re-created
% every time the Hardware Co-Simulation flow is run. If you modify any part
% of this script, please make sure you save it under a new name or in a
% different location.
 
%%
% The following sections exist in the example test function:
% Initialize Bursts
% Initialize Input Data & Golden Vectors
% Open and Simulate Target
% Release Target on Error
% Test Pass / Fail
 
function eta = project3_burst_hwcosim_test
eta = 0;
 
%%
% ncycles is the number of cycles to simulate for and should be adjusted if
% the generated testbench simulation vectors are substituted by user data.
ncycles = 10;
 
%%
% Initialize Input Data & Golden Vectors
% xlHwcosimTestbench is a utility function that reformats fixed-point HDL Netlist
% testbench data vectors into a double-precision floating-point MATLAB binary
% data array.
xlHwcosimTestbench('.','project3_burst');
 
%%
% The testbench data vectors are both stimulus data for each input port, as
% well as expected (golden) data for each output port, recorded during the
% Simulink simulation portion of the Hardware Co-Simulation flow.
% Data gets loaded from the data file ('<name>_<port>_hwcosim_test.dat')
% into the corresponding 'testdata_<port>' workspace variables using
% 'getfield(load('<name>_<port>_hwcosim_test.dat' ... ' commands.
% 
% Alternatively, the workspace variables holding the stimulus and / or golden
% data can be assigned other data (including dynamically generated data) to
% test the design with. If using alternative data assignment, please make
% sure to adjust the "ncycles" variable to the proper number of cycles, as
% well as to disable the "Test Pass / Fail" section if unused.
testdata_noise_x0 = getfield(load('project3_burst_noise_x0_hwcosim_test.dat', '-mat'), 
'values');
testdata_scale = getfield(load('project3_burst_scale_hwcosim_test.dat', '-mat'), 'values');
testdata_wave = getfield(load('project3_burst_wave_hwcosim_test.dat', '-mat'), 'values');
testdata_intout = getfield(load('project3_burst_intout_hwcosim_test.dat', '-mat'), 'values');
testdata_sigout = getfield(load('project3_burst_sigout_hwcosim_test.dat', '-mat'), 'values');
 
%% 
% The 'result_<port>' workspace variables are arrays to receive the actual results
% of a Hardware Co-Simulation read from the FPGA. They will be compared to the
% expected (golden) data at the end of the Co-Simulation.
result_intout = zeros(size(testdata_intout));
result_sigout = zeros(size(testdata_sigout));
 
%%
% project3_burst.hwc is the data structure containing the Hardware Co-Simulation
% design information returned after netlisting the Simulink / System 
% Generator model.
% Hwcosim(project) instantiates and returns a handle to the API shared library object.
project = 'project3_burst.hwc';
h = Hwcosim(project);
try 
    %% Open the Hardware Co-Simulation target and co-simulate the design
    open(h); 
    cosim_t_start = tic;
    h('noise_x0') = testdata_noise_x0;
    h('scale') = testdata_scale;
    h('wave') = testdata_wave;
    run(h, ncycles);
    result_intout = h('intout');
    result_sigout = h('sigout');
    eta = toc(cosim_t_start);
    % Release the handle for the Hardware Co-Simulation target
    release(h);
 
%% Release Target on Error
catch err
    release(h); 
    rethrow(err); 
    error('Error running hardware co-simulation testbench. Please refer to hwcosim.log for 
details.'); 
end 
 
%% Test Pass / Fail
logfile = 'project3_burst_hwcosim_test.results';
logfd = fopen(logfile, 'w');
sim_ok = true;
sim_ok = sim_ok & xlHwcosimCheckResult(logfd, 'intout', testdata_intout, result_intout);
sim_ok = sim_ok & xlHwcosimCheckResult(logfd, 'sigout', testdata_sigout, result_sigout);
fclose(logfd);
if ~sim_ok
    error('Found errors in the simulation results. Please refer to 
project3_burst_hwcosim_test.results for details.');
end 
disp(['Hardware Co-Simulation successful. Data matches the Simulink simulation and completed in 
' num2str(eta) ' seconds.']) ;

このスクリプトはまず、シミュレーションで実行するサイクル数 (ncycles) を定義し、テストベンチを準備し、スティミュラス データおよび予測出力を MATLAB 配列に読み込みます。その後、HWCosim API 共有ライブラリを読み込むハンドル (h) を使用して、xlHwcosim オブジェクト インスタンスを作成します。try-catch ブロック内でインスタンスを開き、FPGA を初期化して、FPGA への接続を開きます。

セットアップが完了したら、tictoc のタイミング コマンド間のコードが書き込み/実行/読み出しのコマンドを実行します。古いバージョンの HWCosim とは異なり、このテストベンチには、各クロック サイクルを通しで実行する for-loop は不要です。これは、(run(h, ncycles) コマンドの実行中に) 細かいサイクルで書き込み/実行/読み出しのバッチ コマンドをハードウェアに実行する前に、ホスト メモリにほぼ任意サイズの書き込みコマンドを格納しておくことができる、新しいスマート キャッシュ レイヤーがあるからです。

実行フェーズの最後で、HWCosim インスタンスは開放され、テストベンチは実際の出力と予測出力と比較します。

テストベンチのコードのコメントは、ハードウェア協調シミュレーションのフローを理解し、ユーザー デザイン用にカスタマイズされたテストベンチ スクリプトを作成するのに役立ちます。