diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c8c56e7..27aeb81a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,10 +18,10 @@ jobs: submodules: recursive - name: Install Linux deps if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get -y --no-install-recommends install git g++ cmake ninja-build llvm-15-dev zlib1g-dev libglew-dev flex bison libfl-dev libzstd-dev + run: sudo apt-get update && sudo apt-get -y --no-install-recommends install git g++ cmake ninja-build llvm-15-dev zlib1g-dev flex bison libfl-dev libzstd-dev - name: Install macOS deps if: runner.os == 'macOS' - run: brew install cmake ninja llvm@15 zlib glew flex bison boost zstd ncurses + run: brew install cmake ninja llvm@15 zlib flex bison boost zstd ncurses - uses: actions/checkout@v6 if: runner.os == 'Linux' with: diff --git a/ocelot/CMakeLists.txt b/ocelot/CMakeLists.txt index 765fbdf2..16a91808 100644 --- a/ocelot/CMakeLists.txt +++ b/ocelot/CMakeLists.txt @@ -4,6 +4,7 @@ option(BUILD_LLVM "Use LLVM compiled from sources: default OFF" OFF) option(BUILD_TESTS "Build tests: default OFF" OFF) option(BUILD_TESTS_CUDA "Build CUDA tests: default ON" ON) option(BUILD_TOOLS "Build tool executables: default ON" ON) +option(ENABLE_OPENGL "Build OpenGL interop support" OFF) if (NOT APPLE AND BUILD_TESTS AND BUILD_TESTS_CUDA) project(gpuocelot C CXX CUDA ASM) @@ -36,11 +37,14 @@ set(Boost_USE_MULTITHREADED ON) find_package(Boost COMPONENTS filesystem thread REQUIRED) find_package(FLEX 2.5 REQUIRED) find_package(BISON 2.5 REQUIRED) -find_package(GLEW REQUIRED) find_package(ZLIB REQUIRED) find_library(ZSTD_LIB NAMES zstd libzstd) find_package(Curses REQUIRED) +if (ENABLE_OPENGL) +find_package(GLEW REQUIRED) +endif() + if ("x${BUILD_LLVM}" STREQUAL "xOFF") find_package(LLVM REQUIRED CONFIG) @@ -239,13 +243,11 @@ separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${PROJECT_NAME}_DEFINITI set(${PROJECT_NAME}_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} - ${GLEW_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/cuda-fatbin-decompression ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}) set(${PROJECT_NAME}_LINK_LIBRARIES - GLEW::GLEW hydrazine Boost::filesystem ZLIB::ZLIB @@ -253,6 +255,14 @@ set(${PROJECT_NAME}_LINK_LIBRARIES ${ZSTD_LIB} ${CMAKE_DL_LIBS}) +if (ENABLE_OPENGL) +list(APPEND ${PROJECT_NAME}_INCLUDE_DIRS ${GLEW_INCLUDE_DIRS}) +list(APPEND ${PROJECT_NAME}_LINK_LIBRARIES GLEW::GLEW) +list(APPEND ${PROJECT_NAME}_DEFINITIONS ENABLE_OPENGL=1) +else() +list(APPEND ${PROJECT_NAME}_DEFINITIONS ENABLE_OPENGL=0) +endif() + if ("x${BUILD_LLVM}" STREQUAL "xON") list(APPEND ${PROJECT_NAME}_LINK_LIBRARIES llvm) endif() diff --git a/ocelot/ThirdParty/hydrazine/CMakeLists.txt b/ocelot/ThirdParty/hydrazine/CMakeLists.txt index 4a61586f..746a2ca2 100644 --- a/ocelot/ThirdParty/hydrazine/CMakeLists.txt +++ b/ocelot/ThirdParty/hydrazine/CMakeLists.txt @@ -3,14 +3,22 @@ cmake_minimum_required(VERSION 2.8.12) project(hydrazine CXX) find_package(Boost COMPONENTS thread REQUIRED) +if (ENABLE_OPENGL) find_package(OpenGL REQUIRED) +endif() file(GLOB SRCS "src/*.cpp") add_library(${PROJECT_NAME} STATIC ${SRCS}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) -target_link_libraries(${PROJECT_NAME} Boost::thread OpenGL::GL) +target_link_libraries(${PROJECT_NAME} Boost::thread) +if (ENABLE_OPENGL) +target_link_libraries(${PROJECT_NAME} OpenGL::GL) +target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_OPENGL=1) +else() +target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_OPENGL=0) +endif() include(CTest) diff --git a/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp b/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp index e2022fdf..e611ff19 100644 --- a/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp +++ b/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp @@ -15,7 +15,9 @@ #include #include #elif __GNUC__ +#if ENABLE_OPENGL #include +#endif #include #include #include @@ -75,12 +77,16 @@ namespace hydrazine bool isAnOpenGLContextAvailable() { - #if __APPLE__ - // TODO fill this in + #if ENABLE_OPENGL + #if __APPLE__ + // TODO fill this in + return false; + #elif __GNUC__ + GLXContext openglContext = glXGetCurrentContext(); + return (openglContext != 0); + #endif + #else return false; - #elif __GNUC__ - GLXContext openglContext = glXGetCurrentContext(); - return (openglContext != 0); #endif } diff --git a/ocelot/include/ocelot/cuda/CudaDriver.h b/ocelot/include/ocelot/cuda/CudaDriver.h index 7b327ca5..6c02b845 100644 --- a/ocelot/include/ocelot/cuda/CudaDriver.h +++ b/ocelot/include/ocelot/cuda/CudaDriver.h @@ -15,11 +15,15 @@ #endif // OpenGL Includes +#if ENABLE_OPENGL #ifdef __APPLE__ #include #else #include #endif +#else +typedef unsigned int GLuint; +#endif // Standard Library Includes #include diff --git a/ocelot/include/ocelot/cuda/CudaDriverInterface.h b/ocelot/include/ocelot/cuda/CudaDriverInterface.h index 4095fbb0..f5286287 100644 --- a/ocelot/include/ocelot/cuda/CudaDriverInterface.h +++ b/ocelot/include/ocelot/cuda/CudaDriverInterface.h @@ -19,11 +19,15 @@ #undef min #endif +#if ENABLE_OPENGL #ifdef __APPLE__ #include #else #include #endif +#else +typedef unsigned int GLuint; +#endif // Ocelot includes #include diff --git a/ocelot/src/executive/EmulatorDevice.cpp b/ocelot/src/executive/EmulatorDevice.cpp index 3a3244e8..7bac0755 100644 --- a/ocelot/src/executive/EmulatorDevice.cpp +++ b/ocelot/src/executive/EmulatorDevice.cpp @@ -24,7 +24,9 @@ #endif // OpenGL includes +#if ENABLE_OPENGL #include +#endif // Standard library includes #include @@ -574,6 +576,7 @@ namespace executive void EmulatorDevice::mapGraphicsResource(void** resource, int count, unsigned int stream) { +#if ENABLE_OPENGL report("mapGraphicsResource(" << resource << ", " << count << ", " << stream << ")"); @@ -626,6 +629,9 @@ namespace executive Throw("OpenGL Error in mapGraphicsResource() - glBindBuffer2.") } } +#else + Throw("OpenGL interop disabled."); +#endif } void* EmulatorDevice::getPointerToMappedGraphicsResource(size_t& size, @@ -668,6 +674,7 @@ namespace executive void EmulatorDevice::unmapGraphicsResource(void** resource, int count, unsigned int streamID) { +#if ENABLE_OPENGL for (int i = 0; i < count; i++) { unsigned int handle = hydrazine::bit_cast( resource[i]); @@ -713,6 +720,9 @@ namespace executive Throw("OpenGL Error in unmapGraphicsResource() - glBindBuffer.") } } +#else + Throw("OpenGL interop disabled."); +#endif } void EmulatorDevice::load(const ir::Module* module)