diff --git a/README.md b/README.md index 537f896..a319e81 100644 --- a/README.md +++ b/README.md @@ -32,66 +32,3 @@ ToDo ToDo -##### glkernel-cmd - -Additionally to using glkernel as a library, there is a standalone command line tool to generate kernels from JSON descriptions. -The usage is as follows: ```glkernel-cmd --i {input filename} --o {output filename}```, where ```{input filename}``` is a JSON kernel description file and ```{output file}``` is a JSON file containing a kernel. - -The description file must contain an entry "init-kernel" that describes the size and the number of components of the the kernel that will be generated. -It also has to contain an entry "commands", which is an array of commands that will be executed on the kernel. -For these, all glkernel commands can be used. - -The naming convention for applying glkernel commands is ```"{namespace}.{function name}"```, e.g. ```"noise.uniform"``` for ```noise::uniform```. -Arguments can be passed as a JSON object, e.g. ```{ "noise.uniform": { "range_min": -1.0, "range_max": 1.0 } }``` will call ```noise::uniform(kernel, -1.0, 1.0)```. - -Here is an input JSON for generating 4 samples using golden point set sampling, scaling them to [-0.5, 0.5] and shuffling them randomly: -```json -{ - "init-kernel": { - "components": 2, - "width": 4, - "height": 1, - "depth": 1 - }, - - "commands": [ - { "sample.golden_point_set": { } }, - { "scale.range": { "range_to_lower": -0.5, "range_to_upper": 0.5 } }, - { "shuffle.random": { } } - ] -} -``` - -The generated output JSON will look like this: -```json -{ - "kernel": [ - [ - [ - [ - -0.286392, - -0.437815 - ], - [ - -0.140494, - 0.180219 - ], - [ - 0.0955744, - -0.201747 - ], - [ - 0.47754, - 0.416287 - ] - ] - ] - ], - "size": { - "depth": 1, - "height": 1, - "width": 4 - } -} - -``` diff --git a/cmake/ClangTidy.cmake b/cmake/ClangTidy.cmake index 04b6c00..3e01032 100644 --- a/cmake/ClangTidy.cmake +++ b/cmake/ClangTidy.cmake @@ -17,6 +17,7 @@ function(perform_clang_tidy check_target target) set_target_properties(${check_target} PROPERTIES FOLDER "Maintenance" + EXCLUDE_FROM_DEFAULT_BUILD 1 ) add_dependencies(${check_target} ${target}) diff --git a/cmake/Cppcheck.cmake b/cmake/Cppcheck.cmake index 87a07d0..5638ac7 100644 --- a/cmake/Cppcheck.cmake +++ b/cmake/Cppcheck.cmake @@ -8,9 +8,7 @@ function(perform_cppcheck check_target target) COMMAND ${cppcheck_EXECUTABLE} "$<$:-I$>" - --check-config - --enable=warning,performance,portability,information,missingInclude - --quiet + --enable=all --std=c++11 --verbose --suppress=missingIncludeSystem diff --git a/cmake/HealthCheck.cmake b/cmake/HealthCheck.cmake index 37530b8..71fce6a 100644 --- a/cmake/HealthCheck.cmake +++ b/cmake/HealthCheck.cmake @@ -13,11 +13,18 @@ function(perform_health_checks target) set_target_properties(check-all PROPERTIES FOLDER "Maintenance" + EXCLUDE_FROM_DEFAULT_BUILD 1 ) endif() add_custom_target(check-${target}) + set_target_properties(check-${target} + PROPERTIES + FOLDER "Maintenance" + EXCLUDE_FROM_DEFAULT_BUILD 1 + ) + if (OPTION_CPPCHECK_ENABLED) perform_cppcheck(cppcheck-${target} ${target} ${ARGN}) add_dependencies(check-${target} cppcheck-${target}) @@ -92,5 +99,6 @@ function(add_check_template_target current_template_sha) set_target_properties(check-template PROPERTIES FOLDER "Maintenance" + EXCLUDE_FROM_DEFAULT_BUILD 1 ) endfunction() diff --git a/source/examples/sample/CMakeLists.txt b/source/examples/sample/CMakeLists.txt index db99355..61020c3 100644 --- a/source/examples/sample/CMakeLists.txt +++ b/source/examples/sample/CMakeLists.txt @@ -36,8 +36,11 @@ else() message(STATUS "Example ${target}") endif() -if (NOT OPENMP_FOUND) +if (NOT OPENMP_FOUND AND NOT OpenMP_FOUND) message("Loop parallelization in ${target} skipped: OpenMP not found") + set(OpenMP_SUPPORTED FALSE) +else() + set(OpenMP_SUPPORTED TRUE) endif() @@ -107,7 +110,7 @@ target_link_libraries(${target} target_compile_definitions(${target} PRIVATE - $<$:USE_OPENMP> + $<$:USE_OPENMP> ${DEFAULT_COMPILE_DEFINITIONS} ) @@ -118,7 +121,7 @@ target_compile_definitions(${target} target_compile_options(${target} PRIVATE - $<$:${OpenMP_CXX_FLAGS}> + $<$:${OpenMP_CXX_FLAGS}> ${DEFAULT_COMPILE_OPTIONS} ) @@ -130,7 +133,7 @@ target_compile_options(${target} target_link_libraries(${target} PRIVATE ${DEFAULT_LINKER_OPTIONS} - $<$>:$<$:${OpenMP_CXX_FLAGS}>> + $<$>:$<$:${OpenMP_CXX_FLAGS}>> ) diff --git a/source/tests/glkernel-test/CMakeLists.txt b/source/tests/glkernel-test/CMakeLists.txt index 9bfea40..dcf3f32 100644 --- a/source/tests/glkernel-test/CMakeLists.txt +++ b/source/tests/glkernel-test/CMakeLists.txt @@ -16,8 +16,11 @@ find_package(OpenMP QUIET) set(target glkernel-test) message(STATUS "Test ${target}") -if (NOT OPENMP_FOUND) +if (NOT OPENMP_FOUND AND NOT OpenMP_FOUND) message("Loop parallelization in ${target} skipped: OpenMP not found") + set(OpenMP_SUPPORTED FALSE) +else() + set(OpenMP_SUPPORTED TRUE) endif() @@ -92,7 +95,7 @@ target_link_libraries(${target} target_compile_definitions(${target} PRIVATE GLM_FORCE_RADIANS - $<$:USE_OPENMP> + $<$:USE_OPENMP> ${DEFAULT_COMPILE_DEFINITIONS} ) @@ -103,7 +106,7 @@ target_compile_definitions(${target} target_compile_options(${target} PRIVATE - $<$:${OpenMP_CXX_FLAGS}> + $<$:${OpenMP_CXX_FLAGS}> ${DEFAULT_COMPILE_OPTIONS} ) @@ -115,5 +118,5 @@ target_compile_options(${target} target_link_libraries(${target} PRIVATE ${DEFAULT_LINKER_OPTIONS} - $<$>:$<$:${OpenMP_CXX_FLAGS}>> + $<$>:$<$:${OpenMP_CXX_FLAGS}>> ) diff --git a/source/tools/CMakeLists.txt b/source/tools/CMakeLists.txt index 980b177..86089b9 100644 --- a/source/tools/CMakeLists.txt +++ b/source/tools/CMakeLists.txt @@ -5,4 +5,3 @@ if(NOT OPTION_BUILD_TOOLS) endif() # Example applications -add_subdirectory(glkernel-cmd) diff --git a/source/tools/glkernel-cmd/CMakeLists.txt b/source/tools/glkernel-cmd/CMakeLists.txt deleted file mode 100644 index 9c06616..0000000 --- a/source/tools/glkernel-cmd/CMakeLists.txt +++ /dev/null @@ -1,129 +0,0 @@ - -# -# External dependencies -# - -find_package(cppassist REQUIRED) -find_package(cppexpose REQUIRED) - -# -# Executable name and options -# - -# Target name -set(target glkernel-cmd) - - -# -# Sources -# - -set(headers - KernelGeneration.h - KernelToJson.h -) - -set(sources - main.cpp - KernelGeneration.cpp -) - -set(header_group "Header Files (API)") -set(source_group "Source Files") -source_group_by_path(${CMAKE_CURRENT_SOURCE_DIR} "\\\\.h$" - ${header_group} ${headers}) -source_group_by_path(${CMAKE_CURRENT_SOURCE_DIR} "\\\\.cpp$" - ${source_group} ${sources}) - - -# -# Create executable -# - -# Build executable -add_executable(${target} - ${sources} - ${headers} -) - - -# Create namespaced alias -add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) - - -# -# Project options -# - -set_target_properties(${target} - PROPERTIES - ${DEFAULT_PROJECT_OPTIONS} - FOLDER "${IDE_FOLDER}" -) - - -# -# Include directories -# - -target_include_directories(${target} - PRIVATE - ${DEFAULT_INCLUDE_DIRECTORIES} - ${CMAKE_CURRENT_BINARY_DIR} - ${PROJECT_BINARY_DIR}/source/include -) - - -# -# Libraries -# - -target_link_libraries(${target} - PRIVATE - ${DEFAULT_LIBRARIES} - cppassist::cppassist - cppexpose::cppexpose - ${META_PROJECT_NAME}::glkernel -) - - -# -# Compile definitions -# - -target_compile_definitions(${target} - PRIVATE - GLM_FORCE_RADIANS - ${DEFAULT_COMPILE_DEFINITIONS} -) - - -# -# Compile options -# - -target_compile_options(${target} - PRIVATE - ${DEFAULT_COMPILE_OPTIONS} -) - - -# -# Linker options -# - -target_link_libraries(${target} - PRIVATE - ${DEFAULT_LINKER_OPTIONS} -) - - -# -# Deployment -# - -# Executable -install(TARGETS ${target} - RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT examples - BUNDLE DESTINATION ${INSTALL_BIN} COMPONENT examples -) diff --git a/source/tools/glkernel-cmd/KernelGeneration.cpp b/source/tools/glkernel-cmd/KernelGeneration.cpp deleted file mode 100644 index baa872a..0000000 --- a/source/tools/glkernel-cmd/KernelGeneration.cpp +++ /dev/null @@ -1,381 +0,0 @@ -#include "KernelGeneration.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace -{ - template - void processPoissonSquare(glkernel::tkernel & kernel, unsigned int num_probes) - { - std::cout << "Poisson square is not implemented for the specified kernel type. Only kernel2 is supported." << std::endl; - } - - template <> - void processPoissonSquare(glkernel::kernel2 & kernel, unsigned int num_probes) - { - glkernel::sample::poisson_square(kernel, num_probes); - } - - template - void processStratified(glkernel::tkernel & kernel) - { - } - - template <> - void processStratified(glkernel::kernel1 & kernel) - { - glkernel::sample::stratified(kernel); - } - - template <> - void processStratified(glkernel::kernel2 & kernel) - { - glkernel::sample::stratified(kernel); - } - - template <> - void processStratified(glkernel::kernel3 & kernel) - { - glkernel::sample::stratified(kernel); - } - - template <> - void processStratified(glkernel::kernel4 & kernel) - { - std::cout << "Stratified is not implemented for kernel4." << std::endl; - } - - template - void processHammersley(glkernel::tkernel & kernel) - { - std::cout << "Hammersley is not implemented for the specified kernel type. Only kernel2 is supported." << std::endl; - } - - template <> - void processHammersley(glkernel::kernel2& kernel) - { - glkernel::sample::hammersley(kernel); - } - - template - void processHalton(glkernel::tkernel & kernel, uint base1, uint base2) - { - std::cout << "Hammersley is not implemented for the specified kernel type. Only kernel2 is supported." << std::endl; - } - - template <> - void processHalton(glkernel::kernel2 & kernel, uint base1, uint base2) - { - glkernel::sample::halton(kernel, base1, base2); - } - - template - void processHammersleySphere(glkernel::tkernel & kernel) - { - std::cout << "Hammersley is not implemented for the specified kernel type. Only kernel3 is supported." << std::endl; - } - - template <> - void processHammersleySphere(glkernel::kernel3 & kernel) - { - glkernel::sample::hammersley_sphere(kernel); - } - - template - void processHaltonSphere(glkernel::tkernel & kernel, uint base1, uint base2) - { - std::cout << "Hammersley is not implemented for the specified kernel type. Only kernel3 is supported." << std::endl; - } - - template <> - void processHaltonSphere(glkernel::kernel3 & kernel, uint base1, uint base2) - { - glkernel::sample::halton_sphere(kernel, base1, base2); - } - - template - void processBestCandidate(glkernel::tkernel & kernel, uint numCandidates) - { - std::cout << "Best Candidate is not implemented for the specified kernel type. Only kernel2 and kernel3 are supported." << std::endl; - } - - template <> - void processBestCandidate(glkernel::kernel2 & kernel, uint numCandidates) - { - glkernel::sample::best_candidate(kernel, numCandidates); - } - - template <> - void processBestCandidate(glkernel::kernel3 & kernel, uint numCandidates) - { - glkernel::sample::best_candidate(kernel, numCandidates); - } - - template - void processNRooks(glkernel::tkernel & kernel) - { - std::cout << "N rooks is not implemented for the specified kernel type. Only kernel2 is supported." << std::endl; - } - - template <> - void processNRooks(glkernel::kernel2 & kernel) - { - glkernel::sample::n_rooks(kernel); - } - - template - void processMultiJittered(glkernel::tkernel & kernel) - { - std::cout << "Multi jittered is not implemented for the specified kernel type. Only kernel2 is supported." << std::endl; - } - - template <> - void processMultiJittered(glkernel::kernel2 & kernel) - { - glkernel::sample::multi_jittered(kernel); - } - - template - void processGoldenPointSet(glkernel::tkernel & kernel) - { - std::cout << "Golden point set is not implemented for the specified kernel type. Only kernel2 is supported." << std::endl; - } - - template <> - void processGoldenPointSet(glkernel::kernel2 & kernel) - { - glkernel::sample::golden_point_set(kernel); - } - - template - void processCommand(glkernel::tkernel & kernel, const std::string & command, const cppexpose::VariantMap & arguments) - { - auto parseArg = [&](const std::string& argName, const float stdValue) -> float - { - if (arguments.find(argName) == arguments.end()) - { - std::cout << "Argument " << argName << " was not supplied to command " << command << ". Assuming standard value of " << stdValue << "." << std::endl; - return stdValue; - } - - return arguments.at(argName).value(); - }; - - // Noise - if (command == "noise.uniform") - { - glkernel::noise::uniform(kernel, parseArg("range_min", 0.0f), parseArg("range_max", 1.0f)); - } - else if (command == "noise.normal") - { - glkernel::noise::normal(kernel, parseArg("mean", 0.0f), parseArg("stddev", 1.0f)); - } - - // Sampling - else if (command == "sample.poisson_square") - { - processPoissonSquare(kernel, parseArg("num_probes", 32)); - } - else if (command == "sample.stratified") - { - processStratified(kernel); - } - else if (command == "sample.hammersley") - { - processHammersley(kernel); - } - else if (command == "sample.hammersley_sphere") - { - processHammersleySphere(kernel); - } - else if (command == "sample.halton") - { - processHalton(kernel, parseArg("base1", 2), parseArg("base2", 2)); - } - else if (command == "sample.halton_sphere") - { - processHaltonSphere(kernel, parseArg("base1", 2), parseArg("base2", 2)); - } - else if (command == "sample.best_candidate") - { - processBestCandidate(kernel, parseArg("num_candidates", 32)); - } - else if (command == "sample.n_rooks") - { - processNRooks(kernel); - } - else if (command == "sample.multi_jittered") - { - processMultiJittered(kernel); - } - else if (command == "sample.golden_point_set") - { - processGoldenPointSet(kernel); - } - - // Scale - else if (command == "scale.range") - { - glkernel::scale::range(kernel, parseArg("range_to_lower", 0.0f), parseArg("range_to_upper", 1.0f), parseArg("range_from_lower", 0.0f), parseArg("range_from_upper", 1.0f)); - } - - // Sequence - else if (command == "sequence.uniform") - { - glkernel::sequence::uniform(kernel, parseArg("range_min", 0.0f), parseArg("range_max", 1.0f)); - } - - // Shuffle - else if (command == "shuffle.bucket_permutate") - { - glkernel::shuffle::bucket_permutate(kernel, parseArg("subkernel_width", 1), parseArg("subkernel_height", 1), parseArg("subkernel_depth", 1)); - } - else if (command == "shuffle.bayer") - { - glkernel::shuffle::bayer(kernel); - } - else if (command == "shuffle.random") - { - glkernel::shuffle::random(kernel, parseArg("start", 1)); - } - - // Sort - else if (command == "sort.distance") - { - // TODO: read origin, needs to be based on T - glkernel::sort::distance(kernel, T()); - } - else - { - std::cout << "Command " << command << " is unknown. It is skipped." << std::endl; - } - } - - template - void processCommands(glkernel::tkernel & kernel, const cppexpose::VariantArray & commandArray) - { - for (auto& command : commandArray) - { - auto commandMap = command.asMap(); - - assert(!commandMap->empty()); - - auto& element = *commandMap->begin(); - - auto& commandName = element.first; - auto& arguments = element.second; - - auto argumentMap = arguments.asMap(); - - processCommand(kernel, commandName, *argumentMap); - } - } -} - -bool generateKernelFromDescription(cppexpose::Variant & kernelVariant, const std::string & filePath) -{ - cppexpose::Variant root; - - if (!cppexpose::JSON::load(root, filePath)) - { - std::cerr << "Input file could not be loaded." << std::endl; - return false; - } - - if (!root.isVariantMap()) - { - std::cerr << "Invalid JSON format. JSON does not contain a JSON object" << std::endl; - return false; - } - - auto rootMap = root.asMap(); - - if (rootMap->find("init-kernel") == rootMap->end()) - { - std::cerr << "Invalid JSON format. Entry 'init-kernel' not found. " << std::endl; - return false; - } - - auto initKernel = rootMap->at("init-kernel"); - auto initKernelMap = initKernel.asMap(); - - if (!initKernelMap) - { - std::cerr << "Invalid JSON format. Entry 'init-kernel' does not contain a JSON object. " << std::endl; - return false; - } - - auto components = initKernelMap->at("components").value(); - - auto width = initKernelMap->at("width").value(); - auto height = initKernelMap->at("height").value(); - auto depth = initKernelMap->at("depth").value(); - - if (rootMap->find("commands") == rootMap->end()) - { - std::cerr << "Invalid JSON format. Entry 'commands' not found. " << std::endl; - return false; - } - - auto commandJson = rootMap->at("commands"); - auto commandArray = commandJson.asArray(); - - if (!commandArray) - { - std::cerr << "Invalid JSON format. Entry 'commands' is not a JSON array. " << std::endl; - return false; - } - - if (components == 4) - { - glkernel::kernel4 kernel{ width, height, depth }; - - processCommands(kernel, *commandArray); - - kernelVariant = cppexpose::Variant::fromValue(kernel); - - return true; - } - else if (components == 3) - { - glkernel::kernel3 kernel{ width, height, depth }; - - processCommands(kernel, *commandArray); - - kernelVariant = cppexpose::Variant::fromValue(kernel); - - return true; - } - else if (components == 2) - { - glkernel::kernel2 kernel{ width, height, depth }; - - processCommands(kernel, *commandArray); - - kernelVariant = cppexpose::Variant::fromValue(kernel); - - return true; - } - else if (components == 1) - { - glkernel::kernel1 kernel{ width, height, depth }; - - processCommands(kernel, *commandArray); - - kernelVariant = cppexpose::Variant::fromValue(kernel); - - return true; - } - - return false; -} diff --git a/source/tools/glkernel-cmd/KernelGeneration.h b/source/tools/glkernel-cmd/KernelGeneration.h deleted file mode 100644 index 13c7965..0000000 --- a/source/tools/glkernel-cmd/KernelGeneration.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -bool generateKernelFromDescription(cppexpose::Variant & kernelVariant, const std::string & filePath); diff --git a/source/tools/glkernel-cmd/KernelToJson.h b/source/tools/glkernel-cmd/KernelToJson.h deleted file mode 100644 index a89d4d5..0000000 --- a/source/tools/glkernel-cmd/KernelToJson.h +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#include - -#include - -namespace -{ - template - void appendValueToVariantArray(cppexpose::Variant & variant, const T & t); - - template <> - void appendValueToVariantArray(cppexpose::Variant & variant, const float & t) - { - variant.asArray()->push_back(t); - } - - template <> - void appendValueToVariantArray(cppexpose::Variant & variant, const glm::vec2 & t) - { - variant.asArray()->push_back(t.x); - variant.asArray()->push_back(t.y); - } - - template <> - void appendValueToVariantArray(cppexpose::Variant & variant, const glm::vec3 & t) - { - variant.asArray()->push_back(t.x); - variant.asArray()->push_back(t.y); - variant.asArray()->push_back(t.z); - } - - template <> - void appendValueToVariantArray(cppexpose::Variant & variant, const glm::vec4 & t) - { - variant.asArray()->push_back(t.x); - variant.asArray()->push_back(t.y); - variant.asArray()->push_back(t.z); - variant.asArray()->push_back(t.w); - } -} - -template -cppexpose::Variant toJSON(const glkernel::tkernel & kernel) -{ - cppexpose::Variant zArray = cppexpose::Variant::array(); - - for (int z = 0; z < kernel.depth(); ++z) - { - cppexpose::Variant yArray = cppexpose::Variant::array(); - - for (int y = 0; y < kernel.height(); ++y) - { - cppexpose::Variant xArray = cppexpose::Variant::array(); - - for (int x = 0; x < kernel.width(); ++x) - { - cppexpose::Variant elementArray = cppexpose::Variant::array(); - - const T& value = kernel.value(x, y, z); - - appendValueToVariantArray(elementArray, value); - - xArray.asArray()->push_back(elementArray); - } - - yArray.asArray()->push_back(xArray); - } - - zArray.asArray()->push_back(yArray); - } - - cppexpose::Variant result = cppexpose::Variant::map(); - cppexpose::Variant size = cppexpose::Variant::map(); - - size.asMap()->emplace("height", kernel.height()); - size.asMap()->emplace("width", kernel.width()); - size.asMap()->emplace("depth", kernel.depth()); - - result.asMap()->emplace("size", size); - result.asMap()->emplace("kernel", zArray); - - return result; -} diff --git a/source/tools/glkernel-cmd/main.cpp b/source/tools/glkernel-cmd/main.cpp deleted file mode 100644 index dc4fb8e..0000000 --- a/source/tools/glkernel-cmd/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "KernelGeneration.h" -#include "KernelToJson.h" - -#include -#include - -#include - -#include -#include - -int main(int argc, char* argv[]) -{ - cppassist::ArgumentParser argParser; - argParser.parse(argc, argv); - - auto inFilename = argParser.value("--i"); - auto outFilename = argParser.value("--o"); - - cppexpose::Variant kernelDescription; - - if (!generateKernelFromDescription(kernelDescription, inFilename)) - { - std::cerr << "ERROR: kernel generation failed. Aborting..." << std::endl; - return 1; - } - - cppexpose::Variant kernelJSON; - - if (kernelDescription.hasType()) - { - kernelJSON = toJSON(kernelDescription.value()); - } - else if (kernelDescription.hasType()) - { - kernelJSON = toJSON(kernelDescription.value()); - } - else if (kernelDescription.hasType()) - { - kernelJSON = toJSON(kernelDescription.value()); - } - else if (kernelDescription.hasType()) - { - kernelJSON = toJSON(kernelDescription.value()); - } - - std::ofstream outStream(outFilename); - - if (!outStream.is_open()) - { - std::cerr << "ERROR: Output file could not be created. Aborting..." << std::endl; - return 1; - } - - outStream << cppexpose::JSON::stringify(kernelJSON, cppexpose::JSON::OutputMode::Beautify) << std::endl; - - return 0; -}