WIP: CUDA build setup with CMake

The current CUDA build setup fails due to invalid flags in the nvcc command, leading to the error:

nvcc fatal: A single input file is required for a non-link phase when an output file is specified

The problematic flags are /MP and /bigobj, which cause nvcc to misinterpret the command structure. Removing these flags allows the compilation to succeed.

Further investigation is needed to determine how they can be removed form the CMake build system.
This commit is contained in:
Emil Wallberg
2025-02-20 15:08:04 +01:00
parent a10e77f255
commit 09397189c6
7 changed files with 123 additions and 10 deletions

View File

@@ -24,27 +24,67 @@
include(${PROJECT_SOURCE_DIR}/support/cmake/module_definition.cmake)
# Define Header Files
set(HEADER_FILES
blackholemodule.h
${CMAKE_CURRENT_SOURCE_DIR}/blackholemodule.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableblackhole.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/viewport.h
)
source_group("Header Files" FILES ${HEADER_FILES})
# Define Source Files
set(SOURCE_FILES
blackholemodule.cpp
${CMAKE_CURRENT_SOURCE_DIR}/blackholemodule.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableblackhole.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/viewport.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
# Define Shader Files
set(SHADER_FILES
shaders/gradiant_vs.glsl
shaders/gradiant_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/gradiant_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/gradiant_fs.glsl
)
source_group("Shader Files" FILES ${SHADER_FILES})
# Define CUDA Files
set(CUDA_FILES
${CMAKE_CURRENT_SOURCE_DIR}/cuda/blackhole_cuda.cu
${CMAKE_CURRENT_SOURCE_DIR}/cuda/blackhole_cuda.h
)
# Organize Files into Groups
source_group("Header Files" FILES ${HEADER_FILES})
source_group("Source Files" FILES ${SOURCE_FILES})
source_group("Shader Files" FILES ${SHADER_FILES})
source_group("CUDA Files" FILES ${CUDA_FILES})
# Create OpenSpace Module
create_new_module(
"BlackHole"
"BlackHole"
black_hole_module
STATIC
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
${HEADER_FILES}
${SOURCE_FILES}
${SHADER_FILES}
)
# Enable CUDA Compilation
enable_language(CUDA)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES native)
endif()
find_package(CUDAToolkit REQUIRED)
include_directories(${CUDAToolkit_INCLUDE_DIRS})
# Debug Messages
message("CMAKE_CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}")
message("CMAKE_CUDA_LIBRARY_ROOT: ${CUDAToolkit_LIBRARY_ROOT}")
message("CMAKE_CUDA_INCLUDE_DIRS: ${CUDAToolkit_INCLUDE_DIRS}")
message("CMAKE_CUDA_LIBRARY_DIR: ${CUDAToolkit_LIBRARY_DIR}")
# Create CUDA Library
add_library(blackhole_cuda SHARED ${CUDA_FILES})
set_target_properties(blackhole_cuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(blackhole_cuda PRIVATE CUDA::cudart)
target_link_libraries(openspace-module-blackhole PRIVATE blackhole_cuda)

View File

@@ -0,0 +1,12 @@
#include "blackhole_cuda.h"
#include <iostream>
#include <cuda_runtime.h>
__global__ void test_kernal() {
printf("HelLo form GPU!!!");
}
void openspace::cuda_test()
{
test_kernal<<<1, 1>>>();
}

View File

@@ -0,0 +1,8 @@
#ifndef __OPENSPACE_MODULE_BLACKHOLE___CUDA___H__
#define __OPENSPACE_MODULE_BLACKHOLE___CUDA___H__
namespace openspace {
void cuda_test();
}
#endif

View File

@@ -3,6 +3,8 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/rendering/framebufferrenderer.h>
#include <openspace/navigation/navigationhandler.h>
#include <openspace/rendering/renderengine.h>
#include <ghoul/opengl/framebufferobject.h>
#include <ghoul/opengl/openglstatecache.h>
@@ -12,6 +14,8 @@
#include <ghoul/filesystem/filesystem.h>
#include <filesystem>
#include <modules/blackhole/cuda/blackhole_cuda.h>
namespace {
constexpr std::string_view _loggerCat = "BlackHoleModule";
constexpr std::string_view ProgramName = "BlackHoleProgram";
@@ -32,6 +36,8 @@ namespace openspace {
}
void RenderableBlackHole::initialize() {
_viewport = ViewPort(global::navigationHandler->camera());
cuda_test();
}
void RenderableBlackHole::initializeGL() {
@@ -123,6 +129,8 @@ namespace openspace {
else {
LWARNING("UniformCache is missing 'enviromentTexture'");
}
//invProjection, invView
}
void RenderableBlackHole::drawQuad() {

View File

@@ -2,6 +2,7 @@
#define __OPENSPACE_MODULE_BLACKHOLE___RENDERABLECANVAS___H__
#include <openspace/rendering/renderable.h>
#include <modules/blackhole/rendering/viewport.h>
#include <ghoul/opengl/uniformcache.h>
namespace openspace {
@@ -31,12 +32,14 @@ private:
void setupQuad();
void loadEnvironmentTexture();
ghoul::opengl::ProgramObject* _program = nullptr;
ViewPort _viewport;
GLuint _framebuffer = 0;
GLuint _quadVao = 0;
GLuint _quadVbo = 0;
UniformCache(enviromentTexture) _uniformCache;
UniformCache(enviromentTexture, invProjection, invView) _uniformCache;
std::unique_ptr<ghoul::opengl::Texture> _enviromentTexture;
};

View File

@@ -0,0 +1,22 @@
#include <modules/blackhole/rendering/viewport.h>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
namespace openspace {
ViewPort::ViewPort(Camera* camera) : _camera(camera) {}
glm::dvec3 ViewPort::sphericalPosition() const {
if (!_camera) {
return glm::dvec3(0.0);
}
glm::dvec3 cartesian = _camera->positionVec3();
double r = glm::length(cartesian);
double theta = (r > 0.0) ? std::acos(cartesian.z / r) : 0.0;
double phi = std::atan2(cartesian.y, cartesian.x);
return glm::dvec3(r, theta, phi);
}
} // openspace namespace

View File

@@ -0,0 +1,20 @@
#ifndef __OPENSPACE_MODULE_BLACKHOLE___BLACKHOLECAMERA___H__
#define __OPENSPACE_MODULE_BLACKHOLE___BLACKHOLECAMERA___H__
#include <openspace/camera/camera.h>
#include <glm/glm.hpp>
namespace openspace {
class ViewPort {
public:
ViewPort() {};
ViewPort(Camera* camera);
glm::dvec3 sphericalPosition() const;
private:
Camera* _camera = nullptr;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_BLACKHOLE___BLACKHOLECAMERA___H__