在 YARN 上使用 FPGA

先決條件

組態

FPGA 排程

resource-types.xml

加入下列屬性

<configuration>
  <property>
     <name>yarn.resource-types</name>
     <value>yarn.io/fpga</value>
  </property>
</configuration>

對於 Capacity SchedulerDominantResourceCalculator 必須設定為啟用 FPGA 排程/隔離。使用下列屬性設定 DominantResourceCalculator(在 capacity-scheduler.xml 中)

屬性 預設值
yarn.scheduler.capacity.resource-calculator org.apache.hadoop.yarn.util.resource.DominantResourceCalculator

FPGA 隔離

yarn-site.xml

  <property>
    <name>yarn.nodemanager.resource-plugins</name>
    <value>yarn.io/fpga</value>
  </property>

這是在 NodeManager 端啟用 FPGA 隔離模組。

預設情況下,當設定上述組態時,YARN 會自動偵測和設定 FPGA。僅在管理員有特殊需求時,才需要在 yarn-site.xml 中設定下列組態。

1) 允許的 FPGA 裝置

屬性 預設值
yarn.nodemanager.resource-plugins.fpga.allowed-fpga-devices auto

指定 YARN NodeManager 可管理的 FPGA 裝置,以逗號分隔 FPGA 裝置數量會回報給 RM 以進行排程決策。設為 auto(預設)讓 YARN 自動從系統偵測 FPGA 資源。

如果管理員僅需要 YARN 管理的 FPGA 裝置子集,請手動指定 FPGA 裝置。目前,由於我們只能在 c-e.cfg 中設定一個主要編號,因此 FPGA 裝置會以其次要裝置編號識別。對於 Intel 裝置,取得 FPGA 次要裝置編號的常見方法是使用「aocl diagnose」並檢查具有裝置名稱的 uevent。

2) 偵測 FPGA 的可執行檔

屬性 預設值
yarn.nodemanager.resource-plugins.fpga.path-to-discovery-executables

當指定 yarn.nodemanager.resource.fpga.allowed-fpga-devices=auto 時,YARN NodeManager 需要執行 FPGA 偵測二進位檔(目前僅支援 IntelFpgaOpenclPlugin)以取得 FPGA 資訊。當值為空(預設)時,YARN NodeManager 會嘗試從供應商外掛程式偏好設定中找出偵測可執行檔。例如,「IntelFpgaOpenclPlugin」會嘗試在從環境「ALTERAOCLSDKROOT」取得的目錄中找出「aocl」

3) 要使用的 FPGA 外掛程式

屬性 預設值
yarn.nodemanager.resource-plugins.fpga.vendor-plugin.class org.apache.hadoop.yarn.server.nodemanager.containermanager.resourceplugin.fpga.IntelFpgaOpenclPlugin

目前僅支援 Intel OpenCL SDK for FPGA。執行於 FPGA 上的 IP 程式(.aocx 檔案)應使用 Intel 平台的 OpenCL 編寫。

4) CGroups 掛載 FPGA 隔離使用 CGroup 裝置控制器進行每個 FPGA 裝置隔離。應將下列設定檔新增至 yarn-site.xml 以自動掛載 CGroup 子裝置,否則管理員必須手動建立裝置子資料夾才能使用此功能。

屬性 預設值
yarn.nodemanager.linux-container-executor.cgroups.mount true

有關 YARN CGroups 設定檔的更多詳細資訊,請參閱 使用 CGroups 與 YARN

container-executor.cfg

一般而言,需要將下列設定檔新增至 container-executor.cfg。fpga.major-device-number 和 allowed-device-minor-numbers 是可選擇的允許裝置。

[fpga]
module.enabled=true
fpga.major-device-number=## Major device number of FPGA, by default is 246. Strongly recommend setting this
fpga.allowed-device-minor-numbers=## Comma separated allowed minor device numbers, empty means all FPGA devices managed by YARN.

當使用者需要在非 Docker 環境下執行 FPGA 應用程式時

[cgroups]
# Root of system cgroups (Cannot be empty or "/")
root=/cgroup
# Parent folder of YARN's CGroups
yarn-hierarchy=yarn

使用它

Distributed-shell + FPGA

Distributed shell 目前支援指定記憶體和 vcores 以外的其他資源類型

在不使用 Docker 容器的情況下執行 distributed shell(.bashrc 包含一些 SDK 相關環境變數)

yarn jar <path/to/hadoop-yarn-applications-distributedshell.jar> \
  -jar <path/to/hadoop-yarn-applications-distributedshell.jar> \
  -shell_command "source /home/yarn/.bashrc && aocl diagnose" \
  -container_resources memory-mb=2048,vcores=2,yarn.io/fpga=1 \
  -num_containers 1

您應該可以看到類似以下的輸出

aocl diagnose: Running diagnose from /home/fpga/intelFPGA_pro/17.0/hld/board/nalla_pcie/linux64/libexec

------------------------- acl0 -------------------------
Vendor: Nallatech ltd

Phys Dev Name  Status   Information

aclnalla_pcie0Passed   nalla_pcie (aclnalla_pcie0)
                       PCIe dev_id = 2494, bus:slot.func = 02:00.00, Gen3 x8
                       FPGA temperature = 54.4 degrees C.
                       Total Card Power Usage = 32.4 Watts.
                       Device Power Usage = 0.0 Watts.

DIAGNOSTIC_PASSED
---------------------------------------------------------

指定 YARN 在啟動容器之前應設定的 IP

對於 FPGA 資源,容器可以有一個環境變數「REQUESTED_FPGA_IP_ID」,讓 YARN 在啟動前下載並為其更新 IP。例如,REQUESTED_FPGA_IP_ID =「matrix_mul」會導致在容器的本機目錄中搜尋名稱包含「matirx_mul」(應用程式應先將其分發)的 IP 檔案(「.aocx」檔案)。我們目前僅支援為所有裝置更新一個 IP。如果使用者未設定此環境變數,我們假設使用者的應用程式可以自行尋找 IP 檔案。請注意,在 YARN 中事先下載和重新編寫 IP 並非必要,因為 OpenCL 應用程式可能會在執行時尋找 IP 檔案並重新編寫裝置。但 YARN 會為容器執行此動作,以達成最快速的重新編寫路徑。