Does valgrind recognise values initialized by OpenCL?

Viewed 43

First off, I know that valgrind does not detect errors in code running on the GPU. However, copying a buffer from the GPU back to the CPU uses code on the CPU so valgrind can check that (right?).

I want to know why the following code produces use of uninitialized variable errors when printing the contents of the buffer after running the kernel:

#include <stdio.h>
#include <stdlib.h>

#define CL_TARGET_OPENCL_VERSION 300
#include <CL/cl.h>

typedef struct {
  void *ptr;
  size_t length;
  size_t unit_size;
  cl_mem buf;
} memory;

int mem_init(memory *m, size_t length, size_t unit_size, cl_mem_flags flags, cl_context context) {
  size_t buffer_size = length*unit_size;
  
  m->ptr = malloc(buffer_size);
  if (!m->ptr) return CL_OUT_OF_HOST_MEMORY;
  
  int err;
  m->buf = clCreateBuffer(context, flags|CL_MEM_USE_HOST_PTR, buffer_size, m->ptr, &err);
  if (err) {
    free(m->ptr);
    return err;
  }
  
  m->length = length;
  m->unit_size = unit_size;
  
  return 0;
}

void mem_destroy(memory *m) {
  clReleaseMemObject(m->buf);
  free(m->ptr);
}

int mem_write_buffer(memory *m, cl_command_queue commands, cl_bool blocking) {
  return clEnqueueWriteBuffer(commands, m->buf, blocking, 0, m->length*m->unit_size, m->ptr, 0, NULL, NULL);
}

int mem_read_buffer(memory *m, cl_command_queue commands, cl_bool blocking) {
  return clEnqueueReadBuffer(commands, m->buf, blocking, 0, m->length*m->unit_size, m->ptr, 0, NULL, NULL);
}

const char *kernel_source =
"kernel void test(global float *out, const unsigned length) {\n"
"  int id = get_global_id(0);\n"
"  if (id < (int) length) {\n"
"    out += id;\n"
"    *out = 0.5;\n"
"  }\n"
"}\n"
;

int main() {
  int err;
  cl_device_id device_id;
  
  err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
  if (err) return err;
  cl_context context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
  if (err) return err;
  cl_command_queue commands = clCreateCommandQueueWithProperties(context, device_id, 0, &err);
  if (err) return err;
  cl_program program = clCreateProgramWithSource(context, 1, &kernel_source, NULL, &err);
  if (err) return err;
  err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
  if (err) return err;
  cl_kernel test_kernel = clCreateKernel(program, "test", &err);
  if (err) return err;
  
  size_t max_workgroup_size;
  err = clGetKernelWorkGroupInfo(test_kernel, device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &max_workgroup_size, NULL);
  if (err) return err;
  
  memory buffer;
  err = mem_init(&buffer, 100, sizeof(float), 0, context);
  if (err) return err;
  size_t total_workgroup_size = buffer.length;
  total_workgroup_size += max_workgroup_size - total_workgroup_size%max_workgroup_size;
  
  err = clSetKernelArg(test_kernel, 0, sizeof(cl_mem), &buffer.buf);
  if (err) return err;
  unsigned len = buffer.length;
  err = clSetKernelArg(test_kernel, 1, sizeof(unsigned), &len);
  if (err) return err;
  
  err = clEnqueueNDRangeKernel(commands, test_kernel, 1, NULL, &total_workgroup_size, &max_workgroup_size, 0, NULL, NULL);
  if (err) return err;
  
  clFinish(commands);
  
  err = mem_read_buffer(&buffer, commands, CL_TRUE);
  if (err) return err;
  
  for (float *cur = (float *) buffer.ptr; cur < ((float *) buffer.ptr) + buffer.length; cur++) {
    printf("%f ", *cur);
  }
  printf("\n");
  
  mem_destroy(&buffer);
  clReleaseKernel(test_kernel);
  clReleaseProgram(program);
  clReleaseCommandQueue(commands);
  clReleaseContext(context);
  return 0;
}

...and after building and running it with valgrind ./test valgrind tells me I'm using uninitialized memory:

==10127== Memcheck, a memory error detector
==10127== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==10127== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==10127== Command: ./test
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7408: __printf_fp_l (printf_fp.c:396)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7422: __printf_fp_l (printf_fp.c:396)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D2FF6: __mpn_extract_double (dbl2mpn.c:56)
==10127==    by 0x49D7C06: __printf_fp_l (printf_fp.c:396)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7578: __printf_fp_l (printf_fp.c:437)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D759B: __printf_fp_l (printf_fp.c:437)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D7E1C: __printf_fp_l (printf_fp.c:437)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D75CB: __printf_fp_l (printf_fp.c:438)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D75EE: __printf_fp_l (printf_fp.c:438)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D75F0: __printf_fp_l (printf_fp.c:438)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7619: __printf_fp_l (printf_fp.c:439)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D763E: __printf_fp_l (printf_fp.c:439)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D7640: __printf_fp_l (printf_fp.c:439)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D765E: __printf_fp_l (printf_fp.c:446)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D858C: __printf_fp_l (printf_fp.c:649)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D8B3A: __printf_fp_l (printf_fp.c:665)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D1B2C: __mpn_lshift (lshift.S:59)
==10127==    by 0x49D8B3E: __printf_fp_l (printf_fp.c:665)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D1B2F: __mpn_lshift (lshift.S:60)
==10127==    by 0x49D8B3E: __printf_fp_l (printf_fp.c:665)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D8B6C: __printf_fp_l (printf_fp.c:666)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D8C34: __printf_fp_l (printf_fp.c:677)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D8C25: __printf_fp_l (printf_fp.c:789)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D8D8C: __printf_fp_l (printf_fp.c:791)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D21B8: __mpn_mul_1 (mul_1.S:36)
==10127==    by 0x49D8DAD: __printf_fp_l (printf_fp.c:795)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D2243: __mpn_mul_1 (mul_1.S:85)
==10127==    by 0x49D8DAD: __printf_fp_l (printf_fp.c:795)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D22B2: __mpn_mul_1 (mul_1.S:117)
==10127==    by 0x49D8DAD: __printf_fp_l (printf_fp.c:795)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D8DCD: __printf_fp_l (printf_fp.c:799)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D8DDA: __printf_fp_l (printf_fp.c:800)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D1C4C: __mpn_rshift (rshift.S:62)
==10127==    by 0x49D975C: __printf_fp_l (printf_fp.c:808)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D1C71: __mpn_rshift (rshift.S:73)
==10127==    by 0x49D975C: __printf_fp_l (printf_fp.c:808)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D6B71: hack_digit (printf_fp.c:177)
==10127==    by 0x49D7BC4: __printf_fp_l (printf_fp.c:966)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D21B8: __mpn_mul_1 (mul_1.S:36)
==10127==    by 0x49D6B78: hack_digit (printf_fp.c:178)
==10127==    by 0x49D7BC4: __printf_fp_l (printf_fp.c:966)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D21DC: __mpn_mul_1 (mul_1.S:52)
==10127==    by 0x49D6B78: hack_digit (printf_fp.c:178)
==10127==    by 0x49D7BC4: __printf_fp_l (printf_fp.c:966)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7F00: __printf_fp_l (printf_fp.c:978)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D6B71: hack_digit (printf_fp.c:177)
==10127==    by 0x49D7F1E: __printf_fp_l (printf_fp.c:979)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D21B8: __mpn_mul_1 (mul_1.S:36)
==10127==    by 0x49D6B78: hack_digit (printf_fp.c:178)
==10127==    by 0x49D7F1E: __printf_fp_l (printf_fp.c:979)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D21DC: __mpn_mul_1 (mul_1.S:52)
==10127==    by 0x49D6B78: hack_digit (printf_fp.c:178)
==10127==    by 0x49D7F1E: __printf_fp_l (printf_fp.c:979)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7F3E: __printf_fp_l (printf_fp.c:981)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D7F64: __printf_fp_l (printf_fp.c:983)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7F7C: __printf_fp_l (printf_fp.c:991)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Use of uninitialised value of size 8
==10127==    at 0x49D7F76: __printf_fp_l (printf_fp.c:991)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D7FB1: UnknownInlinedFun (rounding-mode.h:52)
==10127==    by 0x49D7FB1: __printf_fp_l (printf_fp.c:998)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D8234: __printf_fp_l (printf_fp.c:1166)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D87FA: __printf_fp_l (printf_fp.c:1228)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49D87E3: __printf_fp_l (printf_fp.c:1230)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x4A07D9D: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:782)
==10127==    by 0x49D8397: __printf_fp_l (printf_fp.c:1254)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49F3324: __vfprintf_internal (vfprintf-internal.c:1559)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49F3334: UnknownInlinedFun (vfprintf-internal.c:127)
==10127==    by 0x49F3334: __vfprintf_internal (vfprintf-internal.c:1564)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49F333C: __vfprintf_internal (vfprintf-internal.c:1564)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49F2127: UnknownInlinedFun (vfprintf-internal.c:127)
==10127==    by 0x49F2127: outstring_func (vfprintf-internal.c:241)
==10127==    by 0x49F2127: __vfprintf_internal (vfprintf-internal.c:1593)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49F2140: UnknownInlinedFun (vfprintf-internal.c:127)
==10127==    by 0x49F2140: outstring_func (vfprintf-internal.c:241)
==10127==    by 0x49F2140: __vfprintf_internal (vfprintf-internal.c:1593)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Conditional jump or move depends on uninitialised value(s)
==10127==    at 0x49F2148: __vfprintf_internal (vfprintf-internal.c:1593)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
==10127== Syscall param write(buf) points to uninitialised byte(s)
==10127==    at 0x4A8392F: __libc_write (write.c:26)
==10127==    by 0x4A8392F: write (write.c:24)
==10127==    by 0x4A069CC: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1180)
==10127==    by 0x4A05D6F: new_do_write (fileops.c:448)
==10127==    by 0x4A07A38: _IO_do_write@@GLIBC_2.2.5 (fileops.c:425)
==10127==    by 0x4A07E42: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:783)
==10127==    by 0x49FEA94: putchar (putchar.c:28)
==10127==    by 0x401850: main (test.c:114)
==10127==  Address 0x1186b8a2 is 2 bytes inside a block of size 1,024 alloc'd
==10127==    at 0x484586F: malloc (vg_replace_malloc.c:381)
==10127==    by 0x49FAF03: _IO_file_doallocate (filedoalloc.c:101)
==10127==    by 0x4A08B3F: _IO_doallocbuf (genops.c:347)
==10127==    by 0x4A08B3F: _IO_doallocbuf (genops.c:342)
==10127==    by 0x4A07ED7: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:744)
==10127==    by 0x49D8397: __printf_fp_l (printf_fp.c:1254)
==10127==    by 0x49F382C: UnknownInlinedFun (vfprintf-internal.c:354)
==10127==    by 0x49F382C: __vfprintf_internal (vfprintf-internal.c:1558)
==10127==    by 0x49DCA6E: printf (printf.c:33)
==10127==    by 0x40182C: main (test.c:112)
==10127== 
0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 
==10127== 
==10127== HEAP SUMMARY:
==10127==     in use at exit: 317,315 bytes in 116 blocks
==10127==   total heap usage: 229,480 allocs, 229,364 frees, 73,648,723 bytes allocated
==10127== 
==10127== LEAK SUMMARY:
==10127==    definitely lost: 120 bytes in 1 blocks
==10127==    indirectly lost: 0 bytes in 0 blocks
==10127==      possibly lost: 0 bytes in 0 blocks
==10127==    still reachable: 317,195 bytes in 115 blocks
==10127==         suppressed: 0 bytes in 0 blocks
==10127== Rerun with --leak-check=full to see details of leaked memory
==10127== 
==10127== Use --track-origins=yes to see where uninitialised values come from
==10127== For lists of detected and suppressed errors, rerun with: -s
==10127== ERROR SUMMARY: 10201 errors from 51 contexts (suppressed: 0 from 0)

There are a couple of things I can think of that could be causing issues here:

  1. Valgrind does not play nice with OpenCL. Or,
  2. I did something wrong.

I hope it is the former, but I fear it may be the latter as I'm new to using OpenCL. Either way, I'm at my wit's end. Maybe I'm being stupid and I'm wrong about one of my assumptions, but I searched and can't find anything confirming nor denying them. Obviously I searched my questions too but I couldn't find anything.

If my questions were answered somewhere already, could you point me as to where? Or if not,

Did I do something wrong or are OpenCL and valgrind incompatable?
Did I forget to free something or is valgrind raising a false positive about a memory leak too?

0 Answers
Related