aomp icon indicating copy to clipboard operation
aomp copied to clipboard

memcmp() not defined

Open jtramm opened this issue 3 years ago • 0 comments
trafficstars

The STL function memcmp() does not appear to be available on device. While much of the STL is not expected to be present for device regions, typically simple functions like memcpy are. Notably, memcmp() is supported by other compilers targeting AMD GPUs (including LLVM Clang), so it seems like adding support should be easy.

For instance, take the following code:

#include <string.h>
#include <stdlib.h>
#include <assert.h>

int main(void)
{
  int n = 128;
  int sz = n * sizeof(int);
  int* a = (int*) malloc(sz);
  int* b = (int*) malloc(sz);
  for(int i = 0; i < n; i++)
  {
    a[i] = i;
    b[i] = i;
  }

  #pragma omp target enter data map(to: a[:n], b[:n])

  int ret;
  #pragma omp target map(from:ret)
  {
    ret = memcmp(a, b, sz);
  }

  assert(ret == 0);

  #pragma omp target exit data map(from: a[:n], b[:n])

  return 0;
}

and compile/run as:

jtramm@amdgpu02:~/omp_target_issues/memcmp$ clang++ --version
AOMP_STANDALONE_15.0-2 clang version 15.0.0 (https://github.com/radeonopencompute/llvm-project 651deba7aa2805d1fe19ace427548f42f2c7a29f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /soft/compilers/AOMP/aomp_15.0-2/bin
jtramm@amdgpu02:~/omp_target_issues/memcmp$ make
clang++ -Wall -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx908 -c main.cpp -o main.o
clang++ -Wall -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx908 main.o -o test
lld: error: undefined symbol: memcmp
>>> referenced by /tmp/main-155f81-gfx908-5875ad.o:(__omp_offloading_31_78683268_main_l20)
>>> referenced by /tmp/main-155f81-gfx908-5875ad.o:(__omp_offloading_31_78683268_main_l20)
clang-15: error: amdgcn-link command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:37: test] Error 1

jtramm avatar Sep 26 '22 17:09 jtramm