秋分
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: HPC --- # HPC Lecture#3 [TOC] ## 什麼是 verbs :::success 他是對一個使用 RDMA 應用程式功能的抽象描述 - 他不是一個 API - 他有不同的實作方式 ::: :::info ### verbs 可以被區分為兩種 - Control path > 用於管理資源,通常會需要進行環境切換 (context switch) - Create - Destroy - Modify - Query - Work with events - Data path > 運用資源來收發資料,不需要進行環境切換 - Post Send - Post Receice - Poll CQ (complete queue) - Request for completion event ::: ## 我幹嘛用 verbs - verbs 是一個在 RDMA programming 裡的低階描述 - verbs 貼近 bare-metal,可提供較好的表現 - latency - bw (bandwidth) - message rate - verbs 可當作許多應用程式的組件 - socket - storage - parallel computing ## libibverbs - 某個 open source 的 verbs API - 支援許多 RDMA 傳輸協定 - InfiniBand - RoCE - iWARP ### few tips - 要使用得要 include 此 header - `#include<infiniband/verbs.h>` - 有使用 libibverbs 的可執行檔跟函式庫都要 link `-libverbs` - input struct 需要被預設為零 - 可使用 `memset` - 多數資源控制代碼(handle)是指標(pointer),所以當用了錯誤的控制代碼可能會造成記憶體區段錯誤 - 當回傳的是 pointer,其值為 valid value 代表成功,NULL 代表失敗 - 當回傳的是整數,0 為成功,-1 為失敗 ## Memory Region(MR) :::success 他是一塊已註冊的虛擬連續記憶體區段 ![](https://i.imgur.com/vtSkqNC.png) - 擁有權限(可有一或多種) - Local operations(local read 永遠可執行所以未列出) - IBV_ACCESS_LOCAL_WRITE - IBV_ACCESS_MW_BIND - Remote operations - IBV_ACCESS_REMOTE_WRITE - IBV_ACCESS_REMOTE_READ - IBV_ACCESS_REMOTE_ATOMIC - 若 remote write/atomic 可執行,local write 應該也要可以 ::: ## Queue Pair(QP) - 包括 send queue(SQ) & receive queue(RQ) - 有三種主要傳輸型態 - Reliable Connected(RC) - Unreliable Connected(UC) - Unreliable Datagram(UD) - ![](https://i.imgur.com/SkbY8cF.png) ## API ### 產生一個 Memory Region ```c= struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd //protection domain void *addr, size_t length, enum ibv_access_flags access); ``` - lkey - the local key of this MR - ![](https://i.imgur.com/CRyIPpV.png) - rkey - the remote key of this MR - ![](https://i.imgur.com/job0WWd.png) - addr - the start address of the memory buffer that this MR registered - length - the size of the memory buffer that was registered ### 產生一個 QP ```c= struct ibv_qp *ibv_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr); ``` ### 刪掉一個 QP ```c= int ibv_destory_qp(struct ibv_qp *qp); ``` ### 修改一個 QP ```c= int ibv_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, enum ibv_qp_attr_mask attr_mask, struct ibv_qp_init_attr *init_attr); ``` ### 查詢一個 QP ```c= int ibv_query_qp(struct ibv_qp *qp, struct ibv_q_attr *attr, enum ibv_qp_attr_mask attr_mask, struct ibv_qp_init_attr *init_attr); ``` ![](https://i.imgur.com/tENtJxE.png) ![](https://i.imgur.com/LyPqZGM.png) ### 範例 ![](https://i.imgur.com/RXCnGAh.png) ## Scatter/Gather (S/G) element - 每個 work request(WR) 都會有一或多個 S/G entries - Gather - when local data is read and sent over the wire - Scatter - when data is received and written locally ![](https://i.imgur.com/CtbrCPO.png) ## Post Send Request ```c= int ibv_post_send(struct ibv_qp *qp, struct ibv_send_wr *wr, struct ibv_send_wr **bad_wr); ``` :::info ![](https://i.imgur.com/5oBXjsl.png) ![](https://i.imgur.com/57Ee0K9.png) ::: ## Post Receive Request ```c= int ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr, struct ibv_recv_wr **bad_wr); ``` ![](https://i.imgur.com/jH4DGmK.png) ## Polling for Work Completion - polling of WC 會檢查 work request(WR) 是否結束 - WC 會有一個完成的 WR 資訊 - 每個 WC 都會有些 attributes - 以下欄位都會是 valid (就算 WC 是有出 error 的) - wr_id - status - op_num - vendor_err - 其他則看 QP 的 transport type, opcode & status ### Send Request(SR) ㄉ WC - 標記 SR 已執行,記體體暫存區可以被使用 - for reliable transport QP: 代表訊息已經被成功寫進記憶體 - for unreliable transport QP: 代表訊息已從 local port 被送出去 ### Receive Request(RR) ㄉ WC - 標記傳來的訊息已經處理完,資料確定有放入記憶體,記憶體暫存區可以被使用 - 會包含關於傳來訊息的 attributes,像是 size, origin ### API ```c= int ibv_poll_cq(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc); // 回傳負值代表有 error,回傳非負值代表 polled WC 數量 ``` ![](https://i.imgur.com/M2VS5zw.png) ### typical WC status <!-- ![](https://i.imgur.com/NxODDvl.png) --> - IBV_WC_SUCCESS - 成功 - IBV_WC_LOC_LEN_ERR - 例如我送一個 8 byte 東西過去,他卻只給我 4 byte buffer - IBV_WC_LOC_PROT_ERR - S/G 不是指向有效的 MR - IBV_WC_WR_FLUSH_ERR - 當出現問題,queue 裡的 request 都會被 flush 掉,也就是在某個錯誤後面的 request 都會是此錯誤 - 當你把執行到一半的 QP 關掉,剩下的東西也會全部被 flush 掉 - IBV_WC_RETRY_EXC_ERR - 重試太多次無法連線,可能是連線中斷等問題 - IBV_WC_RNR_RETRY_ERR - 資料有成功傳出去,但 receiver 無回應過多次 ### 範例 ![](https://i.imgur.com/lA8P6Bc.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully