From f85a7d0d2b0e99f487a75451c2b5c9d3474bdc2b Mon Sep 17 00:00:00 2001 From: Mark Reid Date: Sat, 23 Mar 2024 21:49:40 -0700 Subject: [PATCH 1/3] CPUInfo cleanup Remove unneeded duplicate code h Handle unknown processors Signed-off-by: Mark Reid --- src/OpenColorIO/CPUInfo.cpp | 26 ++++++++++++++++------ src/OpenColorIO/CPUInfo.h | 43 ------------------------------------- 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/src/OpenColorIO/CPUInfo.cpp b/src/OpenColorIO/CPUInfo.cpp index c0d7c02899..dce813a4ff 100644 --- a/src/OpenColorIO/CPUInfo.cpp +++ b/src/OpenColorIO/CPUInfo.cpp @@ -183,18 +183,20 @@ CPUInfo::CPUInfo() } } -CPUInfo& CPUInfo::instance() -{ - static CPUInfo singleton = CPUInfo(); - return singleton; -} #elif defined(__aarch64__) // ARM Processor or Apple ARM. + CPUInfo::CPUInfo() { flags = 0; memset(name, 0, sizeof(name)); + memset(vendor, 0, sizeof(vendor)); snprintf(name, sizeof(name), "%s", "ARM"); +#if __APPLE__ + snprintf(vendor, sizeof(vendor), "%s", "Apple"); +# else + snprintf(vendor, sizeof(vendor), "%s", "ARM"); +#endif // SSE2NEON library supports SSE, SSE2, SSE3, SSSE3, SSE4.1 and SSE4.2. // It does not support any AVX instructions. @@ -208,11 +210,23 @@ CPUInfo::CPUInfo() } } +#else + +CPUInfo::CPUInfo() // Unknown Processor +{ + flags = 0; + memset(name, 0, sizeof(name)); + memset(vendor, 0, sizeof(vendor)); + snprintf(name, sizeof(name), "%s", "Unknown"); + snprintf(vendor, sizeof(vendor), "%s", "Unknown"); +} + +#endif + CPUInfo& CPUInfo::instance() { static CPUInfo singleton = CPUInfo(); return singleton; } -#endif } // namespace OCIO_NAMESPACE \ No newline at end of file diff --git a/src/OpenColorIO/CPUInfo.h b/src/OpenColorIO/CPUInfo.h index 288360d7fd..80e9792e01 100644 --- a/src/OpenColorIO/CPUInfo.h +++ b/src/OpenColorIO/CPUInfo.h @@ -36,8 +36,6 @@ namespace OCIO_NAMESPACE #define x86_check_flags(cpuext) \ (OCIO_USE_ ## cpuext && ((flags) & X86_CPU_FLAG_ ## cpuext)) -#if !defined(__aarch64__) && OCIO_ARCH_X86 // Intel-based processor or Apple Rosetta x86_64. - struct CPUInfo { unsigned int flags; @@ -79,47 +77,6 @@ struct CPUInfo #undef x86_check_flags -#elif defined(__aarch64__) // ARM Processor or Apple ARM. - -#define check_flags(cpuext) \ - (OCIO_USE_ ## cpuext && ((flags) & X86_CPU_FLAG_ ## cpuext)) - -struct CPUInfo -{ - unsigned int flags; - char name[65]; - - CPUInfo(); - - static CPUInfo& instance(); - - bool hasSSE2() const { return x86_check_flags(SSE2); } - bool SSE2Slow() const { return false; } - - bool hasSSE3() const { return x86_check_flags(SSE3); } - bool SSE3Slow() const { return false; } - - bool hasSSSE3() const { return x86_check_flags(SSSE3); } - bool SSSE3Slow() const { return false; } - - bool hasSSE4() const { return x86_check_flags(SSE4); } - bool hasSSE42() const { return false; } - - // Apple M1 does not support AVX SIMD instructions through Rosetta. - // SSE2NEON library does not supports AVX SIMD instructions. - bool hasAVX() const { return false; } - bool AVXSlow() const { return false; } - bool hasAVX2() const { return false; } - bool AVX2SlowGather() const { return false; } - bool hasAVX512() const { return false; } - bool hasF16C() const { return false; } - -}; - -#undef x86_check_flags - -#endif - } // namespace OCIO_NAMESPACE #endif // CPUInfo_H From e4efad7861fb7dcd4ce6c401d29181e922497864 Mon Sep 17 00:00:00 2001 From: Mark Reid Date: Sat, 23 Mar 2024 21:50:57 -0700 Subject: [PATCH 2/3] Add ociocpuinfo utility Signed-off-by: Mark Reid --- src/apps/CMakeLists.txt | 1 + src/apps/ociocpuinfo/CMakeLists.txt | 27 ++++++++++++++++++++++++ src/apps/ociocpuinfo/main.cpp | 32 +++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/apps/ociocpuinfo/CMakeLists.txt create mode 100644 src/apps/ociocpuinfo/main.cpp diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index bbedc3c219..decb56d50a 100755 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -6,6 +6,7 @@ if(OCIO_BUILD_APPS) add_subdirectory(ociobakelut) add_subdirectory(ociocheck) add_subdirectory(ociochecklut) + add_subdirectory(ociocpuinfo) add_subdirectory(ociomakeclf) add_subdirectory(ocioperf) add_subdirectory(ociowrite) diff --git a/src/apps/ociocpuinfo/CMakeLists.txt b/src/apps/ociocpuinfo/CMakeLists.txt new file mode 100644 index 0000000000..33115d653e --- /dev/null +++ b/src/apps/ociocpuinfo/CMakeLists.txt @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +set(SOURCES + main.cpp + ${PROJECT_SOURCE_DIR}/src/OpenColorIO/CPUInfo.cpp +) + +add_executable(ociocpuinfo ${SOURCES}) + +set_target_properties(ociocpuinfo PROPERTIES + COMPILE_OPTIONS "${PLATFORM_COMPILE_OPTIONS}" + LINK_OPTIONS "${PLATFORM_LINK_OPTIONS}" +) + +target_include_directories(ociocpuinfo + PRIVATE + "$" + "${PROJECT_BINARY_DIR}/generated_include" +) + +include(StripUtils) +ocio_strip_binary(ociocpuinfo) + +install(TARGETS ociocpuinfo + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/src/apps/ociocpuinfo/main.cpp b/src/apps/ociocpuinfo/main.cpp new file mode 100644 index 0000000000..ef5104e23c --- /dev/null +++ b/src/apps/ociocpuinfo/main.cpp @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright Contributors to the OpenColorIO Project. + +#include + +#include "CPUInfo.h" + +namespace OCIO = OCIO_NAMESPACE; + +int main() +{ + const OCIO::CPUInfo& cpu = OCIO::CPUInfo::instance(); + + std::cout << "name : " << cpu.getName() << std::endl; + std::cout << "vendor : " << cpu.getVendor() << std::endl; + std::cout << "hasSSE2 : " << cpu.hasSSE2() << std::endl; + std::cout << "SSE2Slow : " << cpu.SSE2Slow() << std::endl; + std::cout << "hasSSE3 : " << cpu.hasSSE3() << std::endl; + std::cout << "SSE3Slow : " << cpu.SSE3Slow() << std::endl; + std::cout << "hasSSSE3 : " << cpu.hasSSSE3() << std::endl; + std::cout << "SSSE3Slow : " << cpu.SSSE3Slow() << std::endl; + std::cout << "hasSSE4 : " << cpu.hasSSE4() << std::endl; + std::cout << "hasSSE42 : " << cpu.hasSSE42() << std::endl; + std::cout << "hasAVX : " << cpu.hasAVX() << std::endl; + std::cout << "AVXSlow : " << cpu.AVXSlow() << std::endl; + std::cout << "hasAVX2 : " << cpu.hasAVX2() << std::endl; + std::cout << "AVX2SlowGather : " << cpu.AVX2SlowGather() << std::endl; + std::cout << "hasAVX512 : " << cpu.hasAVX512() << std::endl; + std::cout << "hasF16C : " << cpu.hasF16C() << std::endl; + + return 0; +} \ No newline at end of file From 44f0f0b82774684a24590a49068c3b6d92994bb8 Mon Sep 17 00:00:00 2001 From: Mark Reid Date: Sat, 30 Mar 2024 00:15:13 -0700 Subject: [PATCH 3/3] Add ociocpuinfo to python console_scripts Signed-off-by: Mark Reid --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 1d67a70f24..0362d084ef 100644 --- a/setup.py +++ b/setup.py @@ -212,6 +212,7 @@ def build_extension(self, ext): 'ociocheck=PyOpenColorIO.command_line:main', 'ociochecklut=PyOpenColorIO.command_line:main', 'ocioconvert=PyOpenColorIO.command_line:main', + 'ociocpuinfo=PyOpenColorIO.command_line:main', 'ociodisplay=PyOpenColorIO.command_line:main', 'ociolutimage=PyOpenColorIO.command_line:main', 'ociomakeclf=PyOpenColorIO.command_line:main',