簡體   English   中英

16位浮點MPI_Reduce?

[英]16-bit float MPI_Reduce?

我有一個分布式應用程序,它使用MPI_Reduce()進行某些通信。 在精度方面,我們使用16位浮點數(半精度)獲得完全准確的結果。

為了加速通信(減少數據移動量),有沒有辦法在16位浮點數上調用MPI_Reduce()


(我查看了MPI文檔,但沒有看到有關16位浮點數的任何信息。)

MPI標准在其內部數據類型中僅定義了32位( MPI_FLOAT )或64位( MPI_DOUBLE )浮點數。

但是,您始終可以創建自己的MPI_Datatype和自己的自定義reduce操作。 下面的代碼粗略地說明了如何做到這一點。 由於不清楚你正在使用哪個16位浮點實現,我將簡單地將類型稱為float16_t ,將加法操作稱為fp16_add()

// define custom reduce operation
void my_fp16_sum(void* invec, void* inoutvec, int *len,
              MPI_Datatype *datatype) {
    // cast invec and inoutvec to your float16 type
    float16_t* in = (float16_t)invec;
    float16_t* inout = (float16_t)inoutvec;
    for (int i = 0; i < *len; ++i) {
        // sum your 16 bit floats
        *inout = fp16_add(*in, *inout);
    }
}

// ...

//  in your code:

// create 2-byte datatype (send raw, un-interpreted bytes)
MPI_Datatype mpi_type_float16;
MPI_Type_contiguous(2, MPI_BYTE, &mpi_type_float16);
MPI_Type_commit(&mpi_type_float16);

// create user op (pass function pointer to your user function)
MPI_Op mpi_fp16sum;
MPI_Op_create(&my_fp16_sum, 1, &mpi_fp16sum);

// call MPI_Reduce using your custom reduction operation
MPI_Reduce(&fp16_val, &fp16_result, 1, mpi_type_float16, mpi_fp16sum, 0, MPI_COMM_WORLD);

// clean up (freeing of the custom MPI_Op and MPI_Datatype)
MPI_Type_free(&mpi_type_float16);
MPI_Op_free(&mpi_fp16sum);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM