hcc icon indicating copy to clipboard operation
hcc copied to clipboard

Compiler crash when using std::exp in kernel and compiling with -Ofast flag

Open misos1 opened this issue 7 years ago • 4 comments

Yes I know that I should use exp from fast_math or precise_math but compiler should not crash but either print some errors or successfully compile if std::exp is intended to work in kernel. Also exp without namespace prefix is working.

Some functions cannot be used in both kernel and host code for example on host I can use __builtin_popcount but in kernel I must use hc::__popcount_u32_b32 which I cannot use on host.

hc::array_view<int> result(1);
parallel_for_each(hc::extent<1>(1), [=](hc::index<1> i) [[hc]]
{
	result[0] = std::exp(result[0]);
});
hcc main.cpp `hcc-config --cxxflags` -Ofast
#0 0x00000000014db59a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/opt/rocm/hcc/bin/llc+0x14db59a)
#1 0x00000000014d967e llvm::sys::RunSignalHandlers() (/opt/rocm/hcc/bin/llc+0x14d967e)
#2 0x00000000014d97cc SignalHandler(int) (/opt/rocm/hcc/bin/llc+0x14d97cc)
#3 0x00007f62d4f05150 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13150)
#4 0x0000000000717991 llvm::SITargetLowering::LowerCall(llvm::TargetLowering::CallLoweringInfo&, llvm::SmallVectorImpl<llvm::SDValue>&) const (/opt/rocm/hcc/bin/llc+0x717991)
#5 0x000000000134672e llvm::TargetLowering::LowerCallTo(llvm::TargetLowering::CallLoweringInfo&) const (/opt/rocm/hcc/bin/llc+0x134672e)
#6 0x00000000012fe0c4 (anonymous namespace)::SelectionDAGLegalize::ExpandLibCall(llvm::RTLIB::Libcall, llvm::SDNode*, bool) (/opt/rocm/hcc/bin/llc+0x12fe0c4)
#7 0x00000000012fe382 (anonymous namespace)::SelectionDAGLegalize::ExpandFPLibCall(llvm::SDNode*, llvm::RTLIB::Libcall, llvm::RTLIB::Libcall, llvm::RTLIB::Libcall, llvm::RTLIB::Libcall, llvm::RTLIB::Libcall) (/opt/rocm/hcc/bin/llc+0x12fe382)
#8 0x000000000130673b (anonymous namespace)::SelectionDAGLegalize::ConvertNodeToLibcall(llvm::SDNode*) (/opt/rocm/hcc/bin/llc+0x130673b)
#9 0x00000000013082e7 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) (/opt/rocm/hcc/bin/llc+0x13082e7)
#10 0x000000000130bdc8 llvm::SelectionDAG::Legalize() (/opt/rocm/hcc/bin/llc+0x130bdc8)
#11 0x00000000013bb327 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/rocm/hcc/bin/llc+0x13bb327)
#12 0x00000000013c0dfc llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/rocm/hcc/bin/llc+0x13c0dfc)
#13 0x00000000013c2f82 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/rocm/hcc/bin/llc+0x13c2f82)
#14 0x0000000000cce181 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/rocm/hcc/bin/llc+0xcce181)
#15 0x0000000000fafaca llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/rocm/hcc/bin/llc+0xfafaca)
#16 0x0000000000a64e9e (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) (/opt/rocm/hcc/bin/llc+0xa64e9e)
#17 0x0000000000faf684 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/rocm/hcc/bin/llc+0xfaf684)
#18 0x000000000065d7b3 compileModule(char**, llvm::LLVMContext&) [clone .constprop.398] (/opt/rocm/hcc/bin/llc+0x65d7b3)
#19 0x0000000000603325 main (/opt/rocm/hcc/bin/llc+0x603325)
#20 0x00007f62d3bf61c1 __libc_start_main /build/glibc-itYbWN/glibc-2.26/csu/../csu/libc-start.c:342:0
#21 0x0000000000652779 _start (/opt/rocm/hcc/bin/llc+0x652779)

Also I am getting this in each compilation with hcc (whether successful or not):

objdump: /usr/lib/x86_64-linux-gnu/libm.a: File format not recognized

In this file is:

/* GNU ld script
*/
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /usr/lib/x86_64-linux-gnu/libm-2.26.a /usr/lib/x86_64-linux-gnu/libmvec.a )

misos1 avatar Sep 16 '18 20:09 misos1

Are you using the latest HCC? I do not get a compiler crash running that code. It gives me a linker error because std:exp can't be used here.

If you want to use exp then include hc_math and just use exp normally in the kernel. This complies fine:

#include <hc.hpp>
#include <hc_math.hpp>

int main()
{
	hc::array_view<int> result(1);
	parallel_for_each(hc::extent<1>(1), [=](hc::index<1> i) [[hc]]
	{
		result[0] = exp(result[0]);
	});
	return 0;
}

JMadgwick avatar Sep 17 '18 15:09 JMadgwick

It was on rocm 1.8, now I tested on rocm 1.9 with same results. But it happens only with -Ofast flag:

hcc main.cpp `hcc-config --cxxflags` -Ofast

misos1 avatar Sep 17 '18 16:09 misos1

@misos1 std:: functions are not guaranteed to work in a parallel_for_each unless they are constexpr. In this case exp() is not constexpr.

david-salinas avatar Oct 19 '18 22:10 david-salinas

It should not crash but instead print some errors and then gracefully exit.

misos1 avatar Oct 20 '18 17:10 misos1