Skip to content

optix: Fix coopvec emission #7312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mkeshavaNV opened this issue Jun 3, 2025 · 1 comment
Open

optix: Fix coopvec emission #7312

mkeshavaNV opened this issue Jun 3, 2025 · 1 comment

Comments

@mkeshavaNV
Copy link
Contributor

mkeshavaNV commented Jun 3, 2025

While working on PR #7286 it was noticed that the emission of Coopvec has some issues. Here's the problem. Generate cuda output for the tests/cuda/optix-coopvec.slang test and you will see this:

#line 29
    OptixCoopVec<float, 4> _S8;

#line 29
    optixCoopVecTanh((_S6));

and then:

#line 29
    OptixCoopVec<float, 4> _S9 = _S8;

But it should be: OptixCoopVec<float, 4> _S8 = optixCoopVecTanh((_S6));

What I observe is that inside void CLikeSourceEmitter::emitInstResultDecl(IRInst* inst), I see that
for auto type = inst->getDataType();, type is returned as kIROp_VoidType. So this function terminates earlier because of this check:

if (as<IRVoidType>(type))
    return;

When creating the inst for tanh, I see:

 	slang.dll!Slang::IRBuilder::_createInst(unsigned __int64 minSizeInBytes, Slang::IRType * type, Slang::IROp op, __int64 fixedArgCount, Slang::IRInst * const * fixedArgs, __int64 varArgListCount, const __int64 * listArgCounts, Slang::IRInst * const * const * listArgs) Line 1866	C++
 	slang.dll!Slang::createInstImpl<Slang::IRCall>(Slang::IRBuilder * builder, Slang::IROp op, Slang::IRType * type, __int64 fixedArgCount, Slang::IRInst * const * fixedArgs, __int64 varArgListCount, const __int64 * listArgCounts, Slang::IRInst * const * const * listArgs) Line 1931	C++
 	slang.dll!Slang::createInstImpl<Slang::IRCall>(Slang::IRBuilder * builder, Slang::IROp op, Slang::IRType * type, __int64 fixedArgCount, Slang::IRInst * const * fixedArgs, __int64 varArgCount, Slang::IRInst * const * varArgs) Line 1952	C++
 	slang.dll!Slang::createInstWithTrailingArgs<Slang::IRCall>(Slang::IRBuilder * builder, Slang::IROp op, Slang::IRType * type, __int64 fixedArgCount, Slang::IRInst * const * fixedArgs, __int64 varArgCount, Slang::IRInst * const * varArgs) Line 2028	C++
 	slang.dll!Slang::IRBuilder::emitCallInst(Slang::IRType * type, Slang::IRInst * pFunc, unsigned __int64 argCount, Slang::IRInst * const * args) Line 3897	C++
 	slang.dll!Slang::IRBuilder::emitCallInst(Slang::IRType * type, Slang::IRInst * func, const Slang::List<Slang::IRInst *,Slang::StandardAllocator> & args) Line 4149	C++
>	slang.dll!Slang::makeFuncReturnViaOutParam(Slang::IRBuilder & builder, Slang::IRFunc * func) Line 75	C++
 	slang.dll!Slang::legalizeArrayReturnType(Slang::IRModule * module) Line 94	C++
 	slang.dll!Slang::linkAndOptimizeIR(Slang::CodeGenContext * codeGenContext, const Slang::LinkingAndOptimizationOptions & options, Slang::LinkedIR & outLinkedIR) Line 1695	C++
 	slang.dll!Slang::CodeGenContext::emitEntryPointsSourceFromIR(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 1995	C++
 	slang.dll!Slang::CodeGenContext::emitEntryPointsSource(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 794	C++
 	slang.dll!Slang::CodeGenContext::emitEntryPoints(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 1993	C++
 	slang.dll!Slang::TargetProgram::_createWholeProgramResult(Slang::DiagnosticSink * sink, Slang::EndToEndCompileRequest * endToEndReq) Line 2134	C++
 	slang.dll!Slang::EndToEndCompileRequest::generateOutput(Slang::TargetProgram * targetProgram) Line 2217	C++
 	slang.dll!Slang::EndToEndCompileRequest::generateOutput(Slang::ComponentType * program) Line 2586	C++
 	slang.dll!Slang::EndToEndCompileRequest::generateOutput() Line 2598	C++
 	slang.dll!Slang::EndToEndCompileRequest::executeActionsInner() Line 3940	C++
 	slang.dll!Slang::EndToEndCompileRequest::executeActions() Line 3949	C++
 	slang.dll!Slang::EndToEndCompileRequest::compile() Line 7510	C++
 	slang.dll!spCompile(slang::ICompileRequest * request) Line 720	C++
 	slangc.exe!_compile(slang::ICompileRequest * compileRequest, int argc, const char * const * argv) Line 54	C++
 	slangc.exe!innerMain(Slang::StdWriters * stdWriters, slang::IGlobalSession * sharedSession, int argc, const char * const * argv) Line 119	C++
 	slangc.exe!slangc_main(int argc, char * * argv) Line 129	C++
 	slangc.exe!wmain(int argc, wchar_t * * argv) Line 154	C++

In this callstack, we do makeFuncReturnViaOutParam(), so this ends up setting the type of tanh inst as void. Since this is void, inside void CLikeSourceEmitter::emitInstResultDecl(IRInst* inst)(), do an early return.

Steps to reproduce:

  1. Generate the target cuda code like so:
    ./build/Debug/bin/slangc.exe .\tests\cuda\optix-coopvec.slang -target cuda -o out.cu -Xnvrtc -I"C:/ProgramData/NVIDIA Corporation/OptiX SDK 9.0.0/include" -I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.8/include" -capability optix_coopvec

  2. Observe that the generated code is as described in the issue here.

@mkeshavaNV mkeshavaNV self-assigned this Jun 3, 2025
@bmillsNV bmillsNV added this to the Q3 2025 (Summer) milestone Jun 4, 2025
@mkeshavaNV
Copy link
Contributor Author

The coopvec intrinsics emitted won't really compile correctly without this issue fixed correctly. However this work is currently not prioritized. Will be taking this up at a later point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants