From 6e6a876a6b5ad3d2ef402757d2e20641f5a2b49b Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 12 Dec 2019 11:39:19 -0500 Subject: Slang compiles CUDA source via NVRTC (#1151) * CPPCompiler -> DownstreamCompiler * Added DownstreamCompileResult to start abstraction such that we don't need files. * * Split out slang-blob.cpp * Made CompileResult hold a DownstreamCompileResult - for access to binary or ISlangSharedLibrary * Keep temporary files in scope. * Add a hash to the hex dump stream. * Move all file tracking into DownstreamCompiler. * WIP support for nvrtc. * WIP: Adding support for nvrtc compiler. Adding enum types, wiring up the nvrtc into slang. * Fix remaining CPPCompiler references. * Fix order issue on target string matching. * Use ISlangSharedLibrary for nvrtc. * Use DownstreamCompiler for nvrtc. * WIP first pass at compilation win nvrtc. * Added testing if file is on file system into CommandLineDownstreamCompiler. Added sourceContentsPath. * Make test cuda-compile.cu work by just compiling not comparing output. * Fix warning on clang. --- tools/slang-test/test-context.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'tools/slang-test/test-context.cpp') diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp index c37261b61..d333dbcaa 100644 --- a/tools/slang-test/test-context.cpp +++ b/tools/slang-test/test-context.cpp @@ -3,6 +3,7 @@ #include "../../source/core/slang-io.h" #include "../../source/core/slang-string-util.h" +#include "../../source/core/slang-shared-library.h" #include #include @@ -27,15 +28,6 @@ Result TestContext::init() TestContext::~TestContext() { - for (auto& pair : m_sharedLibTools) - { - const auto& tool = pair.Value; - if (tool.m_sharedLibrary) - { - SharedLibrary::unload(tool.m_sharedLibrary); - } - } - if (m_session) { spDestroySession(m_session); @@ -60,11 +52,13 @@ TestContext::InnerMainFunc TestContext::getInnerMainFunc(const String& dirPath, SharedLibrary::appendPlatformFileName(sharedLibToolBuilder.getUnownedSlice(), builder); String path = Path::combine(dirPath, builder); + DefaultSharedLibraryLoader* loader = DefaultSharedLibraryLoader::getSingleton(); + SharedLibraryTool tool = {}; - if (SLANG_SUCCEEDED(SharedLibrary::loadWithPlatformPath(path.begin(), tool.m_sharedLibrary))) + if (SLANG_SUCCEEDED(loader->loadPlatformSharedLibrary(path.begin(), tool.m_sharedLibrary.writeRef()))) { - tool.m_func = (InnerMainFunc)SharedLibrary::findFuncByName(tool.m_sharedLibrary, "innerMain"); + tool.m_func = (InnerMainFunc)tool.m_sharedLibrary->findFuncByName("innerMain"); } m_sharedLibTools.Add(name, tool); @@ -76,12 +70,7 @@ void TestContext::setInnerMainFunc(const String& name, InnerMainFunc func) SharedLibraryTool* tool = m_sharedLibTools.TryGetValue(name); if (tool) { - if (tool->m_sharedLibrary) - { - SharedLibrary::unload(tool->m_sharedLibrary); - tool->m_sharedLibrary = nullptr; - } - + tool->m_sharedLibrary.setNull(); tool->m_func = func; } else @@ -99,14 +88,19 @@ DownstreamCompilerSet* TestContext::getCompilerSet() compilerSet = new DownstreamCompilerSet; DownstreamCompilerUtil::InitializeSetDesc desc; + + ComPtr nvrtcSharedLibrary; + DefaultSharedLibraryLoader::getSingleton()->loadSharedLibrary(DefaultSharedLibraryLoader::getSharedLibraryNameFromType(SharedLibraryType::NVRTC), nvrtcSharedLibrary.writeRef()); + desc.sharedLibraries[int(DownstreamCompiler::CompilerType::NVRTC)] = nvrtcSharedLibrary; + DownstreamCompilerUtil::initializeSet(desc, compilerSet); } return compilerSet; } -Slang::DownstreamCompiler* TestContext::getDefaultCompiler() +Slang::DownstreamCompiler* TestContext::getDefaultCompiler(DownstreamCompiler::SourceType sourceType) { DownstreamCompilerSet* set = getCompilerSet(); - return set ? set->getDefaultCompiler() : nullptr; + return set ? set->getDefaultCompiler(sourceType) : nullptr; } -- cgit v1.2.3