rggjan · GitHub

When running the following code on Windows with ArrayFire v3.1.1, the results are completely broken for Cuda and somewhat broken for OpenCL (assuming the CPU version is correct), unless line 22 is uncommented (which should not change the results):

#include <arrayfire.h>
#include <cstdint>
int main() {
    af::array image = af::readArray("C:/Users/rggjan/tmp/image.raw", "test2");
    af::array depth = af::readArray("C:/Users/rggjan/tmp/array.raw", "test");
    af::array segmentation = af::abs(depth - 587) < 100;
    int x = 771;
    int y = 351;
    int w = 426;
    int h = 429;
    af::array face_mask = segmentation(af::seq(x, x+w-1),
                       af::seq(y, y+h-1), 0);
    af::array face_Y = image(af::seq(y, y+h-1), 0);
    // face_mask = face_mask.as(f32); // Line 22: Uncomment me to get correct results on OpenCL
    af::array hist_vector = face_Y(af::where(face_mask));
    af::array histogram = af::histogram(af::flat(hist_vector), 256, 0, 255);
    af_print(histogram);
  return 0;
}

The results I get are listed here:
https://drive.google.com/open?id=1Nc20pkUxgxw46TeQFHcSk6yQlvd23LUM82r4-y3tjuU

Notice that

  • CPU gives consistent results, no matter if line 22 is commented or not
  • CUDA gives consistent results as well, but different ones
  • OpenCL gives the same results as the CPU version, but only with line 22 uncommented. With line 22 commented, OpenCL gives completely unreasonable results (all values in one bin).

I was not able to reduce the problem further and still get the same results, so I assume that it has something to do with the JIT compiler combining the operations wrongly.

The input files can be downloaded here:
https://drive.google.com/folderview?id=0B0mZY8Aj3NgwVFRyalNkVC1uNlk&usp=sharing

Read the original on github.com ↗