Skip to content

Commit 91767ac

Browse files
version 0.0.5
1 parent 603db46 commit 91767ac

File tree

13 files changed

+107
-217
lines changed

13 files changed

+107
-217
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "third_party/pybind11"]
2-
path = third_party/pybind11
3-
url = https://github.com/pybind/pybind11
41
[submodule "tensor-array-repo/Tensor-Array"]
52
path = tensor-array-repo/Tensor-Array
63
url = https://github.com/Tensor-Array/Tensor-Array

.vscode/c_cpp_properties.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"name": "Linux",
55
"includePath": [
66
"${workspaceFolder}/**",
7-
"${workspaceFolder}/third_party/pybind11/include/**",
87
"/usr/include/python3.*/**",
98
"${workspaceFolder}/tensor-array-repo/Tensor-Array/src/**"
109
],

CMakeLists.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

MANIFEST.in

Lines changed: 0 additions & 7 deletions
This file was deleted.
File renamed without changes.

pyproject.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
[build-system]
22
requires = [
33
"setuptools>=42",
4-
"ninja",
5-
"cmake>=3.18,<3.29"
4+
"pybind11>=2.6.0"
65
]
76
build-backend = "setuptools.build_meta"
87

98
[tool.cibuildwheel]
10-
xbuild-tools = [
11-
"cmake",
12-
"ninja"
13-
]
149
skip = [
1510
"pp*",
1611
"*-musllinux*",
@@ -30,11 +25,9 @@ skip = [
3025

3126
[tool.cibuildwheel.linux]
3227
before-all = [
33-
"chmod +x tensor-array-repo/Tensor-Array/scripts/actions/install-cuda-rhel.sh",
34-
"dnf install -y redhat-lsb-core wget",
35-
"tensor-array-repo/Tensor-Array/scripts/actions/install-cuda-rhel.sh"
28+
"chmod +x /scripts/build-env/manylinux.sh",
29+
"/scripts/build-env/manylinux.sh"
3630
]
37-
xbuild-tools = ["cmake", "ninja"]
3831

3932
[tool.cibuildwheel.linux.environment]
4033
cuda = "12.9"

scripts/build-env/manylinux.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ else
1010
USE_SUDO=
1111
fi
1212

13-
cd ../..
13+
cd ${PWD}
1414

1515
# Install dependencies for building Tensor-Array on manylinux
1616
echo "Installing dependencies for building Tensor-Array on manylinux..."
17-
chmod +x tensor-array-repo/Tensor-Array/scripts/actions/install-cuda-rhel.sh
17+
chmod +x /tensor-array-repo/Tensor-Array/scripts/actions/install-cuda-rhel.sh
1818
echo "Installing required packages..."
1919
$USE_SUDO yum install -y redhat-lsb-core wget
2020
echo "Running CUDA installation script..."
@@ -29,6 +29,7 @@ echo "$CUDA_PATH"
2929
echo
3030
echo "PATH="
3131
echo "$PATH"
32+
echo
3233
echo "LD_LIBRARY_PATH="
3334
echo "$LD_LIBRARY_PATH"
3435
echo
@@ -42,3 +43,28 @@ if ! command -v nvcc &> /dev/null; then
4243
exit 1
4344
fi
4445
echo "nvcc is available. Proceeding with the build environment setup."
46+
47+
cd tensor-array-repo/Tensor-Array
48+
49+
pip install "cmake>=3.18,<3.29"
50+
51+
# Create build directory if it doesn't exist
52+
if [ ! -d "build" ]; then
53+
echo "Creating build directory..."
54+
mkdir build
55+
else
56+
echo "Build directory already exists."
57+
fi
58+
# Change to the build directory
59+
cd build
60+
# Configure the build with CMake
61+
echo "Configuring the build with CMake..."
62+
cmake ..
63+
cmake --build .
64+
cmake --install .
65+
66+
cd ..
67+
rm -rf build
68+
69+
cd ../..
70+

setup.py

Lines changed: 44 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,38 @@
11
import os
2+
import glob
23
import re
34
import subprocess
45
import sys
5-
from pathlib import Path
66

7-
from setuptools import Extension, setup, find_packages
8-
from setuptools.command.build_ext import build_ext
7+
from setuptools import setup, find_packages
8+
from pybind11.setup_helpers import Pybind11Extension, build_ext
99

10-
# Convert distutils Windows platform specifiers to CMake -A arguments
11-
PLAT_TO_CMAKE = {
12-
"win32": "Win32",
13-
"win-amd64": "x64",
14-
"win-arm32": "ARM",
15-
"win-arm64": "ARM64",
16-
}
17-
18-
19-
# A CMakeExtension needs a sourcedir instead of a file list.
20-
# The name must be the _single_ output extension from the CMake build.
21-
# If you need multiple extensions, see scikit-build.
22-
class CMakeExtension(Extension):
23-
def __init__(self, name: str, sourcedir: str = "") -> None:
24-
super().__init__(name, sources=[])
25-
self.sourcedir = os.fspath(Path(sourcedir).resolve())
26-
27-
28-
class CMakeBuild(build_ext):
29-
def build_extension(self, ext: CMakeExtension) -> None:
30-
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+
31-
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
32-
extdir = ext_fullpath.parent.resolve()
33-
34-
# Using this requires trailing slash for auto-detection & inclusion of
35-
# auxiliary "native" libs
36-
37-
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
38-
cfg = "Debug" if debug else "Release"
39-
40-
# CMake lets you override the generator - we need to check this.
41-
# Can be set with Conda-Build, for example.
42-
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
43-
44-
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
45-
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
46-
# from Python.
47-
cmake_args = [
48-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
49-
f"-DPYTHON_EXECUTABLE={sys.executable}",
50-
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
51-
]
52-
build_args = []
53-
# Adding CMake arguments set as environment variable
54-
# (needed e.g. to build for ARM OSx on conda-forge)
55-
if "CMAKE_ARGS" in os.environ:
56-
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
57-
58-
# In this example, we pass in the version to C++. You might not need to.
59-
cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"]
60-
61-
if self.compiler.compiler_type != "msvc":
62-
# Using Ninja-build since it a) is available as a wheel and b)
63-
# multithreads automatically. MSVC would require all variables be
64-
# exported for Ninja to pick it up, which is a little tricky to do.
65-
# Users can override the generator with CMAKE_GENERATOR in CMake
66-
# 3.15+.
67-
if not cmake_generator or cmake_generator == "Ninja":
68-
try:
69-
import ninja
70-
71-
ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
72-
cmake_args += [
73-
"-GNinja",
74-
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
75-
]
76-
except ImportError:
77-
pass
78-
79-
else:
80-
# Single config generators are handled "normally"
81-
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})
82-
83-
# CMake allows an arch-in-generator style for backward compatibility
84-
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})
85-
86-
# Specify the arch if using MSVC generator, but only if it doesn't
87-
# contain a backward-compatibility arch spec already in the
88-
# generator name.
89-
if not single_config and not contains_arch:
90-
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]
91-
92-
# Multi-config generators have a different way to specify configs
93-
if not single_config:
94-
cmake_args += [
95-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
96-
]
97-
build_args += ["--config", cfg]
98-
99-
if sys.platform.startswith("darwin"):
100-
# Cross-compile support for macOS - respect ARCHFLAGS if set
101-
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
102-
if archs:
103-
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
104-
105-
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
106-
# across all generators.
107-
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
108-
# self.parallel is a Python 3 only way to set parallel jobs by hand
109-
# using -j in the build_ext call, not supported by pip or PyPA-build.
110-
if hasattr(self, "parallel") and self.parallel:
111-
# CMake 3.12+ only.
112-
build_args += [f"-j{self.parallel}"]
113-
114-
build_temp = Path(self.build_temp) / ext.name
115-
if not build_temp.exists():
116-
build_temp.mkdir(parents=True)
117-
118-
subprocess.run(
119-
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
120-
)
121-
subprocess.run(
122-
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
123-
)
10+
__version__ = "0.0.5"
12411

12512
def main():
12613
cwd = os.path.dirname(os.path.abspath(__file__))
12714
with open(os.path.join(cwd, "README.md"), encoding="utf-8") as f:
12815
long_description = f.read()
12916

130-
packages = find_packages()
131-
132-
print(packages)
17+
ext_modules = [
18+
Pybind11Extension(
19+
"tensor_array._ext",
20+
sources = glob.glob(os.path.join("cpp", "*.cc")),
21+
include_dirs=["tensor-array-repo/Tensor-Array/include"],
22+
library_dirs=["tensor-array-repo/Tensor-Array/lib"],
23+
#libraries=["libtensorarray_core"],
24+
define_macros=[("VERSION_INFO", __version__)],
25+
),
26+
]
13327

13428
setup(
13529
name = "TensorArray",
136-
version = "0.0.4",
30+
version = __version__,
13731
description = "A machine learning package",
138-
long_description= long_description,
139-
long_description_content_type="text/markdown",
140-
author="TensorArray-Creators",
141-
url="https://github.com/Tensor-Array/Tensor-Array-Python",
142-
packages=packages,
143-
ext_modules=[
144-
CMakeExtension("tensor2")
145-
],
32+
long_description = long_description,
33+
long_description_content_type = "text/markdown",
34+
author = "TensorArray-Creators",
35+
url = "https://github.com/Tensor-Array/Tensor-Array-Python",
14636
classifiers = [
14737
"Development Status :: 2 - Pre-Alpha",
14838

@@ -158,16 +48,33 @@ def main():
15848

15949
"Environment :: GPU :: NVIDIA CUDA :: 12",
16050
],
161-
license="MIT",
162-
cmdclass={
163-
"build_ext": CMakeBuild
51+
packages = [
52+
"tensor_array",
53+
"tensor_array_data.c_data.include",
54+
"tensor_array_data.c_data.lib",
55+
"tensor_array_data.c_data.scripts",
56+
"tensor_array_data.local.scripts",
57+
],
58+
package_dir= {
59+
"tensor_array": "src/tensor_array",
60+
"tensor_array_data.c_data.include": "tensor-array-repo/Tensor-Array/include",
61+
"tensor_array_data.c_data.lib": "tensor-array-repo/Tensor-Array/lib",
62+
"tensor_array_data.c_data.scripts": "tensor-array-repo/Tensor-Array/scripts",
63+
"tensor_array_data.local.scripts": "scripts",
64+
},
65+
package_data = {
66+
"tensor_array": ["**/*.py"],
67+
"tensor_array_data.c_data.include": ["**/*.hh"],
68+
"tensor_array_data.c_data.lib": ["**/*.so"],
69+
"tensor_array_data.c_data.scripts": ["**/*.sh"],
70+
"tensor_array_data.local.scripts": ["**/*.sh"],
16471
},
165-
package_dir={
166-
"": "src",
167-
"pybind11": "third_party/pybind11/pybind11",
168-
"tests": "tests"
72+
ext_modules = ext_modules,
73+
cmdclass = {
74+
"build_ext": build_ext,
16975
},
170-
python_requires=">=3.8",
76+
license = "MIT",
77+
python_requires = ">=3.8",
17178
)
17279

17380
if __name__ == "__main__":

src/tensor_array/core/constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def zeros(shape : tuple, dtype : DataTypes = DataTypes.S_INT_32) -> Tensor:
1717
Tensor: A tensor filled with zeros.
1818
"""
1919

20-
from .tensor2 import zeros as zerosWrapper
21-
return zerosWrapper(shape, dtype)
20+
from .._ext.tensor2 import zeros as _zeros
21+
return _zeros(shape, dtype)
2222

2323
def rand(shape : tuple, seed: int = 0) -> Tensor:
2424
"""
@@ -32,5 +32,5 @@ def rand(shape : tuple, seed: int = 0) -> Tensor:
3232
Tensor: A tensor filled with random values.
3333
"""
3434

35-
from .tensor2 import rand as randWrapper
36-
return randWrapper(shape, seed)
35+
from .._ext.tensor2 import rand as _rand
36+
return _rand(shape, seed)

src/tensor_array/core/datatypes.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
# The DataTypes enum includes types such as BOOL, INT, FLOAT, DOUBLE, and others, which correspond to the data types used in tensors.
55
"""
66

7-
from .tensor2 import DataType as DataTypeWrapper
7+
from .._ext.tensor2 import DataType as _DataType
88
from enum import Enum
99

1010
class DataTypes(Enum):
1111
"""
1212
Enum representing various data types supported by the TensorArray library.
1313
"""
14-
BOOL = DataTypeWrapper.BOOL
15-
S_INT_8 = DataTypeWrapper.S_INT_8
16-
S_INT_16 = DataTypeWrapper.S_INT_16
17-
S_INT_32 = DataTypeWrapper.S_INT_32
18-
S_INT_64 = DataTypeWrapper.S_INT_64
19-
FLOAT = DataTypeWrapper.FLOAT
20-
DOUBLE = DataTypeWrapper.DOUBLE
21-
HALF = DataTypeWrapper.HALF
22-
BFLOAT16 = DataTypeWrapper.BFLOAT16
23-
U_INT_8 = DataTypeWrapper.U_INT_8
24-
U_INT_16 = DataTypeWrapper.U_INT_16
25-
U_INT_32 = DataTypeWrapper.U_INT_32
26-
U_INT_64 = DataTypeWrapper.U_INT_64
14+
BOOL = _DataType.BOOL
15+
S_INT_8 = _DataType.S_INT_8
16+
S_INT_16 = _DataType.S_INT_16
17+
S_INT_32 = _DataType.S_INT_32
18+
S_INT_64 = _DataType.S_INT_64
19+
FLOAT = _DataType.FLOAT
20+
DOUBLE = _DataType.DOUBLE
21+
HALF = _DataType.HALF
22+
BFLOAT16 = _DataType.BFLOAT16
23+
U_INT_8 = _DataType.U_INT_8
24+
U_INT_16 = _DataType.U_INT_16
25+
U_INT_32 = _DataType.U_INT_32
26+
U_INT_64 = _DataType.U_INT_64

0 commit comments

Comments
 (0)