Skip to content

using conditionally chosen function in cuda()/nvvm() triggers assertion #128

@michael-kenzel

Description

@michael-kenzel

the following code will reproduce the issue:

#[import(cc = "thorin")] fn nvvm(_dev: i32, _grid: (i32, i32, i32), _block: (i32, i32, i32), _body: fn() -> ()) -> ();
#[import(cc = "device")] fn threadfence() -> ();

#[export]
fn test(b: bool) -> () {
	let fun = if b { @|| { asm("nanosleep.u32 0;"); } } else { threadfence };

	nvvm(0, (1, 1, 1), (1, 1, 1), @|| {
		fun();
	});
}

compilation via artic with --emit-llvm results in

src/thorin/util/cast.h:42: L* thorin::scast(R*) [with L = thorin::Global; R = thorin::Def]: Assertion `(!r || dynamic_cast<L*>(r)) && "cast not possible"' failed.

Various seemingly irrelevant changes to the code such as, e.g., turning the else option in the initalization into a lambda that simply forwards to the original function

	let fun = if b { @|| { asm("nanosleep.u32 0;"); } } else { @|| threadfence() };

seem to resolve the issue in some cases but not others. None of these workarounds appear to be reliable in the context of a more complex codebase; something what worked in one example won't work in another.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions