Skip to content

Commit 1d744e5

Browse files
committed
Print more build/runtime info in stats and help message (#1258)
testshade --help or --runstats now print additional info about the dependency versions, hardware capabilities enabled at build time, and hardware capabilities detected at runtime. This should help debugging of user experiences as an easy way to find out what OSL thinks it's working with in terms of its environment. Signed-off-by: Larry Gritz <[email protected]>
1 parent a7bfaf0 commit 1d744e5

File tree

2 files changed

+95
-11
lines changed

2 files changed

+95
-11
lines changed

src/liboslexec/shadingsys.cpp

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
#include "backendllvm.h"
1515
#include <OSL/oslquery.h>
1616

17+
#include <OpenImageIO/filesystem.h>
18+
#include <OpenImageIO/fmath.h>
19+
#include <OpenImageIO/optparser.h>
1720
#include <OpenImageIO/strutil.h>
21+
#include <OpenImageIO/sysutil.h>
1822
#include <OpenImageIO/thread.h>
1923
#include <OpenImageIO/timer.h>
20-
#include <OpenImageIO/filesystem.h>
21-
#include <OpenImageIO/optparser.h>
22-
#include <OpenImageIO/fmath.h>
2324

2425
#include "opcolor.h"
2526

2627
using namespace OSL;
2728
using namespace OSL::pvt;
2829

30+
#include <OpenEXR/ImfChannelList.h> // Just for OPENEXR_VERSION_STRING
31+
2932
// avoid naming conflicts with MSVC macros
3033
#ifdef _MSC_VER
3134
#undef RGB
@@ -1772,20 +1775,56 @@ struct group_time_compare { // So looking forward to C++11 lambdas!
17721775

17731776

17741777

1778+
// Return a comma-separated list of all the important SIMD/capabilities
1779+
// that were enabled as a compile-time option when OSL was built.
1780+
// (Keep this in sync with oiio_simd_caps in imageio.cpp).
1781+
static std::string
1782+
osl_simd_caps()
1783+
{
1784+
// clang-format off
1785+
std::vector<string_view> caps;
1786+
if (OIIO_SIMD_SSE >= 2) caps.emplace_back ("sse2");
1787+
if (OIIO_SIMD_SSE >= 3) caps.emplace_back ("sse3");
1788+
if (OIIO_SIMD_SSE >= 3) caps.emplace_back ("ssse3");
1789+
if (OIIO_SIMD_SSE >= 4) caps.emplace_back ("sse41");
1790+
if (OIIO_SIMD_SSE >= 4) caps.emplace_back ("sse42");
1791+
if (OIIO_SIMD_AVX) caps.emplace_back ("avx");
1792+
if (OIIO_SIMD_AVX >= 2) caps.emplace_back ("avx2");
1793+
if (OIIO_SIMD_AVX >= 512) caps.emplace_back ("avx512f");
1794+
if (OIIO_AVX512DQ_ENABLED) caps.emplace_back ("avx512dq");
1795+
if (OIIO_AVX512IFMA_ENABLED) caps.emplace_back ("avx512ifma");
1796+
if (OIIO_AVX512PF_ENABLED) caps.emplace_back ("avx512pf");
1797+
if (OIIO_AVX512ER_ENABLED) caps.emplace_back ("avx512er");
1798+
if (OIIO_AVX512CD_ENABLED) caps.emplace_back ("avx512cd");
1799+
if (OIIO_AVX512BW_ENABLED) caps.emplace_back ("avx512bw");
1800+
if (OIIO_AVX512VL_ENABLED) caps.emplace_back ("avx512vl");
1801+
if (OIIO_FMA_ENABLED) caps.emplace_back ("fma");
1802+
if (OIIO_F16C_ENABLED) caps.emplace_back ("f16c");
1803+
// if (OIIO_POPCOUNT_ENABLED) caps.emplace_back ("popcnt");
1804+
return OIIO::Strutil::join (caps, ",");
1805+
// clang-format on
1806+
}
1807+
1808+
1809+
17751810
std::string
17761811
ShadingSystemImpl::getstats (int level) const
17771812
{
1813+
int columns = OIIO::Sysutil::terminal_columns() - 2;
1814+
17781815
if (level <= 0)
17791816
return "";
17801817
std::ostringstream out;
17811818
out.imbue (std::locale::classic()); // force C locale
1782-
out << "OSL ShadingSystem statistics (" << (void*)this;
1783-
out << ") ver " << OSL_LIBRARY_VERSION_STRING
1784-
<< ", LLVM " << OSL_LLVM_FULL_VERSION << "\n";
1785-
if (m_stat_shaders_requested == 0 && m_stat_shaders_loaded == 0) {
1786-
out << " No shaders requested or loaded\n";
1787-
return out.str();
1788-
}
1819+
out << "Open Shading Language " << OSL_LIBRARY_VERSION_STRING << "\n";
1820+
out << " Build deps: LLVM-" << OSL_LLVM_FULL_VERSION
1821+
<< " OIIO-" << OIIO_VERSION_STRING << " Imath-" <<
1822+
#ifdef OPENEXR_VERSION_STRING
1823+
OPENEXR_VERSION_STRING
1824+
#else
1825+
"(unknown)"
1826+
#endif
1827+
<< "\n";
17891828

17901829
std::string opt;
17911830
#define BOOLOPT(name) opt += Strutil::sprintf(#name "=%d ", m_##name)
@@ -1851,7 +1890,28 @@ ShadingSystemImpl::getstats (int level) const
18511890
#undef BOOLOPT
18521891
#undef INTOPT
18531892
#undef STROPT
1854-
out << " Options: " << Strutil::wordwrap(opt, 75, 12) << "\n";
1893+
1894+
// Print the HW info
1895+
out << " Build HW support: ";
1896+
std::string buildsimd = osl_simd_caps();
1897+
if (!buildsimd.size())
1898+
buildsimd = "no SIMD";
1899+
out << buildsimd << "\n";
1900+
OIIO::Strutil::fprintf(out, " Runtime HW: %d cores %.1fGB %s\n",
1901+
OIIO::Sysutil::hardware_concurrency(),
1902+
OIIO::Sysutil::physical_memory() / float(1 << 30),
1903+
OIIO::get_string_attribute("hw:simd"));
1904+
// TODO: detect GPU info and print it here
1905+
out << "\n";
1906+
1907+
out << "ShadingSystem Options:\n";
1908+
out << " " << Strutil::wordwrap(opt, columns, 4) << "\n";
1909+
1910+
out << "\nOSL ShadingSystem statistics (" << (void*)this << ")\n";
1911+
if (m_stat_shaders_requested == 0 && m_stat_shaders_loaded == 0) {
1912+
out << " No shaders requested or loaded\n";
1913+
return out.str();
1914+
}
18551915

18561916
out << " Shaders:\n";
18571917
out << " Requested: " << m_stat_shaders_requested << "\n";

src/testshade/testshade.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,29 @@ stash_shader_arg (int argc, const char* argv[])
431431

432432

433433

434+
void
435+
print_info()
436+
{
437+
ErrorHandler errhandler;
438+
SimpleRenderer* rend = nullptr;
439+
#ifdef OSL_USE_OPTIX
440+
if (use_optix)
441+
rend = new OptixGridRenderer;
442+
else
443+
#endif
444+
rend = new SimpleRenderer;
445+
TextureSystem *texturesys = TextureSystem::create();
446+
shadingsys = new ShadingSystem(rend, texturesys, &errhandler);
447+
rend->init_shadingsys(shadingsys);
448+
449+
std::cout << "\n" << shadingsys->getstats (5) << "\n";
450+
451+
delete shadingsys;
452+
delete rend;
453+
}
454+
455+
456+
434457
static void
435458
getargs (int argc, const char *argv[])
436459
{
@@ -520,6 +543,7 @@ getargs (int argc, const char *argv[])
520543
std::cout << "testshade -- Test Open Shading Language\n"
521544
OSL_COPYRIGHT_STRING "\n";
522545
ap.usage ();
546+
print_info();
523547
exit (EXIT_SUCCESS);
524548
}
525549
}

0 commit comments

Comments
 (0)