配置 Google Cloud Platform 的 LSF 資源連接器

指定 LSF 資源連接器配置,以啟用 Google Cloud Platform 作為資源提供者。

程序

  1. 更新 Google Cloud Platform 資源連接器配置。
    變更 googleprov_config.json 檔案中的參數,以啟用資源連接器來連接至 Google Cloud Platform。
    GCLOUD_PROJECT_ID
    Google Cloud 專案 ID。 當您在 Google Cloud Platform 主控台上按一下所有專案的清單時,或使用 gcloud 指令來查看您的專案 ID。
    GCLOUD_CREDENTIALS_FILE
    Google Cloud 服務帳戶金鑰。 服務帳戶必須具有 Google Compute Engine 的讀寫許可權,並完全控制 Google Cloud Storage。

    如果 LSF 管理主機位於 Google Cloud上,且連接至 LSF 管理主機實例的服務帳戶具有必要許可權,則此參數是選用項目。

    GCLOUD_REGION
    大量實例的預設區域。

    Google Cloud Platform 同時提供區域主體 API 端點 (Instances.BulkInsert) 和區域主體 API 端點 (RegionInstances.BulkInsert) 支援。 LSF 資源連接器會自動使用大量 API 端點來建立 Google Cloud 實例。

    如果您要在其中建立實例的區域不重要,請透過指定 GCLOUD_REGION 參數的值或在 googleprov_templates.json 檔案中定義地區,來配置 LSF 資源連接器以呼叫地區主體 API 端點。 googleprov_templates.json 檔案中定義的區域會置換 GCLOUD_REGION 參數中定義的區域。 Google Cloud Platform 會考量每一個區域中可用的硬體容量,自動選取要在其中建立實例的區域。

    如果您要指定要在其中建立實例的區域,請在 googleprov_templates.json 檔案中定義區域,然後 LSF 資源連接器會呼叫區域大量 API 端點。

  2. 建立範本。
    googleprov_templates.json 檔中至少建立一個範本。 請確定您的範本至少正確定義下列屬性:
    • imageId
    • vmType
    • zone

    下列範本是具有 1 個 CPU 之主機的最小範例:

    {
        "templates": [
            {   
                "templateId": "Template-VM-1",
                "maxNumber": 1,
                "attributes": {
                    "type": ["String", "X86_64"],
                    "ncores": ["Numeric", "1"],
                    "ncpus": ["Numeric", "1"],
                    "nthreads": ["Numeric", "1"],
                    "mem": ["Numeric", "600"],
                    "googlehost": ["Boolean", "1"]
                },
                "imageId": "serverimage",
                "vmType": "f1-micro",
                "zone": "us-central1-f",
                "instanceTags" : "team=dev8",
                "userData": "team=dev8"
            }
        ]
    }
    

    選擇性地指定其他屬性,以建立使用其他特性的範本。

    1. 定義 GPU 屬性,以針對具有 GPU 支援的實例建立範本。

      指定 gpuType 屬性以啟用 GPU 支援,並指定其他屬性以配置 GPU 特性。

      下列範本定義 GPU 相關屬性:

      {
          "templates": [
              {
                  "templateId": "TemplateGPU-VM-1",
                  "maxNumber": 100,
                  "attributes": {
                      "type": ["String", "X86_64"],
                      "ncores": ["Numeric", "1"],
                      "ncpus": ["Numeric", "1"],
                      "nthreads": ["Numeric", "2"],
                      "ngpus": ["Numeric", "1"],
                      "ngpus_physical": ["Numeric", "1"],
                      "gpuextend": ["String", "ngpus=1;nnumas=1;gbrand=Tesla;gmodel=K80;gmem=10240;nvlink=yes"],
                      "define_ncpus_threads": ["Boolean", "1"],
                      "mem": ["Numeric", "3840"],
                      "zone": ["String", "us_east1-d"],
                      "googlehost": ["Boolean", "1"]
                  },
                  "imageId": "lsf-gcloud-dynamic-vm",
                  "region": "us-east1",
                  "zone": "us-east1-d",
                  "vmType": "n1-standard-1",
                  "gpuType": "nvidia-tesla-k80",
                  "gpuNumber":"1",
      	     "privateNetworkOnlyFlag": false,
                  "vpc": "lsf-vpc",
                  "priority": "18",
                  "subnetId": "lsf-vpc-us-east1",
                  "instanceTags" : "lsf-vpn-instance=gcloud-VM-1",
                  "userData": "zone=us-east1-d"
              }
          ]
      }
      

      如果您想要使用 GPU 機型、GPU 記憶體或 NVLink 支援之類的因素來選取不同的範本,請使用 gpuextend 屬性。 gpuextend 屬性由以分號區隔的鍵值組組成。

    2. 指定範本的基準線最低 CPU 平台。

      使用 minCpuPlatform 屬性來指定 CPU 平台下限。

      如果您決定指定最低 CPU 平台,請確定您的區域包含多個 CPU 平台,且此實例的指定區域中存在最低 CPU 平台。 如果您指定最低 CPU 平台,則除非您停止實例並變更 CPU 平台,否則您的實例會使用此 CPU 平台。

      如需最低 CPU 平台的相關資訊,請參閱 Google Cloud 文件:https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform

      下列範本使用 Intel Sandy Bridge 作為最低 CPU 平台:

      {    
      	"templates": [
              {
                  "templateId": "TemplateMinCPU-VM-1",
                  "maxNumber": 100,
                  "attributes": {
                      "type": ["String", "X86_64"],
                      "ncores": ["Numeric", "1"],
                      "ncpus": ["Numeric", "1"],
                      "nthreads": ["Numeric", "2"],
                      "define_ncpus_threads": ["Boolean", "1"],
                      "mem": ["Numeric", "3840"],
                      "zone": ["String", "us_east1-d"],
                      "googlehost": ["Boolean", "1"]
                  },
                  "imageId": "lsf-gcloud-dynamic-vm",
                  "region": "us-east1",
                  "zone": "us-east1-d",
                  "vmType": "n1-standard-1",
                  "minCpuPlatform":"Intel Sandy Bridge",
                  "privateNetworkOnlyFlag": false,
                  "vpc": "lsf-vpc",
                  "priority": "18",
                  "subnetId": "lsf-vpc-us-east1",
                  "instanceTags" : "lsf-vpn-instance=gcloud-VM-1",
                  "userData": "zone=us-east1-d"
              }
          ]
      }

      如果不同的工作集具有不同的最低 CPU 平台需求,您可以在不同的範本 ID 中配置字串資源:

      {
          "templates": [
              {
                  "templateId": "gcloud-VM-1",
                  "maxNumber": 100,
                  "attributes": {
                      "type": ["String", "X86_64"],
                      "ncores": ["Numeric", "1"],
                      "ncpus": ["Numeric", "1"],
                      "nthreads": ["Numeric", "2"],
                      "define_ncpus_threads": ["Boolean", "1"],
                      "mem": ["Numeric", "3840"],
                      "zone": ["String", "us_east1-d"],
                      "googlehost": ["Boolean", "1"],
                      "minCpuPlatform": ["String", "Intel_Sandy_Bridge"]
                  },
                  "imageId": "lsf-gcloud-dynamic-vm",
                  "region": "us-east1",
                  "zone": "us-east1-d",
                  "vmType": "n1-standard-1",
                  "minCpuPlatform":"Intel Sandy Bridge",
      	     "privateNetworkOnlyFlag": false,
                  "vpc": "lsf-vpc",
                  "priority": "18",
                  "subnetId": "lsf-vpc-us-east1",
                  "instanceTags" : "lsf-vpn-instance=gcloud-VM-1",
                  "userData": minCpuPlatform=Intel_Sandy_Bridge"
              },
              {
                  "templateId": "gcloud-VM-2",
                  "maxNumber": 50,
                  "attributes": {
                      "type": ["String", "X86_64"],
                      "ncores": ["Numeric", "1"],
                      "ncpus": ["Numeric", "1"],
                      "nthreads": ["Numeric", "2"],
                      "define_ncpus_threads": ["Boolean", "1"],
                      "mem": ["Numeric", "3840"],
                      "zone": ["String", "us_east1-d"],
                      "googlehost": ["Boolean", "1"],
                      "minCpuPlatform": ["String", "Intel_Cascade_Lake"]
                  },
                  "imageId": "lsf-gcloud-dynamic-vm",
                  "region": "us-east1",
                  "zone": "us-east1-d",
                  "vmType": "n1-standard-1",
                  "minCpuPlatform": "Intel Cascade Lake",
                  "privateNetworkOnlyFlag": false,
                  "vpc": "lsf-vpc",
                  "priority": "18",
                  "subnetId": "lsf-vpc-us-east1",
                  "instanceTags" : "lsf-vpn-instance=gcloud-VM-1",
                  "userData": "minCpuPlatform=Intel_Cascade_Lake"
              }
          ]
      }

      lsf.shared 檔中,配置 minCpuPlatform String 資源:

      Begin Resource
      RESOURCENAME  TYPE    INTERVAL INCREASING  DESCRIPTION        # Keywords
      ...
      minCpuPlatform String ()       ()          (minCpuPlatform )
      ...
      End Resource

      userData 屬性的內容會匯出為環境變數。 將下列各行新增至 <LSF_TOP>/<LSF_VERSION>/resource_connector/google/scripts/ 目錄中的 user_data.sh Script ,以在新建立的實例中新增 minCpuPlatform String 資源:

      if [ -n "${minCpuPlatform}" ]; then
      sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 [resourcemap ${minCpuPlatform}*minCpuPlatform]\"/" $LSF_CONF_FILE
      echo "Updated LSF_LOCAL_RESOURCES in $LSF_CONF_FILE successfully to add [resourcemap ${minCpuPlatform}*minCpuPlatform]" >> $logfile
      else
      echo "minCpuPlatform does not exist in the environment variable" >> $logfile
      fi

      您可以根據 minCpuPlatform來提交選取不同範本的工作。

      下列工作提交會從 gcloud-VM-1 範本建立或重複使用實例,其中以 Intel Sandy Bridge 作為最低 CPU 平台:

      bsub -R "select[minCpuPlatform==Intel_Sandy_Bridge]" myjob

      下列工作提交會從 gcloud-VM-2 範本建立或重複使用實例,其中以 Intel Cascade Lake 作為最低 CPU 平台:

      bsub -R "select[minCpuPlatform==Intel_Cascade_Lake]" myjob

      下列兩個工作提交都會從 gcloud-VM-1gcloud-VM-2 範本建立或重複使用實例,因為這兩個範本都滿足需求:

      bsub -R "select[minCpuPlatform==Intel_Sandy_Bridge  || minCpuPlatform==Intel_Cascade_Lake]" myjob
      bsub myjob
      您也可以將 minCpuPlatform 設為「數值」資源,使用不同的值來代表不同的 CPU 平台,然後根據此數值需求來提交工作。 例如,如果您針對不同的 CPU 平台使用下列數字:
      • Intel Skylake: 1
      • Intel Ivy Bridge: 2
      • Intel Haswell: 3
      • Intel Broadwell: 4
      • Intel Cascade Lake: 5
      • Intel Sandy Bridge: 6

      下列工作提交會建立或重複使用使用 Intel Cascade Lake 或 Intel Sandy Bridge CPU 平台的實例:

      bsub -R "select[minCpuPlatform > 4]" myjob
    3. 指定啟動實例範本。

      指定 launchTemplateId 屬性以啟用啟動實例範本。 您需要在 Google Cloud 中建立指定的實例範本,然後才能使用它。 使用啟動實例範本時,您可以在建立範本時定義範本內的所有實例內容,然後只需要在 googleprov_templates.json 檔案中指定區域或地區。 googleprov_templates.json 檔中指定的相同屬性會置換範本中指定的值。 如需實例範本置換行為的相關資訊,請參閱 Google Cloud 說明文件: https://cloud.google.com/compute/docs/instances/create-vm-from-instance-template#creating_a_vm_instance_from_an_instance_template_with_overrides

      附註: 若要將環境變數匯出至實例,您仍然必須在 googleprov_templates.json 檔案中指定 userData 屬性。 若要將標籤新增至實例,您仍然必須在 googleprov_templates.json 檔案中指定 instanceTags 屬性。

      如需啟動實例範本的相關資訊,請參閱 Google Cloud 文件: https://cloud.google.com/compute/docs/instance-templates

      LSF 僅在啟動實例範本中支援下列 Google Cloud 實例特性:

      本端 SSD
      LSF 透過啟動實例範本支援連接的本端 SSD ,但在 googleprov_templates.json 檔案中不包含介面。 在 Google Cloud中,透過在 類型 欄位中選取 本端 SSD 暫存磁碟 ,將本端 SSD 連接至 磁碟 > 新增磁碟 中的啟動實例範本。

      您必須先裝載 SSD ,才能使用它們。 LSF 包括一個範例程式碼,說明如何在 <LSF_TOP>/<LSF_VERSION>/resource_connector/google/scripts/example_user_data.sh 檔案的一個邏輯磁區中裝載多個本端 SSD。

      如需本端 SSD 的相關資訊,請參閱 Google Cloud 文件: https://cloud.google.com/compute/docs/disks/local-ssd

      可先占的 VM 實例
      可先佔 VM 實例是執行成本低於標準實例的實例,且大部分特性與標準實例相同。

      LSF 透過啟動實例範本支援可先占 VM 實例,但在 googleprov_templates.json 檔案中不包含介面。 在 Google Cloud中,建立啟動實例範本以啟用先佔 VM 實例時,將 先佔 欄位設為 開啟

      當先占 VM 實例時,實例會轉移至TERMINATED狀態及 LSF 會自動重新取得正在實例上執行的工作。 然後, LSF 會刪除先佔實例。

      如需可先占 VM 實例的相關資訊,請參閱 Google Cloud 文件: https://cloud.google.com/compute/docs/instances/preemptible

      下列範本指定啟動實例範本:

      {    
      	"templates": [
              {
                  "templateId": "gcloud-VM-1",
                  "maxNumber": 100,
                  "attributes": {
                      "type": ["String", "X86_64"],
                      "ncores": ["Numeric", "1"],
                      "ncpus": ["Numeric", "1"],
                      "nthreads": ["Numeric", "2"],
                      "define_ncpus_threads": ["Boolean", "1"],
                      "mem": ["Numeric", "3840"],
                      "zone": ["String", "us_east1-d"],
                      "googlehost": ["Boolean", "1"]
                  },
                  "zone": "us-east1-d",
                  "launchTemplateId”: “template-f1-micro"
              }
          ]
      }
  3. 選用項目: 更新 user_data.sh Script 中的 LSF_TOP 參數,以執行 lsf_daemons start 指令來啟動實例上的 LSF 常駐程式。 此 Script 會在 Google Cloud Platform 實例啟動期間執行。

    編輯 <LSF_TOP>/<LSF_VERSION>/resource_connector/google/scripts/ 目錄中的 user_data.sh 檔案。

    例如,
        #!/bin/sh
        
        logfile=/tmp/user_data.log
        echo START `date '+%Y-%m-%d %H:%M:%S'` >> $logfile
        
        #
        # Export user data, which is defined with the "UserData" attribute 
        # in the template
        #
        %EXPORT_USER_DATA%
        
        #
        # Add your customization script here
        #
        
        #
        # Source LSF enviornment at the VM host
        #
        LSF_TOP=/usr/share/lsf
        LSF_CONF_FILE=$LSF_TOP/conf/lsf.conf
        . $LSF_TOP/conf/profile.lsf
        env >> $logfile
        
        # 
        # Support rc_account resource to enable RC_ACCOUNT policy  
        # Add additional local resources if needed 
        #
        if [ -n "${rc_account}" ]; then
        sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1  [resourcemap ${rc_account}*rc_account]\"/" $LSF_CONF_FILE
        echo "update LSF_LOCAL_RESOURCES lsf.conf successfully, add [resourcemap ${rc_account}*rc_account]" >> $logfile
        fi
        
        #
        # Start LSF Daemons 
        #
        $LSF_SERVERDIR/lsf_daemons start
        
        echo END AT `date '+%Y-%m-%d %H:%M:%S'` >> $logfile
    
    附註: 您可以新增在 Google Cloud Platform 實例啟動時需要執行的任何額外程式碼。