Skip to content
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

Migrate to pybind11 #393

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "bpl-subset"]
path = bpl-subset
url = https://github.com/inducer/bpl-subset
[submodule "pycuda/compyte"]
path = pycuda/compyte
url = https://github.com/inducer/compyte
1 change: 0 additions & 1 deletion bpl-subset
Submodule bpl-subset deleted from 3702fb
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# implementing that C_API_VERSION.
requires = [
"setuptools",
"pybind11>=2.5.0",
"wheel",
"oldest-supported-numpy",
]
37 changes: 12 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function
from os.path import dirname, join, normpath


Expand All @@ -28,10 +27,8 @@ def get_config_schema():
IncludeDir,
LibraryDir,
Libraries,
BoostLibraries,
Switch,
StringListOption,
make_boost_base_options,
)

nvcc_path = search_on_path(["nvcc", "nvcc.exe"])
Expand Down Expand Up @@ -76,11 +73,7 @@ def get_config_schema():
default_lib_dirs.append("/usr/local/cuda/lib")

return ConfigSchema(
make_boost_base_options()
+ [
Switch("USE_SHIPPED_BOOST", True, "Use included Boost library"),
BoostLibraries("python"),
BoostLibraries("thread"),
[
Switch("CUDA_TRACE", False, "Enable CUDA API tracing"),
Option(
"CUDA_ROOT", default=cuda_root_default, help="Path to the CUDA toolkit"
Expand Down Expand Up @@ -118,27 +111,26 @@ def main():
get_config,
setup,
ExtensionUsingNumpy,
set_up_shipped_boost_if_requested,
check_git_submodules,
NumpyBuildExtCommand,
check_pybind11,
get_pybind_include,
PybindBuildExtCommand,
)

check_pybind11()
check_git_submodules()

hack_distutils()
conf = get_config(get_config_schema())

EXTRA_SOURCES, EXTRA_DEFINES = set_up_shipped_boost_if_requested("pycuda", conf)
EXTRA_SOURCES = []
EXTRA_DEFINES = {}

EXTRA_DEFINES["PYGPU_PACKAGE"] = "pycuda"
EXTRA_DEFINES["PYGPU_PYCUDA"] = "1"

LIBRARY_DIRS = conf["BOOST_LIB_DIR"] + conf["CUDADRV_LIB_DIR"]
LIBRARIES = (
conf["BOOST_PYTHON_LIBNAME"]
+ conf["BOOST_THREAD_LIBNAME"]
+ conf["CUDADRV_LIBNAME"]
)
LIBRARY_DIRS = conf["CUDADRV_LIB_DIR"]
LIBRARIES = conf["CUDADRV_LIBNAME"]

if not conf["CUDA_INC_DIR"] and conf["CUDA_ROOT"]:
conf["CUDA_INC_DIR"] = [join(conf["CUDA_ROOT"], "include")]
Expand All @@ -149,7 +141,7 @@ def main():
if conf["CUDA_PRETEND_VERSION"]:
EXTRA_DEFINES["CUDAPP_PRETEND_CUDA_VERSION"] = conf["CUDA_PRETEND_VERSION"]

INCLUDE_DIRS = ["src/cpp"] + conf["BOOST_INC_DIR"]
INCLUDE_DIRS = ["src/cpp", get_pybind_include()]
if conf["CUDA_INC_DIR"]:
INCLUDE_DIRS += conf["CUDA_INC_DIR"]

Expand Down Expand Up @@ -186,11 +178,6 @@ def main():

import sys

if sys.version_info >= (3,):
pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
else:
pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"

setup(
name="pycuda",
# metadata
Expand Down Expand Up @@ -254,12 +241,12 @@ def main():
),
ExtensionUsingNumpy(
"_pvt_struct",
[pvt_struct_source],
["src/wrapper/_pvt_struct_v3.cpp"],
extra_compile_args=conf["CXXFLAGS"],
extra_link_args=conf["LDFLAGS"],
),
],
cmdclass={"build_ext": NumpyBuildExtCommand},
cmdclass={"build_ext": PybindBuildExtCommand},
include_package_data=True,
package_data={
"pycuda": [
Expand Down
28 changes: 26 additions & 2 deletions src/cpp/bitlog.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
#include <bitlog.hpp>
// Base-2 logarithm bithack
//
// Copyright (C) 2009 Andreas Kloeckner
// Copyright (C) Sean Eron Anderson (in the public domain)
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.


#include "bitlog.hpp"


/* from http://graphics.stanford.edu/~seander/bithacks.html */
const char pycuda::log_table_8[] =
{
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
Expand Down
76 changes: 54 additions & 22 deletions src/cpp/bitlog.hpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,79 @@
// Base-2 logarithm bithack.




#ifndef _AFJDFJSDFSD_PYCUDA_HEADER_SEEN_BITLOG_HPP
#define _AFJDFJSDFSD_PYCUDA_HEADER_SEEN_BITLOG_HPP


//
// Copyright (C) 2009 Andreas Kloeckner
// Copyright (C) Sean Eron Anderson (in the public domain)
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.


#ifndef _AFJDFJSDFSD_PYOPENCL_HEADER_SEEN_BITLOG_HPP
#define _AFJDFJSDFSD_PYOPENCL_HEADER_SEEN_BITLOG_HPP


#include <climits>
#include <boost/cstdint.hpp>
#include <cstdint>


namespace pycuda
namespace pycuda
{
/* from http://graphics.stanford.edu/~seander/bithacks.html */

extern const char log_table_8[];

inline unsigned bitlog2_16(boost::uint16_t v)
inline unsigned bitlog2_16(uint16_t v)
{
if (unsigned long t = v >> 8)
return 8+log_table_8[t];
else
else
return log_table_8[v];
}

inline unsigned bitlog2_32(boost::uint32_t v)
inline unsigned bitlog2_32(uint32_t v)
{
if (boost::uint16_t t = v >> 16)
if (uint16_t t = v >> 16)
return 16+bitlog2_16(t);
else
return bitlog2_16(boost::uint16_t(v));
else
return bitlog2_16(v);
}

inline unsigned bitlog2(size_t v)
#if defined(UINT64_MAX)
inline unsigned bitlog2(uint64_t v)
{
if (uint32_t t = v >> 32)
return 32+bitlog2_32(t);
else
return bitlog2_32(v);
}
#else
inline unsigned bitlog2(unsigned long v)
{
#if (ULONG_MAX != 4294967295) || defined(_WIN64)
if (boost::uint32_t t = v >> 32)
#if (ULONG_MAX != 4294967295)
if (uint32_t t = v >> 32)
return 32+bitlog2_32(t);
else
else
#endif
return bitlog2_32(v);
}
#endif
return bitlog2_32(unsigned(v));
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

#include "cuda.hpp"

boost::thread_specific_ptr<pycuda::context_stack> pycuda::context_stack_ptr;
std::thread_specific_ptr<pycuda::context_stack> pycuda::context_stack_ptr;
Loading