Skip to content

Commit e5eb52a

Browse files
committed
Renaming files and public variables to avoid name collisions
1 parent c02e7c7 commit e5eb52a

18 files changed

+437
-377
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Ellen M. Price
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
# pocky: A Python bridge to OpenCL
2+
3+
[![build-docs action](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/emprice/pocky/gh-pages/endpoint.json)](https://github.com/emprice/pocky/actions/workflows/docs.yml)
4+
[![License: MIT](https://img.shields.io/github/license/emprice/pocky?style=for-the-badge)](https://opensource.org/licenses/MIT)
5+
![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/emprice/pocky/main?logo=codefactor&style=for-the-badge)
6+
![GitHub Repo stars](https://img.shields.io/github/stars/emprice/pocky?style=for-the-badge)

setup.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
source_dir = 'src/pocky/ext'
66
include_dir = 'src/pocky/ext/include'
77

8-
source_files = ['pocky.c', 'bufpair.c', 'context.c',
9-
'functions.c', 'helpers.c', 'utils.c']
8+
source_files = ['pocky.c', 'pocky_bufpair.c', 'pocky_context.c',
9+
'pocky_functions.c', 'pocky_helpers.c', 'pocky_utils.c']
1010
source_files = [os.path.join(source_dir, fname) for fname in source_files]
1111

12-
header_files = ['pocky.h', 'bufpair.h', 'context.h',
13-
'functions.h', 'helpers.h', 'utils.h']
12+
header_files = ['pocky.h', 'pocky_bufpair.h', 'pocky_context.h',
13+
'pocky_functions.h', 'pocky_helpers.h', 'pocky_utils.h']
1414
header_files = [os.path.join(include_dir, fname) for fname in header_files]
1515

1616
ext_modules = [
1717
Extension(name='pocky.ext', sources=source_files, libraries=['OpenCL'],
18-
define_macros=[('CL_TARGET_OPENCL_VERSION', '300')], language='c',
19-
include_dirs=[include_dir, np.get_include()], depends=header_files)
18+
language='c', include_dirs=[include_dir, np.get_include()],
19+
depends=header_files)
2020
]
2121
setup(ext_modules=ext_modules)

src/pocky/ext/helpers.c

-100
This file was deleted.

src/pocky/ext/include/bufpair.h

-36
This file was deleted.

src/pocky/ext/include/helpers.h

-40
This file was deleted.

src/pocky/ext/include/pocky.h

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313

1414
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
1515

16+
#define CL_TARGET_OPENCL_VERSION (300)
17+
1618
#include <CL/opencl.h>
1719

1820
/** Exception object for OpenCL-specific errors */
19-
extern PyObject *ocl_error;
21+
extern PyObject *pocky_ocl_error;
2022

2123
/** Handle of the Python @c Platform type */
22-
extern PyTypeObject *platform_type;
24+
extern PyTypeObject *pocky_platform_type;
2325

2426
/** Handle of the Python @c Device type */
25-
extern PyTypeObject *device_type;
27+
extern PyTypeObject *pocky_device_type;
2628

27-
#include "context.h"
28-
#include "bufpair.h"
29-
#include "functions.h"
30-
#include "helpers.h"
29+
#include "pocky_context.h"
30+
#include "pocky_bufpair.h"
31+
#include "pocky_functions.h"
32+
#include "pocky_helpers.h"
33+
#include "pocky_utils.h"
3134

3235
#endif /* POCKY_H */
36+
37+
/* vim: set ft=c.doxygen: */

src/pocky/ext/include/pocky_bufpair.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef POCKY_BUFPAIR_H
2+
#define POCKY_BUFPAIR_H
3+
4+
typedef struct
5+
{
6+
#ifndef DOXYGEN_SHOULD_SKIP_THIS
7+
PyObject_HEAD
8+
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
9+
pocky_context_object *context;
10+
PyObject *host;
11+
cl_mem device;
12+
size_t host_size;
13+
size_t device_size;
14+
}
15+
pocky_bufpair_object;
16+
17+
extern PyTypeObject pocky_bufpair_type;
18+
19+
extern PyObject *pocky_bufpair_new(PyTypeObject *type,
20+
PyObject *args, PyObject *kwargs);
21+
extern int pocky_bufpair_init(pocky_bufpair_object *self,
22+
PyObject *args, PyObject *kwargs);
23+
extern void pocky_bufpair_dealloc(pocky_bufpair_object *self);
24+
25+
extern PyObject *pocky_bufpair_array(pocky_bufpair_object *self, PyObject *noargs);
26+
27+
extern PyObject *pocky_bufpair_get_host(pocky_bufpair_object *self, void *closure);
28+
extern int pocky_bufpair_set_host(pocky_bufpair_object *self,
29+
PyObject *value, void *closure);
30+
31+
extern PyGetSetDef pocky_bufpair_getsetters[];
32+
extern PyMethodDef pocky_bufpair_methods[];
33+
34+
extern int pocky_bufpair_empty_like(pocky_context_object *context,
35+
pocky_bufpair_object *like, pocky_bufpair_object **bufpair);
36+
extern int pocky_bufpair_empty_from_shape(pocky_context_object *context,
37+
size_t ndim, size_t *shape, pocky_bufpair_object **bufpair);
38+
39+
#endif /* POCKY_BUFPAIR_H */
40+
41+
/* vim: set ft=c.doxygen: */

src/pocky/ext/include/context.h renamed to src/pocky/ext/include/pocky_context.h

+17-14
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,50 @@ typedef struct
1111
cl_uint num_queues; /**< Number of command queues */
1212
cl_command_queue *queues; /**< Array of command queues */
1313
}
14-
context_object;
14+
pocky_context_object;
1515

16-
/** Python type object for the @c Context object type */
17-
extern PyTypeObject context_type;
16+
/** Python type object for the @c pocky.ext.Context object type */
17+
extern PyTypeObject pocky_context_type;
1818

19-
extern PyMethodDef context_methods[];
19+
extern PyMethodDef pocky_context_methods[];
2020

2121
/**
22-
* @brief Allocates and initializes an empty Python @c Context object
22+
* @brief Allocates and initializes an empty Python @c pocky.ext.Context object
2323
* @param[in] type Type of object to allocate
2424
* @param[in] args Python arguments to be parsed
2525
* @param[in] kwargs Python keyword arguments to be parsed
26-
* @return A new Python @c Context object
26+
* @return A new Python @c pocky.ext.Context object
2727
*/
28-
extern PyObject *context_new(PyTypeObject *type, PyObject *args, PyObject *kwargs);
28+
extern PyObject *pocky_context_new(PyTypeObject *type,
29+
PyObject *args, PyObject *kwargs);
2930

3031
/**
31-
* @brief Deallocates a Python @c Context object
32+
* @brief Deallocates a Python @c pocky.ext.Context object
3233
* @param[in] self Object to be deallocated
3334
*/
34-
extern void context_dealloc(context_object *self);
35+
extern void pocky_context_dealloc(pocky_context_object *self);
3536

3637
/**
3738
* @brief Classmethod to create a context for the default platform
3839
* and devices, as well as all their command queues
3940
* @param[in] self Class reference
4041
* @param[in] args Python arguments to be parsed; any non-empty object
4142
* is a fatal error
42-
* @return Python @c Context object
43+
* @return Python @c pocky.ext.Context object
4344
*/
44-
extern PyObject *context_default(PyObject *self, PyObject *args);
45+
extern PyObject *pocky_context_default(PyObject *self, PyObject *args);
4546

4647
/**
4748
* @brief Classmethod to create a context for a list of devices, as
4849
* well as all their command queues
4950
* @param[in] self Class reference
5051
* @param[in] args Python arguments to be parsed; expects exactly one
5152
* argument that must be a Python @c PyList object containing only
52-
* Python @c Device structs
53-
* @return Python @c Context object
53+
* Python @c pocky.ext.Device structs
54+
* @return Python @c pocky.ext.Context object
5455
*/
55-
extern PyObject *context_from_devices(PyObject *self, PyObject *args);
56+
extern PyObject *pocky_context_from_device_list(PyObject *self, PyObject *args);
5657

5758
#endif /* POCKY_CONTEXT_H */
59+
60+
/* vim: set ft=c.doxygen: */

src/pocky/ext/include/functions.h renamed to src/pocky/ext/include/pocky_functions.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
* @param[in] self Module instance reference
77
* @param[in] args Python arguments to be parsed; for this function,
88
* should be empty
9-
* @return Python @c PyList object containing a @c Platform struct
9+
* @return Python @c PyList object containing a @c pocky.ext.Platform struct
1010
* for each available platform
1111
*/
12-
extern PyObject *list_all_platforms(PyObject *self, PyObject *args);
12+
extern PyObject *pocky_list_all_platforms(PyObject *self, PyObject *args);
1313

1414
/**
1515
* @brief Module method to list all available devices for a platform
1616
* @param[in] self Module instance reference
1717
* @param[in] args Python arguments to be parsed; expects exactly one
18-
* argument that must be a Python @c Platform struct
19-
* @return Python @c PyList object containing a @c Device struct
18+
* argument that must be a Python @c pocky.ext.Platform struct
19+
* @return Python @c PyList object containing a @c pocky.ext.Device struct
2020
* for each available device
2121
*/
22-
extern PyObject *list_all_devices(PyObject *self, PyObject *args);
22+
extern PyObject *pocky_list_all_devices(PyObject *self, PyObject *args);
2323

2424
#endif /* POCKY_FUNCTIONS_H */
25+
26+
/* vim: set ft=c.doxygen: */

0 commit comments

Comments
 (0)