<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Okay, thanks for the information. Would you please update the bug tracker?<br><br><div dir="ltr">Regards,<div>Shilei</div></div><div dir="ltr"><br><blockquote type="cite">On Feb 24, 2021, at 12:20, Hervé Yviquel <herve@ic.unicamp.br> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div>Dear Shilei,</div><br><div>Thank you, I saw you already submitted a <a href="https://reviews.llvm.org/D97329/new/" title="https://reviews.llvm.org/D97329/new/">fix</a> for the segfault.</div><br><div>You said in the PR that the test pass with NVPTX target but I was wondering if you tried to run it several times: it is failing sometimes but not always when running on my computer with NVTX target (even with your patch) so it makes it a bit complicated to reproduce. </div><br><div>Regards,</div><div>Hervé</div><br><div class="gmail_quote_attribution">On févr. 23 2021, at 3:46 pm, Shilei Tian <tianshilei1992@gmail.com> wrote:</div><blockquote><div>Thanks. I opened a bug to track the issue. <a href="https://bugs.llvm.org/show_bug.cgi?id=49334" title="https://bugs.llvm.org/show_bug.cgi?id=49334">https://bugs.llvm.org/show_bug.cgi?id=49334</a></div><div><br><div><div><div><div>Regards,</div><div>Shilei</div></div></div></div><div><br><blockquote><div>On Feb 19, 2021, at 4:38 PM, Hervé Yviquel <<a href="mailto:herve@ic.unicamp.br" title="mailto:herve@ic.unicamp.br">herve@ic.unicamp.br</a>> wrote:</div><br><div><div>Hi all,</div><br><div>So I took a deeper look at the problems mentioned by Guilherme and here are few observations:</div><br><div>(1) The data corruption of the result of the BlockMatMul is not only happening with x86_64-pc-linux-gnu target but also with nvptx64-nvidia-cuda. So it seems the problems is coming from target-agnostic part of libomptarget and not specifically from the x86 plugin. Please notice the problem does not always appear so you might need to execute it multiple times. Reducing the number of omp threads sometimes helps to reproduce the problem with CUDA plugin.</div><br><blockquote>export OMP_NUM_THREADS=2</blockquote><blockquote>clang++ -O3 -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda BlockMatMul.cpp -o blockmatmul</blockquote><blockquote>for i in {1..100}; do ./blockmatmul || break; done</blockquote><br><div>(2) The segfault in __kmp_push_task is only happening for x86_64-pc-linux-gnu target but it comes from a regression in libomp which seems to have been introduced with the <a href="https://github.com/llvm/llvm-project/commit/9d64275ae08fbdeeca0ce9c2f3951a2de6f38a08#diff-8402e656316eb873d5db4dea7f697406d15ae4197dcc60d88b3d9fc252fcb69a" title="https://github.com/llvm/llvm-project/commit/9d64275ae08fbdeeca0ce9c2f3951a2de6f38a08#diff-8402e656316eb873d5db4dea7f697406d15ae4197dcc60d88b3d9fc252fcb69a">support for hidden helper task in RTL</a> : it is caused because the task_team pointer <a href="https://github.com/llvm/llvm-project/blob/6584a9a4c55e10c055f9f450798b826a9624d82f/openmp/runtime/src/kmp_tasking.cpp#L334" title="https://github.com/llvm/llvm-project/blob/6584a9a4c55e10c055f9f450798b826a9624d82f/openmp/runtime/src/kmp_tasking.cpp#L334">here</a> is NULL. Maybe you guys have an idea on the best way to solve it.</div><br><div>Best regards,</div><div>Hervé</div><br><div class="gmail_quote_attribution">On févr. 13 2021, at 2:18 am, Shilei Tian via Openmp-dev <<a href="mailto:openmp-dev@lists.llvm.org" title="mailto:openmp-dev@lists.llvm.org">openmp-dev@lists.llvm.org</a>> wrote:</div><blockquote><div>Hi Guilherme,</div><div><br></div><div>We do have some bugs on the target <font style="font-family:"Courier New"">x86_64-pc-linux-gnu</font>. Existing test cases in <font style="font-family:"Courier New"">libomptarget</font> can’t all pass (IIRC, three stable failures and one random failure). Therefore, it is expected to see some data racing or corruption on the target.</div><div><br><div><div><div><div>Regards,</div><div>Shilei</div></div></div></div><div><br><blockquote><div>On Feb 12, 2021, at 12:39 PM, Guilherme Valarini via Openmp-dev <<a href="mailto:openmp-dev@lists.llvm.org" title="mailto:openmp-dev@lists.llvm.org">openmp-dev@lists.llvm.org</a>> wrote:</div><br><div><div><div>Hello everyone,</div><br><div>I'm having some data corruption issues when using the generic-elf plugin on the program below (blocked matrix multiplication). I tried to use 3 builds to test this program: the release branches "release/11.x" and "release/12.x", and the main branch as well. I observed the following behavior:</div><br><div>- release/11.x & main: the program works correctly with up to 4 OpenMP threads (OMP_NUM_THREADS=4), but with any number higher than that the result of the operation becomes incorrect. I believe that the problem may also happen with 2-4 threads, but with a lower likelihood to do so (of 500 executions, none have presented the problem);</div><div>- release/12.x: the program crashes due to a segfault inside a function called "__kmp_push_task" from OpenMP runtime regardless of the number of threads.</div><br><div>The program was compiled with the following command after setting the environment variables to point to the correct clang build:</div><br><div>"clang++ -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu BlockMatMul.cpp"</div><br><div>Does anyone know if this is an already known problem (e.g. multiple parallel mappings happening at the same time)? What about the "__kmp_push_task"?</div><br><div>Thanks for the help,</div><div>Guilherme Valarini</div><br><div>Here is the program (sorry I could not come up with a smaller example to post it here). I have dumped the task graph build by OpenMP in a dot/graphviz form and it seems to be correct with the indented dependencies found at the function "BlockMatMul_TargetNowait":</div><br><blockquote><div>#include <assert.h></div><div>#include <math.h></div><div>#include <stdio.h></div><div>#include <stdlib.h></div><div>#include <vector></div><div>#include <sys/time.h></div><div>#include <time.h></div><div>#include <unistd.h></div><div>class BlockMatrix {</div><div>private:</div><div> const int rowsPerBlock;</div><div> const int colsPerBlock;</div><div> const long nRows;</div><div> const long nCols;</div><div> const int nBlocksPerRow;</div><div> const int nBlocksPerCol;</div><div> std::vector<std::vector<float *>> Blocks;</div><div>public:</div><div> BlockMatrix(const int _rowsPerBlock, const int _colsPerBlock,</div><div> const long _nRows, const long _nCols)</div><div> : rowsPerBlock(_rowsPerBlock), colsPerBlock(_colsPerBlock), nRows(_nRows),</div><div> nCols(_nCols), nBlocksPerRow(_nRows / _rowsPerBlock),</div><div> nBlocksPerCol(_nCols / _colsPerBlock) {</div><div> Blocks = std::vector<std::vector<float *>>(nBlocksPerCol);</div><div> for (int i = 0; i < nBlocksPerCol; i++) {</div><div> std::vector<float *> rowBlocks(nBlocksPerRow);</div><div> for (int j = 0; j < nBlocksPerRow; j++) {</div><div> rowBlocks[j] =</div><div> (float *)calloc(_rowsPerBlock * _colsPerBlock, sizeof(float));</div><div> }</div><div> Blocks[i] = rowBlocks;</div><div> }</div><div> };</div><div> ~BlockMatrix() {};</div><div> // Initialize the BlockMatrix from 2D arrays</div><div> void Initialize(float *matrix) {</div><div> for (int i = 0; i < nBlocksPerCol; i++)</div><div> for (int j = 0; j < nBlocksPerRow; j++) {</div><div> float *CurrBlock = GetBlock(i, j);</div><div> for (int ii = 0; ii < colsPerBlock; ++ii)</div><div> for (int jj = 0; jj < rowsPerBlock; ++jj) {</div><div> int curri = i * colsPerBlock + ii;</div><div> int currj = j * rowsPerBlock + jj;</div><div> CurrBlock[ii + jj * colsPerBlock] = matrix[curri + currj * nCols];</div><div> }</div><div> }</div><div> }</div><div> long Compare(float *matrix) {</div><div> long fail=0;</div><div> for (int i = 0; i < nBlocksPerCol; i++)</div><div> for (int j = 0; j < nBlocksPerRow; j++) {</div><div> float *CurrBlock = GetBlock(i, j);</div><div> for (int ii = 0; ii < colsPerBlock; ++ii)</div><div> for (int jj = 0; jj < rowsPerBlock; ++jj) {</div><div> int curri = i * colsPerBlock + ii;</div><div> int currj = j * rowsPerBlock + jj;</div><div> float m_value = matrix[curri + currj * nCols];</div><div> float bm_value = CurrBlock[ii + jj * colsPerBlock];</div><div> if(bm_value != m_value){</div><div> fprintf(stdout, "i,j = %d,%d\n", i, j);</div><div> fprintf(stdout, "BlockMAT[%d][%d] = %f\n", ii, jj, bm_value);</div><div> fprintf(stdout, "MAT[%d][%d] = %f\n", curri, currj, m_value);</div><div> fail++;</div><div> }</div><div> }</div><div> }</div><div> // Print results</div><div> printf("Non-Matching Block Outputs: %ld\n", fail);</div><div> return fail;</div><div> }</div><div> float *GetBlock(int i, int j) {</div><div> assert(i < nBlocksPerCol && j < nBlocksPerRow && "Accessing outside block");</div><div> return Blocks[i][j];</div><div> }</div><div>};</div><br><div>#define BS 256</div><div>#define N 1024</div><br><div>// Initialize matrices.</div><div>void init(float *a, float *b) {</div><div> int i, j;</div><div> for (i = 0; i < N; ++i) {</div><div> for (j = 0; j < N; ++j) {</div><div> a[i * N + j] = (float)i + j % 100;</div><div> b[i * N + j] = (float)i + j % 100;</div><div> }</div><div> }</div><div>}</div><div>int BlockMatMul_TargetNowait(BlockMatrix &A, BlockMatrix &B, BlockMatrix &C) {</div><div> #pragma omp parallel</div><div> #pragma omp master</div><div> for (int i = 0; i < N / BS; ++i)</div><div> for (int j = 0; j < N / BS; ++j) {</div><div> float *BlockC = C.GetBlock(i, j);</div><div> for (int k = 0; k < N / BS; ++k) {</div><div> float *BlockA = A.GetBlock(i, k);</div><div> float *BlockB = B.GetBlock(k,j);</div><div> #pragma omp target depend(in: BlockA[0], BlockB[0]) \</div><div> depend(inout: BlockC[0]) \</div><div> map(to: BlockA[:BS*BS], BlockB[:BS*BS]) \</div><div> map(tofrom: BlockC[:BS*BS]) nowait</div><div> #pragma omp parallel for</div><div> for(int ii = 0; ii < BS; ii++)</div><div> for(int jj = 0; jj < BS; jj++) {</div><div> for(int kk = 0; kk < BS; ++kk)</div><div> BlockC[ii + jj * BS] += BlockA[ii + kk * BS] * BlockB[kk + jj * BS];</div><div> }</div><div> }</div><div> }</div><div> return 0;</div><div>}</div><div>void Matmul(float *a, float *b, float *c) {</div><div> for (int i = 0; i < N; ++i) {</div><div> for (int j = 0; j < N; ++j) {</div><div> float sum = 0.0;</div><div> for (int k = 0; k < N; ++k) {</div><div> sum = sum + a[i * N + k] * b[k * N + j];</div><div> }</div><div> c[i * N + j] = sum;</div><div> }</div><div> }</div><div>}</div><div>int main(int argc, char *argv[]) {</div><div> double t_start, t_end;</div><div> int ret = 0;</div><div> float *a = (float *)malloc(sizeof(float) * N * N);</div><div> float *b = (float *)malloc(sizeof(float) * N * N);</div><div> float *c = (float *)calloc(sizeof(float), N * N);</div><div> init(a, b);</div><div> auto BlockedA = BlockMatrix(BS, BS, N, N);</div><div> BlockedA.Initialize(a);</div><div> BlockedA.Compare(a);</div><div> auto BlockedB = BlockMatrix(BS, BS, N, N);</div><div> BlockedB.Initialize(b);</div><div> BlockedB.Compare(b);</div><div> Matmul(a, b, c);</div><div> auto BlockedC = BlockMatrix(BS, BS, N, N);</div><div> BlockMatMul_TargetNowait(BlockedA, BlockedB, BlockedC);</div><div> if(BlockedC.Compare(c) > 0) {</div><div> // exit code to error if there is any missmatch</div><div> ret = 1;</div><div> }</div><div> free(a);</div><div> free(b);</div><div> free(c);</div><div> return ret;</div><div>}</div></blockquote></div><div>_______________________________________________</div><div>Openmp-dev mailing list</div><div><a href="mailto:Openmp-dev@lists.llvm.org" title="mailto:Openmp-dev@lists.llvm.org">Openmp-dev@lists.llvm.org</a></div><div><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev" title="https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev</a></div></div></blockquote></div><br></div><div>_______________________________________________</div><div>Openmp-dev mailing list</div><div><a href="mailto:Openmp-dev@lists.llvm.org" title="mailto:Openmp-dev@lists.llvm.org">Openmp-dev@lists.llvm.org</a></div><div><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev" title="https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev</a></div></blockquote></div></blockquote></div></div></blockquote></div></blockquote></body></html>