-
-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python module mutli-platform setup #519
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39fbe2b
Change to pyproject.toml file
vathomass 5dc9fea
Switch to cmake for building the extension
vathomass 2180586
Update readme
vathomass a17925c
Update CHANGELOG
vathomass 116313c
Add hint fot CLBlast discovery
vathomass 7e40840
Update README about detecting the library
vathomass b00e107
Switch to scikit-build-core for using CMake
vathomass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) | ||
|
||
# Find python and numpy | ||
find_package( | ||
Python3 | ||
REQUIRED | ||
COMPONENTS Interpreter Development.Module NumPy | ||
) | ||
|
||
# Run the cython compiler | ||
cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "./src" | ||
OUTPUT_VARIABLE Cython_SOURCE_DIR) | ||
find_program(CYTHON "cython") | ||
add_custom_command( | ||
OUTPUT "${Cython_SOURCE_DIR}/pyclblast.cpp" | ||
DEPENDS "${Cython_SOURCE_DIR}/pyclblast.pyx" | ||
VERBATIM | ||
COMMAND "${CYTHON}" -3 "${Cython_SOURCE_DIR}/pyclblast.pyx" | ||
--output-file "${Cython_SOURCE_DIR}/pyclblast.cpp") | ||
|
||
|
||
# Add module target | ||
Python3_add_library(pyclblast MODULE WITH_SOABI | ||
"${Cython_SOURCE_DIR}/pyclblast.cpp") | ||
|
||
# Numpy libraries - NOTE: clean NPY_LIBRARIES cache (may fail for venv) | ||
cmake_path(GET Python3_NumPy_INCLUDE_DIRS PARENT_PATH Python3_NumPy_CORE_DIR) | ||
unset(NPY_LIBRARIES CACHE) | ||
find_library(NPY_LIBRARIES | ||
NAMES npymath | ||
PATHS ${Python3_NumPy_CORE_DIR} | ||
PATH_SUFFIXES lib | ||
DOC "Numpy math library" | ||
REQUIRED | ||
NO_DEFAULT_PATH) | ||
target_link_libraries(pyclblast PRIVATE ${NPY_LIBRARIES}) | ||
target_include_directories(pyclblast PRIVATE ${Python3_NumPy_INCLUDE_DIRS}) | ||
|
||
# CLBlast library | ||
set(CLBLAST_HINTS | ||
${CLBLAST_ROOT} | ||
$ENV{CLBLAST_ROOT} | ||
) | ||
find_package(CLBlast CONFIG REQUIRED HINTS ${CLBLAST_HINTS}) | ||
target_link_libraries(pyclblast PRIVATE clblast) | ||
|
||
install(TARGETS pyclblast DESTINATION .) | ||
|
||
# In windows pyclblast cannot find the dll, even on path. | ||
# Probably related to change in 3.8, that loads dll only for trusted location | ||
# see https://stackoverflow.com/questions/41365446/how-to-resolve-importerror-dll-load-failed-on-python | ||
# One workaround is to copy the dll to the same dir as the module. | ||
# TODO: add python version check | ||
if (WIN32) | ||
cmake_path(APPEND CLBlast_DIR "../../../bin" OUTPUT_VARIABLE CLBlast_BINDIR) | ||
cmake_path(SET CLBlast_BINDIR NORMALIZE "${CLBlast_BINDIR}") | ||
unset(CLBlast_SHARED_LIBPATH CACHE) | ||
find_file(CLBlast_SHARED_LIBPATH | ||
NAMES clblast.dll | ||
PATHS ${CLBlast_BINDIR} | ||
DOC "CLBlast shared library" | ||
REQUIRED) | ||
|
||
# copy dll to build | ||
install(FILES ${CLBlast_SHARED_LIBPATH} DESTINATION .) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include README.md setup.py src/*.pyx | ||
include README.md src/*.pyx | ||
include samples/*.py | ||
include CMakeLists.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[build-system] | ||
requires = ["scikit-build-core", "cython", "numpy"] | ||
build-backend = "scikit_build_core.build" | ||
|
||
[project] | ||
name = "pyclblast" | ||
version = "1.4.0" | ||
description = "Python bindings for CLBlast, the tuned OpenCL BLAS library" | ||
authors = [ | ||
{name = "Cedric Nugteren", email = "[email protected]"} | ||
] | ||
license = {text = "Apache Software License"} | ||
readme = "README.md" | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: Developers", | ||
"Topic :: Software Development :: Libraries", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Programming Language :: Python :: 2", | ||
"Programming Language :: Python :: 3", | ||
] | ||
keywords = ["OpenCL", "BLAS", "CLBlast", "GEMM", "matrix-multiplication"] | ||
dependencies = [ | ||
"numpy", | ||
"pyopencl" | ||
] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/CNugteren/CLBlast/blob/master/src/pyclblast" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["src"] |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did not work for me, while the old command does still work:
And if I remove that folder then I get
No module named build
. This is with the relatively old Python 3.7.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
No worries for the time taken, it is a festive period after all.
I have updated the changelog file.
Regarding the error, it seems to me that you have not installed the build python package. Running
python3 -m pip install --upgrade build
(or install it through your linux distro package manager) should make it work.Keep in mind that the
python -m build
method for packaging, is the one currently described in the guide in theREADME.md
link.Let me know if the error persists after you install the
build
package.One more unrelated thing, it would be good to add 'hints' (if you have any suggestion) for cmake to find the CLBlast library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes of course, thanks that fixes it. I got confused because I also had a local
build
folder, and didn't think ofbuild
as a Python package. It does build now and the tests pass.Hmm yes indeed. Not sure what those locations would be though. Perhaps something similar to what I did for the clBLAS library here: https://github.com/CNugteren/CLBlast/blob/master/cmake/Modules/FindclBLAS.cmake#L25?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some hints for CLBlast in the
CMakeLists.txt
file and updated theREADME.md
to inform the user about them.