summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-cpp.cpp
diff options
context:
space:
mode:
authorDietrich Geisler <dag368@cornell.edu>2020-07-31 17:51:52 -0400
committerGitHub <noreply@github.com>2020-07-31 14:51:52 -0700
commit011a743668e7cd0b7cf97d27e3bed7d519794aeb (patch)
tree49cf484df958aa705ff910631e8f732a6f0a57b9 /source/slang/slang-emit-cpp.cpp
parent4549597709e29b85b5f95503f4f2258c16db12be (diff)
Binary for Heterogeneous Example (#1467)
* Binary Heterogeneous Example This PR introduces the ability to insert the binary of a non-CPU target by using the -heterogeneous flag. Specifically, this PR updates the emitting logic to produce a variable of name `__[name_of_entryPoint]` when the heterogeneous flag is present. * Prelude path fix Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-emit-cpp.cpp')
-rw-r--r--source/slang/slang-emit-cpp.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index c949075fb..14033866b 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -2529,6 +2529,71 @@ void CPPSourceEmitter::_emitForwardDeclarations(const List<EmitAction>& actions)
void CPPSourceEmitter::emitModuleImpl(IRModule* module)
{
+ // If we are emitting a heterogeneous program
+ // Emit the binary blob of each non-CPP target
+ ComponentType* program = m_compileRequest->getProgram();
+ auto linkage = m_compileRequest->getLinkage();
+ if (linkage->m_heterogeneous)
+ {
+ for (auto inst : module->getGlobalInsts())
+ {
+ auto func = as<IRFunc>(inst);
+ if (!func)
+ continue;
+ if (auto entryPointDecoration = func->findDecoration<IREntryPointDecoration>())
+ {
+ String someName = entryPointDecoration->getName()->getStringSlice();
+ for (int index = 0; index < program->getEntryPointCount(); index++)
+ {
+ auto entryPoint = program->getEntryPoint(index);
+ if (someName == entryPoint->getName()->text)
+ {
+ for (auto targetRequest : linkage->targets)
+ {
+ // Emit for all non-CPU targets
+ switch (targetRequest->getTarget())
+ {
+ case(CodeGenTarget::CPPSource):
+ case(CodeGenTarget::CSource):
+ case(CodeGenTarget::HostCallable):
+ case(CodeGenTarget::CUDASource):
+
+ break;
+
+ default:
+
+ auto targetProgram = program->getTargetProgram(targetRequest);
+ DiagnosticSink sink(linkage->getSourceManager());
+ CompileResult result =
+ targetProgram->getOrCreateEntryPointResult(index, &sink);
+
+ Slang::ComPtr<ISlangBlob> blob;
+ result.getBlob(blob);
+ auto ptr = (const unsigned char*)blob->getBufferPointer();
+
+ m_writer->emit("size_t __");
+ m_writer->emit(someName);
+ m_writer->emit("Size = ");
+ m_writer->emitInt64(blob->getBufferSize());
+ m_writer->emit(";\n");
+
+ m_writer->emit("unsigned char __");
+ m_writer->emit(someName);
+ m_writer->emit("[] = {");
+ for (unsigned int i = 0; i < blob->getBufferSize() - 1; i++) {
+ m_writer->emitUInt64(ptr[i]);
+ m_writer->emit(", ");
+ }
+ m_writer->emitUInt64(ptr[blob->getBufferSize() - 1]);
+ m_writer->emit("};\n");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
// Setup all built in types used in the module
m_typeSet.addAllBuiltinTypes(module);
// If any matrix types are used, then we need appropriate vector types too.