Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cuda+OptiX dependency reporting to testshade and stats #1259

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/include/OSL/oslexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,44 @@ class OSLEXECPUBLIC ShadingSystem
return attribute (group, name, TypeDesc::STRING, &s);
}

/// Get the named attribute, store it in value.
/// Get the named attribute of the ShadingSystem, store it in `*val`.
/// Return `true` if found and it was compatible with the type
/// specified, otherwise return `false` and do not modify the contents
/// of `*val`. It is up to the caller to ensure that `val` points to
/// the right kind and size of storage for the given type.
///
/// In addition to being able to retrieve all the attributes that are
/// documented as settable by the `attribute()` call, `getattribute()`
/// can also retrieve the following read-only attributes:
///
/// - `string osl:simd`, `string hw:simd` : A comma-separated list of
/// CPU hardware SIMD features. The `osl:simd` is a list of features
/// enabled when OSL was built, and `hw:simd` is a list of features
/// detected on the actual hardware at runtime.
///
/// - `string osl:cuda_version` : The version string of the Cuda version
/// OSL is using (empty string if no Cuda support was enabled at build
/// time).
///
/// - `string osl:optix_version` : The version string of the OptiX
/// version OSL is using (empty string if no OptiX support was enabled
/// at build time).
///
/// - `string osl:dependencies` : A comma-separated list of OSL's major
/// library build dependencies and their versions (for example,
/// "OIIO-2.3.0,LLVM-10.0.0,OpenEXR-2.5.0").
///
bool getattribute (string_view name, TypeDesc type, void *val);

// Shortcuts for common types
/// Shortcut getattribute() for retrieving a single integer.
/// The value is placed in `val`, and the function returns `true` if the
/// attribute was found and was legally convertible to an int.
bool getattribute (string_view name, int &val) {
return getattribute (name, TypeDesc::INT, &val);
}
/// Shortcut getattribute() for retrieving a single float.
/// The value is placed in `val`, and the function returns `true` if the
/// attribute was found and was legally convertible to a float.
bool getattribute (string_view name, float &val) {
return getattribute (name, TypeDesc::FLOAT, &val);
}
Expand All @@ -256,12 +286,21 @@ class OSLEXECPUBLIC ShadingSystem
val = f;
return ok;
}
/// Shortcut getattribute() for retrieving a single string as a
/// `const char*`. The value is placed in `val`, and the function
/// returns `true` if the attribute was found.
bool getattribute (string_view name, char **val) {
return getattribute (name, TypeDesc::STRING, val);
}
/// Shortcut getattribute() for retrieving a single string as a
/// `ustring`. The value is placed in `val`, and the function returns
/// `true` if the attribute was found.
bool getattribute (string_view name, ustring &val) {
return getattribute (name, TypeDesc::STRING, (char **)&val);
}
/// Shortcut getattribute() for retrieving a single string as a
/// `std::string`. The value is placed in `val`, and the function
/// returns `true` if the attribute was found.
bool getattribute (string_view name, std::string &val) {
const char *s = NULL;
bool ok = getattribute (name, TypeDesc::STRING, &s);
Expand Down
7 changes: 6 additions & 1 deletion src/liboslexec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ target_include_directories (${local_lib}
PRIVATE
"${CMAKE_SOURCE_DIR}/src/liboslcomp"
)
target_compile_definitions (${local_lib} PRIVATE OSL_EXPORTS)
target_compile_definitions (${local_lib}
PRIVATE
OSL_EXPORTS
OSL_CUDA_VERSION="${CUDA_VERSION}"
OSL_OPTIX_VERSION="${OPTIX_VERSION}"
)
if (partio_FOUND)
target_link_libraries(${local_lib} PRIVATE partio::partio)
target_compile_definitions (${local_lib} PRIVATE USE_PARTIO=1)
Expand Down
122 changes: 76 additions & 46 deletions src/liboslexec/shadingsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,38 @@ ShadingSystemImpl::~ShadingSystemImpl ()



// Return a comma-separated list of all the important SIMD/capabilities
// that were enabled as a compile-time option when OSL was built.
// (Keep this in sync with oiio_simd_caps in imageio.cpp).
static std::string
osl_simd_caps()
{
// clang-format off
std::vector<string_view> caps;
if (OIIO_SIMD_SSE >= 2) caps.emplace_back ("sse2");
if (OIIO_SIMD_SSE >= 3) caps.emplace_back ("sse3");
if (OIIO_SIMD_SSE >= 3) caps.emplace_back ("ssse3");
if (OIIO_SIMD_SSE >= 4) caps.emplace_back ("sse41");
if (OIIO_SIMD_SSE >= 4) caps.emplace_back ("sse42");
if (OIIO_SIMD_AVX) caps.emplace_back ("avx");
if (OIIO_SIMD_AVX >= 2) caps.emplace_back ("avx2");
if (OIIO_SIMD_AVX >= 512) caps.emplace_back ("avx512f");
if (OIIO_AVX512DQ_ENABLED) caps.emplace_back ("avx512dq");
if (OIIO_AVX512IFMA_ENABLED) caps.emplace_back ("avx512ifma");
if (OIIO_AVX512PF_ENABLED) caps.emplace_back ("avx512pf");
if (OIIO_AVX512ER_ENABLED) caps.emplace_back ("avx512er");
if (OIIO_AVX512CD_ENABLED) caps.emplace_back ("avx512cd");
if (OIIO_AVX512BW_ENABLED) caps.emplace_back ("avx512bw");
if (OIIO_AVX512VL_ENABLED) caps.emplace_back ("avx512vl");
if (OIIO_FMA_ENABLED) caps.emplace_back ("fma");
if (OIIO_F16C_ENABLED) caps.emplace_back ("f16c");
// if (OIIO_POPCOUNT_ENABLED) caps.emplace_back ("popcnt");
return OIIO::Strutil::join (caps, ",");
// clang-format on
}



bool
ShadingSystemImpl::attribute (string_view name, TypeDesc type,
const void *val)
Expand Down Expand Up @@ -1436,6 +1468,36 @@ ShadingSystemImpl::getattribute (string_view name, TypeDesc type,
(char*)&colorsystem().colorspace());
return true;
}
if (name == "osl:simd" && type == TypeDesc::STRING) {
*(const char**)val = ustring(osl_simd_caps()).c_str();
return true;
}
if (name == "hw:simd" && type == TypeDesc::STRING) {
return OIIO::getattribute("hw:string", type, val);
}
if (name == "osl:cuda_version" && type == TypeDesc::STRING) {
*(const char**)val = OSL_CUDA_VERSION;
return true;
}
if (name == "osl:optix_version" && type == TypeDesc::STRING) {
*(const char**)val = OSL_OPTIX_VERSION;
return true;
}
if (name == "osl:dependencies" && type == TypeDesc::STRING) {
std::string deps = OIIO::Strutil::sprintf("LLVM-%s,OpenImageIO-%s,Imath-%s",
OSL_LLVM_FULL_VERSION, OIIO_VERSION_STRING,
OPENEXR_VERSION_STRING);
if (!strcmp(OSL_CUDA_VERSION, ""))
deps += ",Cuda-NONE";
else
deps += ",Cuda-" OSL_CUDA_VERSION;
if (!strcmp(OSL_OPTIX_VERSION, ""))
deps += ",OptiX-NONE";
else
deps += ",OptiX-" OSL_OPTIX_VERSION;
*(const char**)val = ustring(deps).c_str();
return true;
}

return false;
#undef ATTR_DECODE
Expand Down Expand Up @@ -1775,38 +1837,6 @@ struct group_time_compare { // So looking forward to C++11 lambdas!



// Return a comma-separated list of all the important SIMD/capabilities
// that were enabled as a compile-time option when OSL was built.
// (Keep this in sync with oiio_simd_caps in imageio.cpp).
static std::string
osl_simd_caps()
{
// clang-format off
std::vector<string_view> caps;
if (OIIO_SIMD_SSE >= 2) caps.emplace_back ("sse2");
if (OIIO_SIMD_SSE >= 3) caps.emplace_back ("sse3");
if (OIIO_SIMD_SSE >= 3) caps.emplace_back ("ssse3");
if (OIIO_SIMD_SSE >= 4) caps.emplace_back ("sse41");
if (OIIO_SIMD_SSE >= 4) caps.emplace_back ("sse42");
if (OIIO_SIMD_AVX) caps.emplace_back ("avx");
if (OIIO_SIMD_AVX >= 2) caps.emplace_back ("avx2");
if (OIIO_SIMD_AVX >= 512) caps.emplace_back ("avx512f");
if (OIIO_AVX512DQ_ENABLED) caps.emplace_back ("avx512dq");
if (OIIO_AVX512IFMA_ENABLED) caps.emplace_back ("avx512ifma");
if (OIIO_AVX512PF_ENABLED) caps.emplace_back ("avx512pf");
if (OIIO_AVX512ER_ENABLED) caps.emplace_back ("avx512er");
if (OIIO_AVX512CD_ENABLED) caps.emplace_back ("avx512cd");
if (OIIO_AVX512BW_ENABLED) caps.emplace_back ("avx512bw");
if (OIIO_AVX512VL_ENABLED) caps.emplace_back ("avx512vl");
if (OIIO_FMA_ENABLED) caps.emplace_back ("fma");
if (OIIO_F16C_ENABLED) caps.emplace_back ("f16c");
// if (OIIO_POPCOUNT_ENABLED) caps.emplace_back ("popcnt");
return OIIO::Strutil::join (caps, ",");
// clang-format on
}



std::string
ShadingSystemImpl::getstats (int level) const
{
Expand All @@ -1817,14 +1847,11 @@ ShadingSystemImpl::getstats (int level) const
std::ostringstream out;
out.imbue (std::locale::classic()); // force C locale
out << "Open Shading Language " << OSL_LIBRARY_VERSION_STRING << "\n";
out << " Build deps: LLVM-" << OSL_LLVM_FULL_VERSION
<< " OIIO-" << OIIO_VERSION_STRING << " Imath-" <<
#ifdef OPENEXR_VERSION_STRING
OPENEXR_VERSION_STRING
#else
"(unknown)"
#endif
<< "\n";
ustring build_deps;
const_cast<ShadingSystemImpl*>(this)->getattribute("osl:dependencies", TypeDesc::STRING, &build_deps);
out << " Build deps: " << Strutil::wordwrap(
Strutil::join(Strutil::splitsv(build_deps,","), ", "), columns, 14)
<< "\n";

std::string opt;
#define BOOLOPT(name) opt += Strutil::sprintf(#name "=%d ", m_##name)
Expand Down Expand Up @@ -1892,15 +1919,18 @@ ShadingSystemImpl::getstats (int level) const
#undef STROPT

// Print the HW info
out << " Build HW support: ";
std::string buildsimd = osl_simd_caps();
if (!buildsimd.size())
ustring buildsimd;
if (!const_cast<ShadingSystemImpl*>(this)->getattribute("osl:simd", TypeDesc::STRING, &buildsimd))
buildsimd = "no SIMD";
out << buildsimd << "\n";
OIIO::Strutil::fprintf(out, " Runtime HW: %d cores %.1fGB %s\n",
out << " Build HW support: " << Strutil::wordwrap(
Strutil::join(Strutil::splitsv(buildsimd,","), ", "), columns, 20)
<< "\n";
out << Strutil::wordwrap(
OIIO::Strutil::sprintf(" Runtime HW: %d cores, %.1fGB, %s",
OIIO::Sysutil::hardware_concurrency(),
OIIO::Sysutil::physical_memory() / float(1 << 30),
OIIO::get_string_attribute("hw:simd"));
Strutil::replace(OIIO::get_string_attribute("hw:simd"), ",", ", ", true)),
columns, 8) << "\n";
// TODO: detect GPU info and print it here
out << "\n";

Expand Down