halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.88k stars 1.07k forks source link

Segfault after compiled to file #1218

Open zydo opened 8 years ago

zydo commented 8 years ago

I defined Func's and pipelined, then compiled to <header, object> pair. When I link it to executable and run, it comes with segfault. I checked with valgrind, information like so:

==12442== Command: ./network_run_single test_labeled_images/AND00.png ==12442== ==12442== Invalid read of size 4 ==12442== at 0x408438: __network_aot (in xxxxxxxxxxxxxxx/network_run_single) ==12442== by 0x466: ??? ==12442== by 0x1F25BC1: ??? ==12442== by 0xF00000000: ???**** ==12442== Address 0x413000 is not stack'd, malloc'd or (recently) free'd

network_aot.h network_aot.o are compiled from network.cpp. Since no source file, valgrind cannot tell errors in network_aot.o at exact line.

Here is what I basically did in network.cpp:

  1. Read parameters to halide image object
  2. Define input image: ImageParam input(type_of(), 3);
  3. Define layers of Func
  4. Schedule Func
  5. Compile to file to <network_aot.o, network_aot.h>

Then I called network_aot(args, output) in network_run_single.cpp, compiled, run with segfault.

How can I debug such kind of error?

abadams commented 8 years ago

The most like cause of this is a buffer_t with some bogus fields. How are you setting up your buffer_t?

On Tue, May 17, 2016 at 5:14 PM, Ziyu Dong notifications@github.com wrote:

I defined Func's and pipelined, then compiled to pair. When I link it to executable and run, it comes with segfault. I checked with valgrind, information like so:

==12442== Command: ./network_run_single test_labeled_images/AND00.png ==12442== ==12442== Invalid read of size 4 ==12442== at 0x408438: __network_aot (in xxxxxxxxxxxxxxx/network_run_single)

==12442== by 0x466: ??? *==12442== by 0x1F25BC1: ???* ==12442== by 0xF00000000: ???** ==12442== Address 0x413000 is not stack'd, malloc'd or (recently) free'd

network_aot.h network_aot.o are compiled from network.cpp. Since no source file, valgrind cannot tell errors in network_aot.o at exact line.

Here is what I basically did in network.cpp:

  1. Read parameters to halide image object
  2. Define input image: ImageParam input(type_of(), 3);
  3. Define layers of Func
  4. Schedule Func
  5. Compile to file to

Then I called network_aot(args, output) in network_run_single.cpp, compiled, run with segfault.

How can I debug such kind of error?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/halide/Halide/issues/1218

zydo commented 8 years ago

I read a png from file and fit it to buffer_t at first. Then I used more simple buffer_t, but still error:

buffer_t input_buf = {0}; input_buf.host = new uint8_t[64 * 64 * 1]; for (int z = 0; z < 1; z++) { for (int y = 0; y < 64; y++) { for (int x = 0; x < 64; x++) { input_buf.host[z * 64 * 64 + y * 64 + x] = 1; } } }

input_buf.extent[0] = 64; input_buf.extent[1] = 64; input_buf.extent[2] = 1;

input_buf.stride[0] = 1; input_buf.stride[1] = 64; input_buf.stride[2] = 64;

input_buf.elem_size = sizeof(uint8_t);

My output buffer should be at size 7x1x1 floating-point, so:

buffer_t output_buf = {0};

float* output = new float[7]; output_buf.host = (uint8_t *) output;

output_buf.stride[0] = 1; output_buf.stride[1] = 7; output_buf.stride[2] = 7;

output_buf.extent[0] = 7; output_buf.extent[0] = 1; output_buf.extent[0] = 1;

output_buf.elem_size = sizeof(float);