summaryrefslogtreecommitdiff
path: root/tools/slang-test
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-12-12 11:39:19 -0500
committerGitHub <noreply@github.com>2019-12-12 11:39:19 -0500
commit6e6a876a6b5ad3d2ef402757d2e20641f5a2b49b (patch)
tree29eab69c4982537376d7eaf422d9090c849e95f7 /tools/slang-test
parent79ec0cfdb5f3461c763e0bf712cf42eb87fccb90 (diff)
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.
Diffstat (limited to 'tools/slang-test')
-rw-r--r--tools/slang-test/slang-test-main.cpp33
-rw-r--r--tools/slang-test/test-context.cpp32
-rw-r--r--tools/slang-test/test-context.h7
3 files changed, 41 insertions, 31 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 51c3ecea9..44cc73b4e 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -21,6 +21,8 @@ using namespace Slang;
#include "../../source/core/slang-downstream-compiler.h"
+#include "../../source/core/slang-nvrtc-compiler.h"
+
#include "../../source/core/slang-process-util.h"
#define STB_IMAGE_IMPLEMENTATION
@@ -523,6 +525,10 @@ static SlangPassThrough _toPassThroughType(const UnownedStringSlice& slice)
{
return SLANG_PASS_THROUGH_VISUAL_STUDIO;
}
+ else if (slice == "nvrtc")
+ {
+ return SLANG_PASS_THROUGH_NVRTC;
+ }
return SLANG_PASS_THROUGH_NONE;
}
@@ -562,6 +568,10 @@ static PassThroughFlags _getPassThroughFlagsForTarget(SlangCompileTarget target)
{
return PassThroughFlag::Generic_C_CPP;
}
+ case SLANG_PTX:
+ {
+ return PassThroughFlag::NVRTC;
+ }
default:
{
@@ -593,6 +603,8 @@ static SlangCompileTarget _getCompileTarget(const UnownedStringSlice& name)
CASE("dll", SHARED_LIBRARY)
CASE("callable", HOST_CALLABLE)
CASE("host-callable", HOST_CALLABLE)
+ CASE("ptx", PTX)
+ CASE("cuda", CUDA_SOURCE)
#undef CASE
return SLANG_TARGET_UNKNOWN;
@@ -1088,7 +1100,6 @@ TestResult runSimpleTest(TestContext* context, TestInput& input)
TestResult runCompile(TestContext* context, TestInput& input)
{
- // need to execute the stand-alone Slang compiler on the file, and compare its output to what we expect
auto outputStem = input.outputStem;
CommandLine cmdLine;
@@ -1280,9 +1291,9 @@ static String _calcModulePath(const TestInput& input)
return Path::combine(directory, moduleName);
}
-static TestResult runCompilerCompile(TestContext* context, TestInput& input)
+static TestResult runCPPCompilerCompile(TestContext* context, TestInput& input)
{
- DownstreamCompiler* compiler = context->getDefaultCompiler();
+ DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
if (!compiler)
{
return TestResult::Ignored;
@@ -1322,9 +1333,9 @@ static TestResult runCompilerCompile(TestContext* context, TestInput& input)
return TestResult::Pass;
}
-static TestResult runCompilerSharedLibrary(TestContext* context, TestInput& input)
+static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& input)
{
- DownstreamCompiler* compiler = context->getDefaultCompiler();
+ DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
if (!compiler)
{
return TestResult::Ignored;
@@ -1440,9 +1451,9 @@ static TestResult runCompilerSharedLibrary(TestContext* context, TestInput& inpu
return TestResult::Pass;
}
-static TestResult runCompilerExecute(TestContext* context, TestInput& input)
+static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
{
- DownstreamCompiler* compiler = context->getDefaultCompiler();
+ DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
if (!compiler)
{
return TestResult::Ignored;
@@ -2442,9 +2453,9 @@ static const TestCommandInfo s_testCommandInfos[] =
{ "COMPARE_RENDER_COMPUTE", &runSlangRenderComputeComparisonTest},
{ "COMPARE_GLSL", &runGLSLComparisonTest},
{ "CROSS_COMPILE", &runCrossCompilerTest},
- { "CPP_COMPILER_EXECUTE", &runCompilerExecute},
- { "CPP_COMPILER_SHARED_LIBRARY", &runCompilerSharedLibrary},
- { "CPP_COMPILER_COMPILE", &runCompilerCompile},
+ { "CPP_COMPILER_EXECUTE", &runCPPCompilerExecute},
+ { "CPP_COMPILER_SHARED_LIBRARY", &runCPPCompilerSharedLibrary},
+ { "CPP_COMPILER_COMPILE", &runCPPCompilerCompile},
{ "PERFORMANCE_PROFILE", &runPerformanceProfile},
{ "COMPILE", &runCompile},
};
@@ -2777,6 +2788,7 @@ static bool endsWithAllowedExtension(
".rgen",
".c",
".cpp",
+ ".cu",
};
for( auto allowedExtension : allowedExtensions)
@@ -2871,6 +2883,7 @@ SlangResult innerMain(int argc, char** argv)
auto unixCatagory = categorySet.add("unix", fullTestCategory);
#endif
+
// An un-categorized test will always belong to the `full` category
categorySet.defaultCategory = fullTestCategory;
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 <stdio.h>
#include <stdlib.h>
@@ -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<ISlangSharedLibrary> 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;
}
diff --git a/tools/slang-test/test-context.h b/tools/slang-test/test-context.h
index aa81fc72a..520e0bf1d 100644
--- a/tools/slang-test/test-context.h
+++ b/tools/slang-test/test-context.h
@@ -11,6 +11,8 @@
#include "../../source/core/slang-render-api-util.h"
#include "../../source/core/slang-downstream-compiler.h"
+#include "../../slang-com-ptr.h"
+
#include "options.h"
typedef uint32_t PassThroughFlags;
@@ -25,6 +27,7 @@ struct PassThroughFlag
GCC = 1 << int(SLANG_PASS_THROUGH_GCC),
Clang = 1 << int(SLANG_PASS_THROUGH_CLANG),
Generic_C_CPP = 1 << int(SLANG_PASS_THROUGH_GENERIC_C_CPP),
+ NVRTC = 1 << int(SLANG_PASS_THROUGH_NVRTC)
};
};
@@ -94,7 +97,7 @@ class TestContext
/// Get compiler set
Slang::DownstreamCompilerSet* getCompilerSet();
- Slang::DownstreamCompiler* getDefaultCompiler();
+ Slang::DownstreamCompiler* getDefaultCompiler(Slang::DownstreamCompiler::SourceType sourceType);
/// Ctor
TestContext();
@@ -117,7 +120,7 @@ class TestContext
protected:
struct SharedLibraryTool
{
- Slang::SharedLibrary::Handle m_sharedLibrary;
+ Slang::ComPtr<ISlangSharedLibrary> m_sharedLibrary;
InnerMainFunc m_func;
};