Skip to content

Commit

Permalink
Renaming files and public variables to avoid name collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
emprice committed Apr 3, 2024
1 parent c02e7c7 commit e5eb52a
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 377 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Ellen M. Price

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.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# pocky: A Python bridge to OpenCL

[![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)
[![License: MIT](https://img.shields.io/github/license/emprice/pocky?style=for-the-badge)](https://opensource.org/licenses/MIT)
![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/emprice/pocky/main?logo=codefactor&style=for-the-badge)
![GitHub Repo stars](https://img.shields.io/github/stars/emprice/pocky?style=for-the-badge)
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
source_dir = 'src/pocky/ext'
include_dir = 'src/pocky/ext/include'

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

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

ext_modules = [
Extension(name='pocky.ext', sources=source_files, libraries=['OpenCL'],
define_macros=[('CL_TARGET_OPENCL_VERSION', '300')], language='c',
include_dirs=[include_dir, np.get_include()], depends=header_files)
language='c', include_dirs=[include_dir, np.get_include()],
depends=header_files)
]
setup(ext_modules=ext_modules)
100 changes: 0 additions & 100 deletions src/pocky/ext/helpers.c

This file was deleted.

36 changes: 0 additions & 36 deletions src/pocky/ext/include/bufpair.h

This file was deleted.

40 changes: 0 additions & 40 deletions src/pocky/ext/include/helpers.h

This file was deleted.

19 changes: 12 additions & 7 deletions src/pocky/ext/include/pocky.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@

#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION

#define CL_TARGET_OPENCL_VERSION (300)

#include <CL/opencl.h>

/** Exception object for OpenCL-specific errors */
extern PyObject *ocl_error;
extern PyObject *pocky_ocl_error;

/** Handle of the Python @c Platform type */
extern PyTypeObject *platform_type;
extern PyTypeObject *pocky_platform_type;

/** Handle of the Python @c Device type */
extern PyTypeObject *device_type;
extern PyTypeObject *pocky_device_type;

#include "context.h"
#include "bufpair.h"
#include "functions.h"
#include "helpers.h"
#include "pocky_context.h"
#include "pocky_bufpair.h"
#include "pocky_functions.h"
#include "pocky_helpers.h"
#include "pocky_utils.h"

#endif /* POCKY_H */

/* vim: set ft=c.doxygen: */
41 changes: 41 additions & 0 deletions src/pocky/ext/include/pocky_bufpair.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef POCKY_BUFPAIR_H
#define POCKY_BUFPAIR_H

typedef struct
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
PyObject_HEAD
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
pocky_context_object *context;
PyObject *host;
cl_mem device;
size_t host_size;
size_t device_size;
}
pocky_bufpair_object;

extern PyTypeObject pocky_bufpair_type;

extern PyObject *pocky_bufpair_new(PyTypeObject *type,
PyObject *args, PyObject *kwargs);
extern int pocky_bufpair_init(pocky_bufpair_object *self,
PyObject *args, PyObject *kwargs);
extern void pocky_bufpair_dealloc(pocky_bufpair_object *self);

extern PyObject *pocky_bufpair_array(pocky_bufpair_object *self, PyObject *noargs);

extern PyObject *pocky_bufpair_get_host(pocky_bufpair_object *self, void *closure);
extern int pocky_bufpair_set_host(pocky_bufpair_object *self,
PyObject *value, void *closure);

extern PyGetSetDef pocky_bufpair_getsetters[];
extern PyMethodDef pocky_bufpair_methods[];

extern int pocky_bufpair_empty_like(pocky_context_object *context,
pocky_bufpair_object *like, pocky_bufpair_object **bufpair);
extern int pocky_bufpair_empty_from_shape(pocky_context_object *context,
size_t ndim, size_t *shape, pocky_bufpair_object **bufpair);

#endif /* POCKY_BUFPAIR_H */

/* vim: set ft=c.doxygen: */
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,50 @@ typedef struct
cl_uint num_queues; /**< Number of command queues */
cl_command_queue *queues; /**< Array of command queues */
}
context_object;
pocky_context_object;

/** Python type object for the @c Context object type */
extern PyTypeObject context_type;
/** Python type object for the @c pocky.ext.Context object type */
extern PyTypeObject pocky_context_type;

extern PyMethodDef context_methods[];
extern PyMethodDef pocky_context_methods[];

/**
* @brief Allocates and initializes an empty Python @c Context object
* @brief Allocates and initializes an empty Python @c pocky.ext.Context object
* @param[in] type Type of object to allocate
* @param[in] args Python arguments to be parsed
* @param[in] kwargs Python keyword arguments to be parsed
* @return A new Python @c Context object
* @return A new Python @c pocky.ext.Context object
*/
extern PyObject *context_new(PyTypeObject *type, PyObject *args, PyObject *kwargs);
extern PyObject *pocky_context_new(PyTypeObject *type,
PyObject *args, PyObject *kwargs);

/**
* @brief Deallocates a Python @c Context object
* @brief Deallocates a Python @c pocky.ext.Context object
* @param[in] self Object to be deallocated
*/
extern void context_dealloc(context_object *self);
extern void pocky_context_dealloc(pocky_context_object *self);

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

/**
* @brief Classmethod to create a context for a list of devices, as
* well as all their command queues
* @param[in] self Class reference
* @param[in] args Python arguments to be parsed; expects exactly one
* argument that must be a Python @c PyList object containing only
* Python @c Device structs
* @return Python @c Context object
* Python @c pocky.ext.Device structs
* @return Python @c pocky.ext.Context object
*/
extern PyObject *context_from_devices(PyObject *self, PyObject *args);
extern PyObject *pocky_context_from_device_list(PyObject *self, PyObject *args);

#endif /* POCKY_CONTEXT_H */

/* vim: set ft=c.doxygen: */
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
* @param[in] self Module instance reference
* @param[in] args Python arguments to be parsed; for this function,
* should be empty
* @return Python @c PyList object containing a @c Platform struct
* @return Python @c PyList object containing a @c pocky.ext.Platform struct
* for each available platform
*/
extern PyObject *list_all_platforms(PyObject *self, PyObject *args);
extern PyObject *pocky_list_all_platforms(PyObject *self, PyObject *args);

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

#endif /* POCKY_FUNCTIONS_H */

/* vim: set ft=c.doxygen: */
Loading

0 comments on commit e5eb52a

Please sign in to comment.