[llvm-bugs] [Bug 52019] New: llvm_omp_target_alloc_shared does not allocate memory on device

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 29 23:56:43 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=52019

            Bug ID: 52019
           Summary: llvm_omp_target_alloc_shared does not allocate memory
                    on device
           Product: OpenMP
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Runtime Library
          Assignee: unassignedbugs at nondot.org
          Reporter: itaru.kitayama at gmail.com
                CC: llvm-bugs at lists.llvm.org

Below code does not work on an A100 device:

#include <cstdlib>
#include <new>
#include <limits>
#include <iostream>
#include <vector>
#include <omp.h>
#include <array>

extern "C" {
void* llvm_omp_target_alloc_shared(size_t, int);
}

class A {
public:
  A();
  double get(int slot, int pos) {
    return buffer_[slot][pos];
  }
  std::size_t size() {
    return buffer_.size();
  }

private:
  std::vector<std::array<double,3>> buffer_;
};

A::A()
{
 buffer_.reserve(1024);
 for (int i=0;i<1024;i++)
  buffer_[i].fill(0.1);
}

class B {
public:
  int b;
};
int main()
{
  A *p = (A*)llvm_omp_target_alloc_shared(sizeof(A), 0);
  A *a = new (p) A();
#pragma omp target parallel for
  for (auto i=0;i<2;i++) {
    printf("%f\n", a->get(i,0));
  }

  //omp_target_free(a,0);
  //free(a);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210930/cd6e6763/attachment.html>


More information about the llvm-bugs mailing list