Skip to content

Commit

Permalink
Merge pull request #125 from Kubiczek36/dev_pycpufit
Browse files Browse the repository at this point in the history
Dev_pycpufit
  • Loading branch information
gpufit authored Aug 31, 2023
2 parents df9a6b0 + 3e926ba commit 772d96f
Show file tree
Hide file tree
Showing 17 changed files with 843 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ if( PYTHONINTERP_FOUND )
add_python_launcher( RUN_PYTHON
"${CMAKE_SOURCE_DIR}/Gpufit/python"
"${Python_WORKING_DIRECTORY}"
)
add_custom_target( RUN_PYTHON_CPUFIT )
set_property( TARGET RUN_PYTHON_CPUFIT PROPERTY FOLDER CMakePredefinedTargets )
add_dependencies( RUN_PYTHON_CPUFIT Cpufit )
add_python_launcher( RUN_PYTHON_CPUFIT
"${CMAKE_SOURCE_DIR}/Cpufit/python"
"${Python_WORKING_DIRECTORY}"
)
endif()
endif()
Expand Down
1 change: 1 addition & 0 deletions Cpufit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ set_target_properties( Cpufit
#install( TARGETS Cpufit RUNTIME DESTINATION bin )

add_subdirectory( matlab )
add_subdirectory( python )
4 changes: 4 additions & 0 deletions Cpufit/cpufit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#define VISIBLE
#endif

#ifdef __APPLE__
#define VISIBLE __attribute__((visibility("default")))
#endif

#include <cstddef>
#include "../Gpufit/constants.h"
#include "../Gpufit/definitions.h"
Expand Down
58 changes: 58 additions & 0 deletions Cpufit/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

# Python

# Python package

set( build_directory "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/pyCpufit" )
set( setup_files
"${CMAKE_CURRENT_SOURCE_DIR}/README.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/setup.py"
"${CMAKE_CURRENT_SOURCE_DIR}/setup.cfg"
)
set( module_directory "${build_directory}/pycpufit" )
set( module_files
"${CMAKE_CURRENT_SOURCE_DIR}/pycpufit/__init__.py"
"${CMAKE_CURRENT_SOURCE_DIR}/pycpufit/cpufit.py"
"${CMAKE_CURRENT_SOURCE_DIR}/pycpufit/version.py"
)


set( binary $<TARGET_FILE:Cpufit> )


add_custom_target( PYTHON_PACKAGE_CPUFIT
COMMAND ${CMAKE_COMMAND} -E
remove_directory ${build_directory}
COMMAND ${CMAKE_COMMAND} -E
make_directory ${build_directory}
COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${setup_files} ${build_directory}
COMMAND ${CMAKE_COMMAND} -E
make_directory ${module_directory}
COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${module_files} ${module_directory}
COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${binary} ${module_directory}
)

set_property( TARGET PYTHON_PACKAGE_CPUFIT PROPERTY FOLDER CMakePredefinedTargets )
add_dependencies( PYTHON_PACKAGE_CPUFIT Cpufit )

if( NOT PYTHONINTERP_FOUND )
message( STATUS "Python NOT found - skipping creation of Python wheel!" )
return()
endif()

# Python wheel (output name is incorrect, requires plattform tag, see packaging)

add_custom_target( PYTHON_WHEEL_CPUFIT ALL
COMMAND ${CMAKE_COMMAND} -E
chdir ${build_directory} "${PYTHON_EXECUTABLE}" setup.py clean --all
COMMAND ${CMAKE_COMMAND} -E
chdir ${build_directory} "${PYTHON_EXECUTABLE}" setup.py bdist_wheel
COMMENT "Preparing Python Wheel"
)
set_property( TARGET PYTHON_WHEEL_CPUFIT PROPERTY FOLDER CMakePredefinedTargets )
add_dependencies( PYTHON_WHEEL_CPUFIT PYTHON_PACKAGE_CPUFIT )

# add launcher to Python package
22 changes: 22 additions & 0 deletions Cpufit/python/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Python binding for the [Cpufit library](https://github.com/gpufit/Gpufit) which implements Levenberg Marquardt curve fitting in CUDA

Requirements

- Windows
- Python 2 or 3 with NumPy

Installation

Currently the wheel file has to be installed locally.

If NumPy is not yet installed, install it using pip from the command line

pip install numpy

Then install pyCpufit from the local folder via:

pip install --no-index --find-links=LocalPathToWheelFile pyCpufit

Examples

See project-root/examples/python folder. **Cpufit** examples begin with `cpufit_`.
1 change: 1 addition & 0 deletions Cpufit/python/pycpufit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from cpufit import *
Loading

0 comments on commit 772d96f

Please sign in to comment.