Skip to content

Commit

Permalink
Visual Studio 2022 + CUDA 12.6
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyi1801 committed Sep 19, 2024
1 parent 3443292 commit 97795de
Show file tree
Hide file tree
Showing 77 changed files with 21,503 additions and 1,032 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)


# Enable C++11 for host code
set(CMAKE_CXX_STANDARD 11)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
Expand Down Expand Up @@ -61,6 +62,14 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/Bounds3.hpp
src/BVH.h
src/material.h
src/tiny_obj_loader.hpp
src/lightSample.h
src/distribution1D.h
src/distribution2D.h
src/ImGui/imconfig.h
)

set(sources
Expand All @@ -69,11 +78,14 @@ set(sources
src/image.cpp
src/glslUtility.cpp
src/pathtrace.cu
src/intersections.cu
src/interactions.cu
src/scene.cpp
src/preview.cpp
src/utilities.cpp
src/BVH.cpp
src/material.cpp
src/tiny_obj_loader.cpp
src/distribution1D.cpp
src/distribution2D.cpp
)

set(imgui_headers
Expand Down
102 changes: 102 additions & 0 deletions cmake/CUDAComputesList.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
## CUDA Compute detection code
## Sourced from ArrayFire https://github.com/arrayfire/arrayfire/
## Under BSD-3 Clause License https://github.com/arrayfire/arrayfire/blob/devel/LICENSE

#Disables running cuda_compute_check.c when build windows using remote
OPTION(CUDA_COMPUTE_DETECT "Run autodetection of CUDA Architecture" ON)
MARK_AS_ADVANCED(CUDA_COMPUTE_DETECT)

IF(CUDA_COMPUTE_DETECT AND NOT DEFINED COMPUTES_DETECTED_LIST)
#############################
#Sourced from:
#https://raw.githubusercontent.com/jwetzl/CudaLBFGS/master/CheckComputeCapability.cmake
#############################
# Check for GPUs present and their compute capability
# based on http://stackoverflow.com/questions/2285185/easiest-way-to-test-for-existence-of-cuda-capable-gpu-from-cmake/2297877#2297877 (Christopher Bruns)

IF(CUDA_FOUND)
MESSAGE(STATUS "${CMAKE_MODULE_PATH}/cuda_compute_capability.cpp")

TRY_RUN(RUN_RESULT_VAR COMPILE_RESULT_VAR
${PROJECT_BINARY_DIR}
${CMAKE_MODULE_PATH}/cuda_compute_capability.cpp
CMAKE_FLAGS
-DINCLUDE_DIRECTORIES:STRING=${CUDA_TOOLKIT_INCLUDE}
-DLINK_LIBRARIES:STRING=${CUDA_CUDART_LIBRARY}
COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT_VAR
RUN_OUTPUT_VARIABLE RUN_OUTPUT_VAR)

MESSAGE(STATUS "COMPILE_OUTPUT_VAR: ${COMPILE_OUTPUT_VAR}")
MESSAGE(STATUS "CUDA Compute Detection Output: ${RUN_OUTPUT_VAR}")
MESSAGE(STATUS "CUDA Compute Detection Return: ${RUN_RESULT_VAR}")

# COMPILE_RESULT_VAR is TRUE when compile succeeds
# Check Return Value of main() from RUN_RESULT_VAR
# RUN_RESULT_VAR is 0 when a GPU is found
# RUN_RESULT_VAR is 1 when errors occur

IF(COMPILE_RESULT_VAR AND RUN_RESULT_VAR EQUAL 0)
MESSAGE(STATUS "CUDA Compute Detection Worked")
# Convert output into a list of computes
STRING(REPLACE " " ";" COMPUTES_DETECTED_LIST ${RUN_OUTPUT_VAR})
SET(CUDA_HAVE_GPU TRUE CACHE BOOL "Whether CUDA-capable GPU is present")
ELSE()
MESSAGE(STATUS "CUDA Compute Detection Failed")
SET(CUDA_HAVE_GPU FALSE CACHE BOOL "Whether CUDA-capable GPU is present")
ENDIF()
ENDIF(CUDA_FOUND)
ENDIF()

IF( CUDA_COMPUTE_20
OR CUDA_COMPUTE_30
OR CUDA_COMPUTE_32
OR CUDA_COMPUTE_35
OR CUDA_COMPUTE_37
OR CUDA_COMPUTE_50
OR CUDA_COMPUTE_52
OR CUDA_COMPUTE_53
OR CUDA_COMPUTE_60
OR CUDA_COMPUTE_61
OR CUDA_COMPUTE_62
OR CUDA_COMPUTE_70
OR CUDA_COMPUTE_72
OR CUDA_COMPUTE_75
OR CUDA_COMPUTE_80
OR CUDA_COMPUTE_86
)
SET(FALLBACK OFF)
ELSE()
SET(FALLBACK ON)
ENDIF()

LIST(LENGTH COMPUTES_DETECTED_LIST COMPUTES_LEN)
IF(${COMPUTES_LEN} EQUAL 0 AND ${FALLBACK})
MESSAGE(STATUS "You can use -DCOMPUTES_DETECTED_LIST=\"AB;XY\" (semicolon separated list of CUDA Compute versions to enable the specified computes")
MESSAGE(STATUS "Individual compute versions flags are also available under CMake Advance options")
LIST(APPEND COMPUTES_DETECTED_LIST "30" "50" "60" "70" "80")
MESSAGE(STATUS "No computes detected. Fall back to 30, 50, 60, 70, 80")
ENDIF()

LIST(LENGTH COMPUTES_DETECTED_LIST COMPUTES_LEN)
MESSAGE(STATUS "Number of Computes Detected = ${COMPUTES_LEN}")

FOREACH(COMPUTE_DETECTED ${COMPUTES_DETECTED_LIST})
SET(CUDA_COMPUTE_${COMPUTE_DETECTED} ON CACHE BOOL "" FORCE)
ENDFOREACH()

MACRO(SET_COMPUTE VERSION)
SET(CUDA_GENERATE_CODE_${VERSION} "-gencode arch=compute_${VERSION},code=sm_${VERSION}")
SET(CUDA_GENERATE_CODE ${CUDA_GENERATE_CODE} ${CUDA_GENERATE_CODE_${VERSION}})
LIST(APPEND COMPUTE_VERSIONS "${VERSION}")
ADD_DEFINITIONS(-DCUDA_COMPUTE_${VERSION})
MESSAGE(STATUS "Setting Compute ${VERSION} to ON")
ENDMACRO(SET_COMPUTE)

# Iterate over compute versions. Create variables and enable computes if needed
FOREACH(VER 20 30 32 35 37 50 52 53 60 61 62 70 72 75 80 86)
OPTION(CUDA_COMPUTE_${VER} "CUDA Compute Capability ${VER}" OFF)
MARK_AS_ADVANCED(CUDA_COMPUTE_${VER})
IF(${CUDA_COMPUTE_${VER}})
SET_COMPUTE(${VER})
ENDIF()
ENDFOREACH()
60 changes: 60 additions & 0 deletions cmake/cuda_compute_capability.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2011 Florian Rathgeber, [email protected]
*
* This code is licensed under the MIT License. See the FindCUDA.cmake script
* for the text of the license.
*
* Based on code by Christopher Bruns published on Stack Overflow (CC-BY):
* http://stackoverflow.com/questions/2285185
*/

#include <stdio.h>
#include <cuda_runtime.h>
#include <iterator>
#include <set>

int main() {
int deviceCount;
int gpuDeviceCount = 0;
struct cudaDeviceProp properties;

if (cudaGetDeviceCount(&deviceCount) != cudaSuccess)
{
printf("Couldn't get device count: %s\n", cudaGetErrorString(cudaGetLastError()));
return 1;
}

std::set<int> computes;
typedef std::set<int>::iterator iter;

// machines with no GPUs can still report one emulation device
for (int device = 0; device < deviceCount; ++device) {
int major = 9999, minor = 9999;
cudaGetDeviceProperties(&properties, device);
if (properties.major != 9999) { // 9999 means emulation only
++gpuDeviceCount;
major = properties.major;
minor = properties.minor;
if ((major == 2 && minor == 1)) {
// There is no --arch compute_21 flag for nvcc, so force minor to 0
minor = 0;
}
computes.insert(10 * major + minor);
}
}
int i = 0;
for(iter it = computes.begin(); it != computes.end(); it++, i++) {
if(i > 0) {
printf(" ");
}
// IF CMAKE CAN NOT CAPTURE THE OUTPUT OF printf, USE fprintf INSTEAD
fprintf(stderr, "%d", *it);
// printf("%d", *it);
}
/* don't just return the number of gpus, because other runtime cuda
errors can also yield non-zero return values */
if (gpuDeviceCount <= 0 || computes.size() <= 0) {
return 1; // failure
}
return 0; // success
}
124 changes: 124 additions & 0 deletions scenes/BVH_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5

// Diffuse white
MATERIAL 1
RGB .98 .98 .98
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse red
MATERIAL 2
RGB .85 .35 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse green
MATERIAL 3
RGB .35 .85 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Specular white
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 5000
DEPTH 8
FILE cornell
EYE 4 5 10.5
LOOKAT 0 5 0
UP 0 1 0

// Back wall
OBJECT 0
cube
material 1
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10

// Floor
OBJECT 1
cube
material 1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 10 .01 10

// Ceiling
OBJECT 2
cube
material 1
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 10 10

// Ceiling light
OBJECT 3
cube
material 0
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3

// Left wall
OBJECT 4
cube
material 2
TRANS -4.99 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Right wall
OBJECT 5
cube
material 3
TRANS 4.99 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Sphere
OBJECT 6
../scenes/model/bunny.obj
material 4
TRANS -2 4 -1
ROTAT 0 0 0
SCALE 1 1 1

// Sphere
OBJECT 7
../scenes/model/bunny.obj
material 4
TRANS 3 4 -1
ROTAT 0 0 0
SCALE 1 1 1
Loading

0 comments on commit 97795de

Please sign in to comment.