google / xls

XLS: Accelerated HW Synthesis
http://google.github.io/xls/
Apache License 2.0
1.21k stars 178 forks source link

Investigate Csmith for fuzzing xlscc #598

Open meheff opened 2 years ago

meheff commented 2 years ago

I wonder if Csmith would be useful for generating random input programs for fuzzing xlscc. It might need to be augmented with a wrapper which does I/O and feeds Csmith-generated functions. Not sure if Csmith would be able to generate ac_int types, however it probably would be good at stress testing other parts of xlscc such as control flow handling.

ted-xie commented 2 years ago

I very briefly took a stab at this and found a couple obstacles:

cdleary commented 2 years ago

@ted-xie Did it feel like the obstacles could be handled with a rewrite / "early rejection script" pre-pass kind of thing?

(I imagine one of the challenges is that most of the interesting things are to do with ac_int types, as @meheff mentioned, and we won't be generating those.)

ted-xie commented 2 years ago

@cdleary XLScc was failing fast enough - iteration time was not the issue, but rather just getting the frontend to pass. I hadn't even gotten to the ac_int part yet.

My memory is already a little foggy on this since I looked at it 3 weeks ago, but IIRC the main issue was that the cmsith headers themselves would pull in system includes such as string.h. I think we might need some kind of basic postprocessor that dumps out just the kernel generated by CSmith that has as few dependencies as possible. Ideally we'd be able to generate the testbench (i.e. main()) and the kernel compilation unit separately. What do you think?

ted-xie commented 2 years ago

Alternatively, if there's an XLScc flag that tells the frontend to not choke on string.h, stdint.h etc that would be great too!

ted-xie commented 2 years ago

@JoshVarga @spurserh

Poked around with this a little more, couple updates:

After all of the various hacks, we can get a first-pass reading on the csmith-generated file:

412 warnings generated.
UNIMPLEMENTED: For loop missing #pragma
   --> ./foo.cc:111:5
    |
111 |     for (i = 0; i < 5; i++)
    |     ^

command: bazel-bin/xls/contrib/xlscc/xlscc foo.cc --clang_args_file clang.args --top func_1

I hacked up some sed magic to automatically insert pragmas in front of for loops and ran into other issues.