pocl icon indicating copy to clipboard operation
pocl copied to clipboard

undefined symbol: _Z9_cl_isinfDv8_Dh'

Open linehill opened this issue 1 year ago • 3 comments

Encountered on OpenVINO running an inference an YOLO model.

Reproducer:

#define CL_HPP_ENABLE_EXCEPTIONS
#include "CL/opencl.hpp"
#include <iostream>
#include <string>

int main() try {
  unsigned PlatformIdx = 0;
  unsigned DeviceIdx = 0;

  std::vector<cl::Platform> Platforms;
  cl::Platform::get(&Platforms);
  cl::Platform Platform = Platforms.at(PlatformIdx);

  std::vector<cl::Device> Devices;
  Platform.getDevices(CL_DEVICE_TYPE_ALL, &Devices);
  cl::Device Device = Devices.at(DeviceIdx);

  auto Source = std::string(R"OCL(
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
global half8 Src = (half8)(1.0h);
global short8 Dst;
kernel void k() { Dst = isinf(Src); }
)OCL");

  auto Program = cl::Program(Source);
  try {
    Program.build("-cl-std=CL3.0");
  } catch (cl::Error &Ex) {
    std::string Log = Program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(Device);
    std::cout << "Error building a program. Build log:\n" << Log << std::endl;
    return 1;
  }

  cl::Kernel K(Program, "k");
  auto Q = cl::CommandQueue::getDefault();
  Q.enqueueNDRangeKernel(K, cl::NullRange, cl::NDRange(1));
  Q.finish();

  std::cout << "Passed!" << std::endl;
  return 0;
} catch (cl::Error &Ex) {
  std::cerr << "Caught OpenCL exception: " << Ex.what() << "\n";
  std::cerr << "Error code: " << Ex.err() << "\n";
  return 2;
} catch (std::exception &Ex) {
  std::cerr << "Caught STL exception: " << Ex.what() << "\n";
  return 2;
}

Produces:

dlopen("/home/linehill/.cache/pocl/kcache/AI/BHKAOJFKKLHMGBPCGPEPJEEBHAGDJEEOBFBBN/k/1-1-1-goffs0-smallgrid/k.so") failed with '/home/linehill/.cache/pocl/kcache/AI/BHKAOJFKKLHMGBPCGPEPJEEBHAGDJEEOBFBBN/k/1-1-1-goffs0-smallgrid/k.so: undefined symbol: _Z9_cl_isinfDv8_Dh'.
note: missing symbols in the kernel binary might be reported as 'file not found' errors.

linehill avatar Sep 17 '24 09:09 linehill

Likely due to half mangling difference between OpenCL C and C. See _Z23intel_sub_group_shuffleDhj in subgroups.c for an example wrapper function.

pjaaskel avatar Sep 17 '24 12:09 pjaaskel

@pjaaskel the example is compiled from source - the SPIR-V wrapper is not involved. More likely due to missing implementation of isinf(half8) in the CPU builtin library. As mentioned in the docs, half support in CPU builtin library is very limited; it was never a priority since it's not natively supported on most existing CPUs.

franz avatar Sep 18 '24 07:09 franz

IIRC this was not due to SPIR-V wrapper but just Clang's mangling difference for half when compiling for OpenCL C instead of C. The isinf(half8) seemed to be there.

pjaaskel avatar Sep 18 '24 07:09 pjaaskel