Skip to content
Snippets Groups Projects
Commit c8e39354 authored by Hkorb's avatar Hkorb
Browse files

separate muparser and pyfluids bindings

unify cpu and gpu bindings
parent 1cd5bda3
No related branches found
No related tags found
1 merge request!170Kernel templetization and efficiency improvements
include pythonbindings/pyfluids/bindings*
\ No newline at end of file
include pythonbindings/*/bindings*
\ No newline at end of file
project(VirtualFluidsPython LANGUAGES CUDA CXX)
IF(BUILD_VF_GPU)
pybind11_add_module(python_bindings MODULE src/VirtualFluidsModulesGPU.cpp)
set_target_properties(python_bindings PROPERTIES
pybind11_add_module(python_bindings MODULE src/VirtualFluids.cpp)
set_target_properties( python_bindings PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pyfluids
OUTPUT_NAME "bindings")
set_source_files_properties(src/VirtualFluidsModulesGPU.cpp PROPERTIES LANGUAGE CUDA)
target_link_libraries(python_bindings PRIVATE GridGenerator VirtualFluids_GPU basics lbmCuda logger)
IF(BUILD_VF_GPU)
set_source_files_properties(src/VirtualFluids.cpp PROPERTIES LANGUAGE CUDA)
target_include_directories(python_bindings PRIVATE ${VF_THIRD_DIR}/cuda_samples/)
target_compile_definitions(python_bindings PRIVATE VF_GPU_PYTHONBINDINGS)
target_link_libraries(python_bindings PRIVATE GridGenerator VirtualFluids_GPU basics lbmCuda logger)
ENDIF()
IF(BUILD_VF_CPU)
pybind11_add_module(python_bindings MODULE src/VirtualFluidsModulesCPU.cpp)
pybind11_add_module(pymuparser MODULE src/muParser.cpp)
set_target_properties(python_bindings PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pyfluids
OUTPUT_NAME "bindings")
IF(BUILD_VF_CPU)
target_compile_definitions(python_bindings PRIVATE VF_METIS VF_MPI VF_CPU_PYTHONBINDINGS)
target_link_libraries(python_bindings PRIVATE simulationconfig VirtualFluidsCore muparser basics)
set_target_properties(pymuparser PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pyfluids
OUTPUT_NAME "pymuparser_bindings")
# include bindings for muparsers
pybind11_add_module(pymuparser MODULE src/muParser.cpp)
# TODO: Move this to MuParser CMakeLists.txt
set_target_properties(muparser PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(python_bindings PRIVATE VF_METIS VF_MPI)
set_target_properties( pymuparser PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pymuparser
OUTPUT_NAME "bindings")
target_compile_definitions(pymuparser PRIVATE VF_METIS VF_MPI)
target_link_libraries(python_bindings PRIVATE simulationconfig VirtualFluidsCore muparser basics)
target_link_libraries(pymuparser PRIVATE muparser)
ENDIF()
target_include_directories(python_bindings PRIVATE ${CMAKE_SOURCE_DIR}/src/)
target_include_directories(python_bindings PRIVATE ${CMAKE_BINARY_DIR})
\ No newline at end of file
try:
from .bindings import basics
except ImportError:
print("Basics bindings not included")
try:
from .bindings import logger
except ImportError:
print("Logger bindings not included")
try:
from .bindings import lbm
except ImportError:
print("LBM bindings not included")
try:
from .bindings import gpu
except ImportError:
print("GPU bindings not included")
try:
from .bindings import cpu
except ImportError:
print("CPU bindings not included")
\ No newline at end of file
try:
from .bindings import Parser
except ImportError as e:
raise ImportError("Pymuparser bindings were not built. Only included if VirtualFluids is built with VF_BUILD_CPU=ON.")
\ No newline at end of file
#include <pybind11/pybind11.h>
#include "basics/basics.cpp"
#include "lbm/lbm.cpp"
#include "gpu/gpu.cpp"
#include "logger/logger.cpp"
#ifdef VF_GPU_PYTHONBINDINGS
#include "gpu/gpu.cpp"
#endif
#ifdef VF_CPU_PYTHONBINDINGS
#include "cpu/cpu.cpp"
#endif
namespace py_bindings
{
namespace py = pybind11;
PYBIND11_MODULE(bindings, m)
{
py::add_ostream_redirect(m, "ostream_redirect");
basics::makeModule(m);
gpu::makeModule(m);
lbm::makeModule(m);
logging::makeModule(m);
py::add_ostream_redirect(m, "ostream_redirect");
#ifdef VF_GPU_PYTHONBINDINGS
gpu::makeModule(m);
#endif
#ifdef VF_CPU_PYTHONBINDINGS
cpu::makeModule(m);
#endif
}
}
\ No newline at end of file
#include <pybind11/pybind11.h>
#include "cpu/cpu.cpp"
namespace py_bindings
{
namespace py = pybind11;
PYBIND11_MODULE(bindings, m)
{
cpu::makeModule(m);
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@
namespace py = pybind11;
PYBIND11_MODULE(pymuparser, m) {
PYBIND11_MODULE(bindings, m) {
py::class_<mu::ParserBase>(m, "_ParserBase");
py::class_<mu::Parser, mu::ParserBase>(m, "Parser")
......
import sys
from pathlib import Path
import setuptools
import skbuild
"""
Install python wrapper of Virtual Fluids
install via python:
python setup.py install
set CMAKE Flags via -DBUILD_VF_GPU:BOOL=1
set CMAKE Flags via -DBUILD_VF_GPU:BOOL=ON
CMAKE flags have to be separated by --
example: python setup.py install -- VBUILD_VF_CPU:BOOL=ON
example: python setup.py install -- -DBUILD_VF_CPU:BOOL=ON
or install via pip:
pip install .
for pip>21:
......@@ -42,7 +41,7 @@ cmake_args += [
skbuild.setup(
name=package_name,
packages=[package_name],
packages=[package_name, "pymuparser"],
package_dir={"": src_dir},
cmake_args = cmake_args,
cmake_install_target=target,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment