LLVM Backend for riscv (follow up )

Following up with my forum post, Using LLVM Target for RISCV (incompatibility error) I tried to implement the workaround that was suggested to solve the soft floating issue , added to some other approaches. Automatically by exporting the IR editing the cc by setting the shared to false and appendding new arguments to the cmd list i go this

While saving the IR module as .s file and calling the compiler to generate the object files (either manually or by editing the tvm cc ) I ran into similar ABI incompatibility. The issue for the manual workaround using this code snippet
a,c_mod,b = relay.build(self.mod, self.target, params=self.params) # here just to get c_mod to be an IR module type to be able to use (.save on it )

lib = export_path/"lib.s" c_mod.save(str(lib))

The thing with this approach the .S text file contains only supported tvm functions without the kernel functions

.Lfunc_end0:
	.size	TVMSystemLibEntryPoint, 
.Lfunc_end0-TVMSystemLibEntryPoint
	.cfi_endproc

.type	_tvm_func_registry_ptrs,@object
.section	.data.rel.ro,"aw",@progbits
.p2align	2
_tvm_func_registry_ptrs:
	.word	fused_nn_contrib_dense_pack_add
	.word	fused_nn_contrib_dense_pack_add_nn_relu
	.word	fused_nn_contrib_dense_pack_add_nn_relu_1
	.size	_tvm_func_registry_ptrs, 12

.type	.L.str,@object
.section	.rodata,"a",@progbits
.L.str:
	.asciz	"\003fused_nn_contrib_dense_pack_add\000fused_nn_contrib_dense_pack_add_nn_relu\000fused_nn_contrib_dense_pack_add_nn_relu_1\000"
	.size	.L.str, 116

.type	_tvm_crt_func_registry,@object
.section	.data.rel.ro,"aw",@progbits
.p2align	3
_tvm_crt_func_registry:
	.word	.L.str
	.word	_tvm_func_registry_ptrs
	.size	_tvm_crt_func_registry, 8

.type	_tvm_crt_module,@object
.p2align	3
_tvm_crt_module:
	.word	_tvm_crt_func_registry
	.size	_tvm_crt_module, 4

.section	.debug_abbrev,"",@progbits
.byte	1
.byte	17
.byte	0
.byte	37
.byte	14
.byte	19
.byte	5
.byte	3
.byte	14
.byte	16
.byte	23
.byte	27
.byte	14
.ascii	"\264B"
.byte	25
.ascii	"\261B"
.byte	7
.byte	0
.byte	0
.byte	0
.section	.debug_info,"",@progbits
.Lcu_begin0:
	.word	.Ldebug_info_end0-.Ldebug_info_start0
.Ldebug_info_start0:
	.half	4
	.word	.debug_abbrev
	.byte	4
	.byte	1
	.word	.Linfo_string0
	.half	2
	.word	.Linfo_string1
	.word	.Lline_table_start0
	.word	.Linfo_string2

	.quad	1
.Ldebug_info_end0:
	.section	.debug_str,"MS",@progbits,1
.Linfo_string0:
	.asciz	"TVM"
.Linfo_string1:
	.asciz	"model.tvm"
.Linfo_string2:
	.asciz	"/tmp/"
	.section	.debug_pubnames,"",@progbits
	.word	.LpubNames_end0-.LpubNames_begin0
.LpubNames_begin0:
	.half	2
	.word	.Lcu_begin0
	.word	38
	.word	0
.LpubNames_end0:
	.section	.debug_pubtypes,"",@progbits
	.word	.LpubTypes_end0-.LpubTypes_begin0
.LpubTypes_begin0:
	.half	2
	.word	.Lcu_begin0
	.word	38
	.word	0
.LpubTypes_end0:
	.section	".note.GNU-stack","",@progbits
	.section	.debug_line,"",@progbits
.Lline_table_start0:

Is there a way to get the kernel function implementations as .s file, in order to manually edit the incompatible line of codes causing this error before calling the compiler

Thank you in advance

1 Like

hi @heatdh,

i believe the kernels are in c_mod.imported_modules[0]. can you try c_mod.imported_modules[0].save("lib.s")?

andrew

1 Like

Hey @areusch, Thank you, this generated the files I needed. However, I’m still getting the soft float to double float issue after generating the .o files

Rayen

glad it helped. I don’t know offhand why this would be happening; it seems like LLVM should support double. it seems likely we are misconfiguring it. if you find anything, please feel free to send a PR!

-Andrew