1. 程式人生 > >Hadoop 3.1.1 - Yarn - 使用 FPGA

Hadoop 3.1.1 - Yarn - 使用 FPGA

gree 提前 value 系統 nor discovery 驅動程序 rop oar

在 Yarn 上使用 FPGA

前提

  • YARN 目前只支持通過 IntelFpgaOpenclPlugin 發布的 FPGA 資源
  • YARN NodeManager 所在的機器上必須預先安裝供應商的驅動程序並配置好必需的環境變量。
  • Docker 容器尚不支持。

配置

FPGA 調度

resource-types.xml添加如下配置

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

在 yarn-site.xml 中DominantResourceCalculator 必須被配置以啟用 FPGA 調度和隔離。 在 capacity-scheduler.xml 中使用如下參數以配置 DominantResourceCalculator

參數默認值
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 設備,用逗號分隔。GPU 卡的數量將被匯報給 ResourceManager用於調度。默認值 auto 代表讓 YARN 從系統中自動發現 GPU 卡。

如果管理員只希望一部分的 FPGA 設備被 Yarn 管理,請人為地指明可用的 FPGA 設備。因為當前只能配置為 c-e.cfg 中的一個主設備號,FPGA 設備由其次設備號標識。對於 Intel 設備,可以通過執行命令 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 設備之間的隔離。為了自動掛載次設備到 CGroups,以下配置要添加到 yarn-site.xml 文件中。否則,管理員必須人為地創建設備子目錄以使用該功能。

參數默認值
yarn.nodemanager.linux-container-executor.cgroups.mount true

想知道 Yarn 使用 CGroup 的更多信息,請參閱使用 CGroups。

container-executor.cfg

通常需要添加如下配置到 container-executor.cfg 中。fpag.major-device-number 和 allowed-device-minor-numbers 是可選參數,指明允許的 FPGA 設備。

[fpga]
module.enabled=true
fpga.major-device-number=## FPGA 的主設備號,默認是 246。強烈建議設置該參數。
fpga.allowed-device-minor-numbers=## 逗號分隔的次設備號,空值代表由 Yarn 管理所有的 FPGA 設備。

如果用戶要在非 Docker 環境下運行 FPGA 程序:

[cgroups]
# 系統 Cgroup 的根目錄(不能為空或“/”)
root=/cgroup
# YARN CGroup 的父目錄
yarn-hierarchy=yarn

使用

Distributed-shell + FPGA

分布式 Shell 程序在內存和虛擬核之外,還支持申請更多的資源類型。

不使用 Docker 運行分布式 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 文件。需要註意的是,提前 下載 IP 並重新編程在 Yarn 中並不是必需的,因為 OpenCL 程序可以在運行時查找 IP 文件並重新編程設備。但 Yarn 為容器完成這一步驟,以實現最快的重新編程。

Hadoop 3.1.1 - Yarn - 使用 FPGA