tancheng / CGRA-Mapper

An LLVM pass that can generate CDFG and map the target loops onto a parameterizable CGRA.
BSD 3-Clause "New" or "Revised" License
53 stars 8 forks source link

Error occurs when test the "run.sh" #5

Closed Dtristone closed 2 years ago

Dtristone commented 3 years ago

Hello! I am trying to using your tools to map same simple kernel to a cgra for my researh. I installed the llvm-11 from source code and use cmake-16 firstly, and then I compiled the cgra mapper successfully, but I met the following bug when I run the test script “run.sh” under the test folder:

terminate called after throwing an instance of 'nlohmann::detail::parse_error'
  what():  [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.  Program arguments: opt -load ../../CGRA-Mapper/build/mapper/libmapperPass.so -mapperPass kernel.bc -f 
1.  Running pass 'Function Pass Manager' on module 'kernel.bc'.
2.  Running pass 'DFG Pass Analyse' on function '@main'
 #0 0x000055a173392b3e llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/bin/opt+0x2c63b3e)
 #1 0x000055a173390914 llvm::sys::RunSignalHandlers() (/usr/local/bin/opt+0x2c61914)
 #2 0x000055a173390a58 SignalHandler(int) (/usr/local/bin/opt+0x2c61a58)
 #3 0x00007f896b1a13c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f896ac7018b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #5 0x00007f896ac4f859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #6 0x00007f896b026911 (/lib/x86_64-linux-gnu/libstdc++.so.6+0x9e911)
 #7 0x00007f896b03238c (/lib/x86_64-linux-gnu/libstdc++.so.6+0xaa38c)
 #8 0x00007f896b0323f7 (/lib/x86_64-linux-gnu/libstdc++.so.6+0xaa3f7)
 #9 0x00007f896b0326a9 (/lib/x86_64-linux-gnu/libstdc++.so.6+0xaa6a9)
#10 0x00007f896abf6bb0 bool nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, nlohmann::detail::input_stream_adapter>::sax_parse_internal<nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > > >(nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > >*) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0x1cbb0)
#11 0x00007f896abf1475 nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, nlohmann::detail::input_stream_adapter>::parse(bool, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >&) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0x17475)
#12 0x00007f896abeff5c nlohmann::operator>>(std::istream&, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >&) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0x15f5c)
#13 0x00007f896abee032 (anonymous namespace)::mapperPass::runOnFunction(llvm::Function&) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0x14032)
#14 0x000055a172b4736c llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/bin/opt+0x241836c)
#15 0x000055a172b47a39 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/bin/opt+0x2418a39)
#16 0x000055a172b46527 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/opt+0x2417527)
#17 0x000055a170ece7b5 main (/usr/local/bin/opt+0x79f7b5)
#18 0x00007f896ac510b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#19 0x000055a170f6b3fe _start (/usr/local/bin/opt+0x83c3fe)
./run.sh: line 1:  8646 Aborted                 (core dumped) opt -load ../../CGRA-Mapper/build/mapper/libmapperPass.so -mapperPass kernel.bc -f

I lack the experience of developing a llvm pass so I donnot know how to solve it. Is it result from my using a cmake-1.6 rather than the required cmake1.0 or something else?

tancheng commented 3 years ago

Thanks for your interest in the tool. I think the problem is about the input. The "nlohmann json paser" assume there is a param.json in the kernel folder. You can see one example here. Is there a param.json in your kernel folder? Please let me know if it still doesn't work after you put a param.json in the folder. I will try to provide a tutorial/readme meanwhile...

Dtristone commented 3 years ago

Yeah! This problem is solved after I add the file, but another problem occurs when "[generate dot for DFG]":

.....
==================================
[show opcode count]
add : 2
br : 4
fadd : 1
fmul : 1
getelementptr : 3
icmp : 2
load : 3
phi : 3
ret : 1
store : 1
DFG node count: 21; DFG edge count: 34
==================================
[generate dot for DFG]
opt: /home/llvmsrc/llvm/lib/Support/raw_ostream.cpp:839: virtual size_t llvm::raw_fd_ostream::preferred_buffer_size() const: Assertion `FD >= 0 && "File not yet open!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.  Program arguments: opt -load ../../CGRA-Mapper/build/mapper/libmapperPass.so -mapperPass kernel.bc -o /dev/null 
1.  Running pass 'Function Pass Manager' on module 'kernel.bc'.
2.  Running pass 'DFG Pass Analyse' on function '@_Z6kernelPfS_S_'
 #0 0x0000561fa927eb3e llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/bin/opt+0x2c63b3e)
 #1 0x0000561fa927c914 llvm::sys::RunSignalHandlers() (/usr/local/bin/opt+0x2c61914)
 #2 0x0000561fa927ca58 SignalHandler(int) (/usr/local/bin/opt+0x2c61a58)
 #3 0x00007f8c3e87e3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f8c3e34d18b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #5 0x00007f8c3e32c859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #6 0x00007f8c3e32c729 (/lib/x86_64-linux-gnu/libc.so.6+0x25729)
 #7 0x00007f8c3e33df36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
 #8 0x0000561fa925865e llvm::raw_fd_ostream::preferred_buffer_size() const (/usr/local/bin/opt+0x2c3d65e)
 #9 0x0000561fa9258c54 llvm::raw_ostream::SetBuffered() (/usr/local/bin/opt+0x2c3dc54)
#10 0x0000561fa92591ec llvm::raw_ostream::write(char const*, unsigned long) (/usr/local/bin/opt+0x2c3e1ec)
#11 0x0000561fa922ff2d llvm::Twine::print(llvm::raw_ostream&) const (/usr/local/bin/opt+0x2c14f2d)
#12 0x0000561fa922ff2d llvm::Twine::print(llvm::raw_ostream&) const (/usr/local/bin/opt+0x2c14f2d)
#13 0x00007f8c3e2b0e2e llvm::operator<<(llvm::raw_ostream&, llvm::Twine const&) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0xeae2e)
#14 0x00007f8c3e2ad204 DFG::generateDot(llvm::Function&, bool) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0xe7204)
#15 0x00007f8c3e2794a1 (anonymous namespace)::mapperPass::runOnFunction(llvm::Function&) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0xb34a1)
#16 0x0000561fa8a3336c llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/bin/opt+0x241836c)
#17 0x0000561fa8a33a39 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/bin/opt+0x2418a39)
#18 0x0000561fa8a32527 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/opt+0x2417527)
#19 0x0000561fa6dba7b5 main (/usr/local/bin/opt+0x79f7b5)
#20 0x00007f8c3e32e0b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#21 0x0000561fa6e573fe _start (/usr/local/bin/opt+0x83c3fe)
./run.sh: line 1:  9144 Aborted                 (core dumped) opt -load ../../CGRA-Mapper/build/mapper/libmapperPass.so -mapperPass kernel.bc -o /dev/null

I run the "run.sh" in the folder "CGRA-Bench/kernels/fir" but the result is the same with above.

Dtristone commented 3 years ago

Yeah! This problem is solved after I add the file, but another problem occurs when "[generate dot for DFG]":

.....
==================================
[show opcode count]
add : 2
br : 4
fadd : 1
fmul : 1
getelementptr : 3
icmp : 2
load : 3
phi : 3
ret : 1
store : 1
DFG node count: 21; DFG edge count: 34
==================================
[generate dot for DFG]
opt: /home/llvmsrc/llvm/lib/Support/raw_ostream.cpp:839: virtual size_t llvm::raw_fd_ostream::preferred_buffer_size() const: Assertion `FD >= 0 && "File not yet open!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.    Program arguments: opt -load ../../CGRA-Mapper/build/mapper/libmapperPass.so -mapperPass kernel.bc -o /dev/null 
1.    Running pass 'Function Pass Manager' on module 'kernel.bc'.
2.    Running pass 'DFG Pass Analyse' on function '@_Z6kernelPfS_S_'
 #0 0x0000561fa927eb3e llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/bin/opt+0x2c63b3e)
 #1 0x0000561fa927c914 llvm::sys::RunSignalHandlers() (/usr/local/bin/opt+0x2c61914)
 #2 0x0000561fa927ca58 SignalHandler(int) (/usr/local/bin/opt+0x2c61a58)
 #3 0x00007f8c3e87e3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f8c3e34d18b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #5 0x00007f8c3e32c859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #6 0x00007f8c3e32c729 (/lib/x86_64-linux-gnu/libc.so.6+0x25729)
 #7 0x00007f8c3e33df36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
 #8 0x0000561fa925865e llvm::raw_fd_ostream::preferred_buffer_size() const (/usr/local/bin/opt+0x2c3d65e)
 #9 0x0000561fa9258c54 llvm::raw_ostream::SetBuffered() (/usr/local/bin/opt+0x2c3dc54)
#10 0x0000561fa92591ec llvm::raw_ostream::write(char const*, unsigned long) (/usr/local/bin/opt+0x2c3e1ec)
#11 0x0000561fa922ff2d llvm::Twine::print(llvm::raw_ostream&) const (/usr/local/bin/opt+0x2c14f2d)
#12 0x0000561fa922ff2d llvm::Twine::print(llvm::raw_ostream&) const (/usr/local/bin/opt+0x2c14f2d)
#13 0x00007f8c3e2b0e2e llvm::operator<<(llvm::raw_ostream&, llvm::Twine const&) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0xeae2e)
#14 0x00007f8c3e2ad204 DFG::generateDot(llvm::Function&, bool) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0xe7204)
#15 0x00007f8c3e2794a1 (anonymous namespace)::mapperPass::runOnFunction(llvm::Function&) (../../CGRA-Mapper/build/mapper/libmapperPass.so+0xb34a1)
#16 0x0000561fa8a3336c llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/bin/opt+0x241836c)
#17 0x0000561fa8a33a39 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/bin/opt+0x2418a39)
#18 0x0000561fa8a32527 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/opt+0x2417527)
#19 0x0000561fa6dba7b5 main (/usr/local/bin/opt+0x79f7b5)
#20 0x00007f8c3e32e0b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#21 0x0000561fa6e573fe _start (/usr/local/bin/opt+0x83c3fe)
./run.sh: line 1:  9144 Aborted                 (core dumped) opt -load ../../CGRA-Mapper/build/mapper/libmapperPass.so -mapperPass kernel.bc -o /dev/null

I run the "run.sh" in the folder "CGRA-Bench/kernels/fir" but the result is the same with above.

I change the "kernel" from "_Z3firPfSS" to "main" in the param.json and the problem disappers.

tancheng commented 3 years ago

Ha, yes. The kernel's name should be as same as it is shown in the IR (.ll). Different versions of the LLVM might give a function a different name. So now it can complete? And you probably have a _Z3firPfS_S_.dot generated. And you can use dot.sh to generate the DFG figure in .png. You can also see the mapping of the DFG on the target CGRA (if it works well).

Dtristone commented 3 years ago

Ha, yes. The kernel's name should be as same as it is shown in the IR (.ll). Different versions of the LLVM might give a function a different name. So now it can complete? And you probably have a _Z3firPfS_S_.dot generated. And you can use dot.sh to generate the DFG figure in .png. You can also see the mapping of the DFG on the target CGRA (if it works well).

If I use the original "_Z3firPfSS“ as the kernel name, it will go wrong. But I if change the target kernel's name from "_Z3firPfSS" (with "_")to "fir" in the .ll file and convert it back to .bc file, the program works fine. Maybe the "_" in the kernel name can affect the creating of the target file in my computer environment?

tancheng commented 3 years ago

You can either use the existing names to replace your .ll or explicitly define a name in the param.json. Both should work. Please let me know if there is anything else I can help!