Skip to content

Commit beabaeb

Browse files
Add project files.
1 parent b1ac4a9 commit beabaeb

File tree

10 files changed

+436
-0
lines changed

10 files changed

+436
-0
lines changed

CPythonTensor.sln

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34316.72
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPythonTensor", "CPythonTensor\CPythonTensor.vcxproj", "{79ABB953-907D-469F-9723-42ED1915A4B0}"
7+
EndProject
8+
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PythonTensorTesting", "PythonTensorTesting\PythonTensorTesting.pyproj", "{99206FE6-CF46-4140-93B2-3F659D2CA890}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Debug|x64 = Debug|x64
14+
Debug|x86 = Debug|x86
15+
Release|Any CPU = Release|Any CPU
16+
Release|x64 = Release|x64
17+
Release|x86 = Release|x86
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Debug|Any CPU.ActiveCfg = Debug|x64
21+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Debug|Any CPU.Build.0 = Debug|x64
22+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Debug|x64.ActiveCfg = Debug|x64
23+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Debug|x64.Build.0 = Debug|x64
24+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Debug|x86.ActiveCfg = Debug|Win32
25+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Debug|x86.Build.0 = Debug|Win32
26+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Release|Any CPU.ActiveCfg = Release|x64
27+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Release|Any CPU.Build.0 = Release|x64
28+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Release|x64.ActiveCfg = Release|x64
29+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Release|x64.Build.0 = Release|x64
30+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Release|x86.ActiveCfg = Release|Win32
31+
{79ABB953-907D-469F-9723-42ED1915A4B0}.Release|x86.Build.0 = Release|Win32
32+
{99206FE6-CF46-4140-93B2-3F659D2CA890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{99206FE6-CF46-4140-93B2-3F659D2CA890}.Debug|x64.ActiveCfg = Debug|Any CPU
34+
{99206FE6-CF46-4140-93B2-3F659D2CA890}.Debug|x86.ActiveCfg = Debug|Any CPU
35+
{99206FE6-CF46-4140-93B2-3F659D2CA890}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{99206FE6-CF46-4140-93B2-3F659D2CA890}.Release|x64.ActiveCfg = Release|Any CPU
37+
{99206FE6-CF46-4140-93B2-3F659D2CA890}.Release|x86.ActiveCfg = Release|Any CPU
38+
EndGlobalSection
39+
GlobalSection(SolutionProperties) = preSolution
40+
HideSolutionNode = FALSE
41+
EndGlobalSection
42+
GlobalSection(ExtensibilityGlobals) = postSolution
43+
SolutionGuid = {F504DBBF-809B-49DA-9604-93EE9EB84AB4}
44+
EndGlobalSection
45+
EndGlobal

CPythonTensor/CPythonTensor.vcxproj

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{79abb953-907d-469f-9723-42ed1915a4b0}</ProjectGuid>
25+
<RootNamespace>CPythonTensor</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>DynamicLibrary</ConfigurationType>
44+
<PlatformToolset>v143</PlatformToolset>
45+
<CharacterSet>Unicode</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>DynamicLibrary</ConfigurationType>
49+
<PlatformToolset>v143</PlatformToolset>
50+
<WholeProgramOptimization>true</WholeProgramOptimization>
51+
<CharacterSet>Unicode</CharacterSet>
52+
</PropertyGroup>
53+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
54+
<ImportGroup Label="ExtensionSettings">
55+
</ImportGroup>
56+
<ImportGroup Label="Shared">
57+
</ImportGroup>
58+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
59+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
60+
</ImportGroup>
61+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<PropertyGroup Label="UserMacros" />
71+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
72+
<TargetExt>.pyd</TargetExt>
73+
<TargetName>tensor_d</TargetName>
74+
</PropertyGroup>
75+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
76+
<TargetExt>.pyd</TargetExt>
77+
<TargetName>tensor</TargetName>
78+
</PropertyGroup>
79+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
80+
<ClCompile>
81+
<WarningLevel>Level3</WarningLevel>
82+
<SDLCheck>true</SDLCheck>
83+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
84+
<ConformanceMode>true</ConformanceMode>
85+
</ClCompile>
86+
<Link>
87+
<SubSystem>Console</SubSystem>
88+
<GenerateDebugInformation>true</GenerateDebugInformation>
89+
</Link>
90+
</ItemDefinitionGroup>
91+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
92+
<ClCompile>
93+
<WarningLevel>Level3</WarningLevel>
94+
<FunctionLevelLinking>true</FunctionLevelLinking>
95+
<IntrinsicFunctions>true</IntrinsicFunctions>
96+
<SDLCheck>true</SDLCheck>
97+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
98+
<ConformanceMode>true</ConformanceMode>
99+
</ClCompile>
100+
<Link>
101+
<SubSystem>Console</SubSystem>
102+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
103+
<OptimizeReferences>true</OptimizeReferences>
104+
<GenerateDebugInformation>true</GenerateDebugInformation>
105+
</Link>
106+
</ItemDefinitionGroup>
107+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
108+
<ClCompile>
109+
<WarningLevel>Level3</WarningLevel>
110+
<SDLCheck>true</SDLCheck>
111+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
112+
<ConformanceMode>true</ConformanceMode>
113+
<AdditionalIncludeDirectories>..\..\TensorCore\TensorCore;C:\Users\Noob\AppData\Local\Programs\Python\Python311\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
114+
<LanguageStandard>stdcpp17</LanguageStandard>
115+
</ClCompile>
116+
<Link>
117+
<SubSystem>NotSet</SubSystem>
118+
<GenerateDebugInformation>true</GenerateDebugInformation>
119+
<AdditionalLibraryDirectories>..\..\TensorCore\$(IntDir);C:\Users\Noob\AppData\Local\Programs\Python\Python311\libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
120+
<AdditionalDependencies>python311.lib;TensorCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
121+
</Link>
122+
<PostBuildEvent>
123+
<Command>xcopy /y /d "..\..\TensorCore\$(IntDir)TensorCore.dll" "$(OutDir)"</Command>
124+
</PostBuildEvent>
125+
</ItemDefinitionGroup>
126+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
127+
<ClCompile>
128+
<WarningLevel>Level3</WarningLevel>
129+
<FunctionLevelLinking>true</FunctionLevelLinking>
130+
<SDLCheck>true</SDLCheck>
131+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132+
<ConformanceMode>true</ConformanceMode>
133+
<AdditionalIncludeDirectories>..\..\TensorCore\TensorCore;C:\Users\Noob\AppData\Local\Programs\Python\Python311\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
134+
<LanguageStandard>stdcpp17</LanguageStandard>
135+
</ClCompile>
136+
<Link>
137+
<SubSystem>NotSet</SubSystem>
138+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
139+
<OptimizeReferences>true</OptimizeReferences>
140+
<GenerateDebugInformation>true</GenerateDebugInformation>
141+
<AdditionalLibraryDirectories>..\..\TensorCore\$(IntDir);C:\Users\Noob\AppData\Local\Programs\Python\Python311\libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
142+
<AdditionalDependencies>python311.lib;TensorCore.lib;%(AdditionalDependencies)</AdditionalDependencies>
143+
</Link>
144+
<PostBuildEvent>
145+
<Command>xcopy /y /d "..\..\TensorCore\$(IntDir)TensorCore.dll" "$(OutDir)"</Command>
146+
</PostBuildEvent>
147+
</ItemDefinitionGroup>
148+
<ItemGroup>
149+
<ClCompile Include="module.c" />
150+
<ClCompile Include="py_tensor.cpp" />
151+
</ItemGroup>
152+
<ItemGroup>
153+
<ClInclude Include="module.h" />
154+
</ItemGroup>
155+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
156+
<ImportGroup Label="ExtensionTargets">
157+
</ImportGroup>
158+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="module.c">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
<ClCompile Include="py_tensor.cpp">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClInclude Include="module.h">
27+
<Filter>Header Files</Filter>
28+
</ClInclude>
29+
</ItemGroup>
30+
</Project>

CPythonTensor/module.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include "module.h"
2+
#include <Python.h>
3+
4+
typedef struct
5+
{
6+
PyObject_HEAD
7+
void* t;
8+
} PyTensorObject;
9+
10+
static PyObject* Tensor_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
11+
{
12+
static char* kwlist[] = { "dtype", "shape", "data", NULL};
13+
PyObject *dtype, *shape;
14+
Py_ssize_t data_ptr;
15+
PyArg_ParseTupleAndKeywords(args, kwds, "|OOn", kwlist, &dtype, &shape, &data_ptr);
16+
unsigned int* ca = calloc(PyTuple_GET_SIZE(shape), sizeof(unsigned int));
17+
for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(shape); i++)
18+
ca[i] = _PyLong_AsInt(PyTuple_GET_ITEM(shape, i));
19+
PyTensorObject* self;
20+
self = type->tp_alloc(type, 0);
21+
if (self != NULL) {
22+
self->t = call_tensor(PyTuple_GET_SIZE(shape), ca, data_ptr);
23+
}
24+
free(ca);
25+
return self;
26+
}
27+
28+
static void Tensor_dealloc(PyTensorObject* self)
29+
{
30+
delete_tensor(self->t);
31+
Py_TYPE(self)->tp_free(self);
32+
}
33+
34+
static PyObject*
35+
Tensor_ToString(PyTensorObject* self)
36+
{
37+
return PyUnicode_FromString(to_string(self->t));
38+
}
39+
40+
static PyMethodDef Tensor_methods[] = {
41+
{NULL} /* Sentinel */
42+
};
43+
44+
static PyTypeObject TensorType =
45+
{
46+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
47+
.tp_name = "tensor.Tensor",
48+
.tp_doc = PyDoc_STR("Custom objects"),
49+
.tp_basicsize = sizeof(PyTensorObject),
50+
.tp_itemsize = 0,
51+
.tp_flags = Py_TPFLAGS_DEFAULT,
52+
.tp_new = Tensor_new,
53+
.tp_dealloc = Tensor_dealloc,
54+
.tp_methods = Tensor_methods,
55+
.tp_str = Tensor_ToString,
56+
};
57+
58+
static PyModuleDef tensor_module =
59+
{
60+
PyModuleDef_HEAD_INIT,
61+
"tensor",
62+
NULL,
63+
-1
64+
};
65+
66+
PyMODINIT_FUNC
67+
PyInit_tensor()
68+
{
69+
PyObject* m;
70+
if (PyType_Ready(&TensorType) < 0)
71+
return NULL;
72+
73+
m = PyModule_Create(&tensor_module);
74+
if (m == NULL)
75+
return NULL;
76+
77+
Py_INCREF(&TensorType);
78+
if (PyModule_AddObject(m, "Tensor", &TensorType) < 0) {
79+
Py_DECREF(&TensorType);
80+
Py_DECREF(m);
81+
return NULL;
82+
}
83+
84+
return m;
85+
}

CPythonTensor/module.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C"
5+
{
6+
#endif // __cplusplus
7+
void* call_tensor(unsigned int nd, unsigned int* dimensions, const void* data);
8+
void delete_tensor(void* t);
9+
const char* to_string(void* t);
10+
#ifdef __cplusplus
11+
}
12+
#endif // __cplusplus

CPythonTensor/py_tensor.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "module.h"
2+
#include <sstream>
3+
#include <tensor.hh>
4+
5+
using namespace tensor_array::value;
6+
7+
void* call_tensor(unsigned int nd, unsigned int* dimensions, const void* data)
8+
{
9+
return new Tensor(TensorBase(typeid(int), std::initializer_list(dimensions, dimensions + nd), data, tensor_array::devices::DEVICE_CPU_0, tensor_array::devices::DEVICE_CPU_0));
10+
}
11+
12+
void delete_tensor(void* t)
13+
{
14+
delete t;
15+
}
16+
17+
const char* to_string(void* t)
18+
{
19+
Tensor* t1 = static_cast<Tensor*>(t);
20+
std::ostringstream steam;
21+
steam << *t1;
22+
return steam.str().c_str();
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import numpy as np
2+
import tensor as t
3+
4+
class Tensor:
5+
def __init__(self, arr: np.ndarray):
6+
self.temp_tensor = t.Tensor(dtype = arr.dtype, shape = arr.shape, data = arr.ctypes.data)
7+
8+
9+
10+

PythonTensorTesting/PyTensorArray/tensor.py

Whitespace-only changes.

0 commit comments

Comments
 (0)