diff options
| author | Dietrich Geisler <dag368@cornell.edu> | 2020-07-31 17:51:52 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-31 14:51:52 -0700 |
| commit | 011a743668e7cd0b7cf97d27e3bed7d519794aeb (patch) | |
| tree | 49cf484df958aa705ff910631e8f732a6f0a57b9 /source | |
| parent | 4549597709e29b85b5f95503f4f2258c16db12be (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')
| -rwxr-xr-x | source/slang/slang-compiler.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-emit-cpp.cpp | 65 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 4 |
4 files changed, 78 insertions, 0 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 146cf9ed0..19f56031d 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1265,6 +1265,9 @@ namespace Slang bool m_obfuscateCode = false; + // Determine whether to output heterogeneity-related code + bool m_heterogeneous = false; + // Name pool for looking up names NamePool namePool; 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. diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index b115b8222..b931212fd 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -1416,6 +1416,12 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower resultType); } + IRType* visitPtrType(PtrType* type) + { + IRType* valueType = lowerType(context, type->getValueType()); + return getBuilder()->getPtrType(valueType); + } + IRType* visitDeclRefType(DeclRefType* type) { auto declRef = type->declRef; diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 6b4d5adf2..5da87bde6 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -664,6 +664,10 @@ struct OptionsParser rawEntryPoints.add(rawEntryPoint); } + else if (argStr == "-heterogeneous") + { + requestImpl->getLinkage()->m_heterogeneous = true; + } else if (argStr == "-lang") { String name; |
