├── OpenCLGA
├── evaluation
│ ├── simulated_annealing
│ │ ├── __init__.py
│ │ ├── ocl_sa.cl
│ │ ├── sa.py
│ │ └── ocl_sa.py
│ ├── type_casting
│ │ ├── casting_vector.c
│ │ ├── casting.c
│ │ └── casting.py
│ ├── memory_usage
│ │ ├── test_private.c
│ │ ├── test_local.c
│ │ └── main.py
│ └── ant
│ │ ├── ant_tsp.cl
│ │ ├── python_ant_tsp.py
│ │ └── ant_tsp.py
├── ui
│ ├── favicon.ico
│ ├── apple-icon.png
│ ├── favicon-16x16.png
│ ├── favicon-32x32.png
│ ├── favicon-96x96.png
│ ├── ms-icon-70x70.png
│ ├── ms-icon-144x144.png
│ ├── ms-icon-150x150.png
│ ├── ms-icon-310x310.png
│ ├── android-icon-36x36.png
│ ├── android-icon-48x48.png
│ ├── android-icon-72x72.png
│ ├── android-icon-96x96.png
│ ├── apple-icon-114x114.png
│ ├── apple-icon-120x120.png
│ ├── apple-icon-144x144.png
│ ├── apple-icon-152x152.png
│ ├── apple-icon-180x180.png
│ ├── apple-icon-57x57.png
│ ├── apple-icon-60x60.png
│ ├── apple-icon-72x72.png
│ ├── apple-icon-76x76.png
│ ├── android-icon-144x144.png
│ ├── android-icon-192x192.png
│ ├── apple-icon-precomposed.png
│ ├── static
│ │ └── css
│ │ │ ├── main.5da4bf40.css.map
│ │ │ └── main.5da4bf40.css
│ ├── asset-manifest.json
│ ├── browserconfig.xml
│ ├── manifest.json
│ └── index.html
├── utilities
│ ├── __init__.py
│ ├── httpwebsocketserver
│ │ ├── __init__.py
│ │ ├── README.md
│ │ ├── ExampleWSServer.py
│ │ ├── websocket.html
│ │ ├── index.html
│ │ └── HTTPWebSocketsHandler.py
│ ├── socketserverclient
│ │ └── __init__.py
│ └── generaltaskthread
│ │ ├── __init__.py
│ │ ├── logger.py
│ │ └── generaltaskthread.py
├── __init__.py
├── __main__.py
├── kernel
│ ├── simple_gene.cl
│ ├── ocl_ga.cl
│ ├── ga_utils.cl
│ └── simple_chromosome.cl
├── simple_gene.py
├── ocl_ga_wsserver.py
├── utils.py
├── simple_chromosome.py
└── shuffler_chromosome.py
├── examples
├── taiwan_travel
│ ├── ui
│ │ ├── favicon.ico
│ │ ├── apple-icon.png
│ │ ├── favicon-16x16.png
│ │ ├── favicon-32x32.png
│ │ ├── favicon-96x96.png
│ │ ├── ms-icon-70x70.png
│ │ ├── apple-icon-57x57.png
│ │ ├── apple-icon-60x60.png
│ │ ├── apple-icon-72x72.png
│ │ ├── apple-icon-76x76.png
│ │ ├── ms-icon-144x144.png
│ │ ├── ms-icon-150x150.png
│ │ ├── ms-icon-310x310.png
│ │ ├── android-icon-36x36.png
│ │ ├── android-icon-48x48.png
│ │ ├── android-icon-72x72.png
│ │ ├── android-icon-96x96.png
│ │ ├── apple-icon-114x114.png
│ │ ├── apple-icon-120x120.png
│ │ ├── apple-icon-144x144.png
│ │ ├── apple-icon-152x152.png
│ │ ├── apple-icon-180x180.png
│ │ ├── android-icon-144x144.png
│ │ ├── android-icon-192x192.png
│ │ ├── apple-icon-precomposed.png
│ │ ├── static
│ │ │ └── css
│ │ │ │ ├── main.10448cc5.css.map
│ │ │ │ └── main.10448cc5.css
│ │ ├── asset-manifest.json
│ │ ├── browserconfig.xml
│ │ ├── manifest.json
│ │ └── index.html
│ ├── TW319_368Addresses.xlsx
│ ├── taiwan_travel_client.py
│ ├── kernel
│ │ └── taiwan_fitness.cl
│ └── taiwan_travel_server.py
├── algebra_expansion
│ ├── kernel
│ │ └── expansion.cl
│ └── expansion.py
├── grouping
│ ├── grouping.cl
│ └── grouping.py
├── tsp
│ ├── kernel
│ │ └── simple_tsp.cl
│ └── simple_tsp.py
└── scheduling - power station
│ ├── power.py
│ └── power.cl
├── .gitmodules
├── MANIFEST.in
├── LICENSE
├── setup.py
├── .gitignore
└── README.rst
/OpenCLGA/evaluation/simulated_annealing/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/OpenCLGA/ui/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/favicon.ico
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/favicon-16x16.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/favicon-32x32.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/favicon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/favicon-96x96.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/ms-icon-70x70.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/ms-icon-70x70.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/ms-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/ms-icon-144x144.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/ms-icon-150x150.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/ms-icon-150x150.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/ms-icon-310x310.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/ms-icon-310x310.png
--------------------------------------------------------------------------------
/OpenCLGA/utilities/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ["generaltaskthread", "httpwebsocketserver", "socketserverclient"]
2 |
--------------------------------------------------------------------------------
/OpenCLGA/utilities/httpwebsocketserver/__init__.py:
--------------------------------------------------------------------------------
1 | from .HTTPWebSocketsHandler import HTTPWebSocketsHandler
2 |
--------------------------------------------------------------------------------
/OpenCLGA/ui/android-icon-36x36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/android-icon-36x36.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/android-icon-48x48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/android-icon-48x48.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/android-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/android-icon-72x72.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/android-icon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/android-icon-96x96.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-114x114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-114x114.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-120x120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-120x120.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-144x144.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-152x152.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-180x180.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-57x57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-57x57.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-60x60.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-72x72.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-76x76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-76x76.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/android-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/android-icon-144x144.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/android-icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/android-icon-192x192.png
--------------------------------------------------------------------------------
/OpenCLGA/utilities/socketserverclient/__init__.py:
--------------------------------------------------------------------------------
1 | from .server_client import Client, Server, OP_MSG_BEGIN, OP_MSG_END
2 |
--------------------------------------------------------------------------------
/OpenCLGA/ui/apple-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/OpenCLGA/ui/apple-icon-precomposed.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/favicon.ico
--------------------------------------------------------------------------------
/OpenCLGA/utilities/generaltaskthread/__init__.py:
--------------------------------------------------------------------------------
1 | from .generaltaskthread import TaskThread, Task
2 | from .logger import Logger
3 |
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/favicon-16x16.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/favicon-32x32.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/favicon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/favicon-96x96.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/ms-icon-70x70.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/ms-icon-70x70.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/TW319_368Addresses.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/TW319_368Addresses.xlsx
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-57x57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-57x57.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-60x60.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-72x72.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-76x76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-76x76.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/ms-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/ms-icon-144x144.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/ms-icon-150x150.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/ms-icon-150x150.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/ms-icon-310x310.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/ms-icon-310x310.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/android-icon-36x36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/android-icon-36x36.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/android-icon-48x48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/android-icon-48x48.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/android-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/android-icon-72x72.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/android-icon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/android-icon-96x96.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-114x114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-114x114.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-120x120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-120x120.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-144x144.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-152x152.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-180x180.png
--------------------------------------------------------------------------------
/OpenCLGA/ui/static/css/main.5da4bf40.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":[],"names":[],"mappings":"","file":"static/css/main.5da4bf40.css","sourceRoot":""}
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/android-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/android-icon-144x144.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/android-icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/android-icon-192x192.png
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/apple-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PyOCL/OpenCLGA/HEAD/examples/taiwan_travel/ui/apple-icon-precomposed.png
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "utilities/generaltaskthread"]
2 | path = utilities/generaltaskthread
3 | url = https://github.com/kilikkuo/py_generaltaskthread.git
4 |
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/static/css/main.10448cc5.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":[],"names":[],"mappings":"","file":"static/css/main.10448cc5.css","sourceRoot":""}
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include LICENSE README.rst
2 | recursive-include OpenCLGA/kernel *
3 | recursive-include OpenCLGA/ui *
4 | recursive-exclude * __pycache__
5 | recursive-exclude * .gitignore
6 |
--------------------------------------------------------------------------------
/examples/taiwan_travel/taiwan_travel_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | if __name__ == '__main__':
3 | from OpenCLGA import start_ocl_ga_client
4 | start_ocl_ga_client('127.0.0.1', 12345)
5 |
--------------------------------------------------------------------------------
/OpenCLGA/ui/asset-manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "main.css": "static/css/main.5da4bf40.css",
3 | "main.css.map": "static/css/main.5da4bf40.css.map",
4 | "main.js": "static/js/main.7371ebc2.js",
5 | "main.js.map": "static/js/main.7371ebc2.js.map"
6 | }
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/asset-manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "main.css": "static/css/main.10448cc5.css",
3 | "main.css.map": "static/css/main.10448cc5.css.map",
4 | "main.js": "static/js/main.0b7ca193.js",
5 | "main.js.map": "static/js/main.0b7ca193.js.map"
6 | }
--------------------------------------------------------------------------------
/OpenCLGA/ui/browserconfig.xml:
--------------------------------------------------------------------------------
1 |
2 | #ffffff
--------------------------------------------------------------------------------
/OpenCLGA/__init__.py:
--------------------------------------------------------------------------------
1 | from .simple_gene import SimpleGene
2 | from .shuffler_chromosome import ShufflerChromosome
3 | from .simple_chromosome import SimpleChromosome
4 | from .ocl_ga import OpenCLGA
5 | from .ocl_ga_server import start_ocl_ga_server
6 | from .ocl_ga_client import start_ocl_ga_client
7 | from . import utils
8 |
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/browserconfig.xml:
--------------------------------------------------------------------------------
1 |
2 | #ffffff
--------------------------------------------------------------------------------
/OpenCLGA/evaluation/type_casting/casting_vector.c:
--------------------------------------------------------------------------------
1 |
2 | __kernel void casting_test(__global const float4* a_g, __global const float4* b_g,
3 | __global float4 *res_g) {
4 |
5 | int id = get_global_id(0);
6 | if (id >= (GLOBAL_SIZE)) {
7 | return;
8 | }
9 | __global TypedStruct2* tsA = (__global TypedStruct2*) a_g;
10 | __global TypedStruct2* tsB = (__global TypedStruct2*) b_g;
11 | __global TypedStruct2* tsR = (__global TypedStruct2*) res_g;
12 |
13 | %code_generation%
14 | }
15 |
--------------------------------------------------------------------------------
/OpenCLGA/__main__.py:
--------------------------------------------------------------------------------
1 | def main():
2 | import argparse
3 | from .ocl_ga_client import start_ocl_ga_client
4 | parser = argparse.ArgumentParser(description='OpenCLGA client help')
5 | parser.add_argument('server', metavar='ip', type=str,
6 | help='the server ip, default : 127.0.0.1', default='127.0.0.1')
7 | parser.add_argument('port', metavar='port', type=int,
8 | help='the server port, default : 12345', default=12345)
9 | args = parser.parse_args()
10 | start_ocl_ga_client(args.server, args.port)
11 |
12 | main()
13 |
--------------------------------------------------------------------------------
/OpenCLGA/kernel/simple_gene.cl:
--------------------------------------------------------------------------------
1 | #ifndef __oclga_simple_gene__
2 | #define __oclga_simple_gene__
3 |
4 | #include "ga_utils.cl"
5 |
6 | /**
7 | * simle_gene_mutate mutates a single gene. Because we mapped the elements as
8 | * the index, we random select another index as the value of the gene.
9 | * @param *gene (global) the gene we need to mutate
10 | * @param max the size of elements.
11 | * @param *ra the random number holder.
12 | */
13 | void simple_gene_mutate(global int* gene, uint max, uint* ra) {
14 | *gene = rand_range_exclude(ra, max, *gene);
15 | }
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/OpenCLGA/evaluation/type_casting/casting.c:
--------------------------------------------------------------------------------
1 | typedef struct {
2 | float data[GLOBAL_SIZE];
3 | } TypedStruct;
4 |
5 | __kernel void casting_test(__global const float* a_g, __global const float* b_g,
6 | __global float *res_g) {
7 |
8 | int id = get_global_id(0);
9 | if (id >= GLOBAL_SIZE) {
10 | return;
11 | }
12 | __global TypedStruct* tsA = (__global TypedStruct*) a_g;
13 | __global TypedStruct* tsB = (__global TypedStruct*) b_g;
14 | __global TypedStruct* tsR = (__global TypedStruct*) res_g;
15 | tsR->data[id] = tsA->data[id] + tsB->data[id];
16 | }
17 |
--------------------------------------------------------------------------------
/OpenCLGA/evaluation/memory_usage/test_private.c:
--------------------------------------------------------------------------------
1 |
2 | int calcutate(int index)
3 | {
4 | int a = (index * 32) & 128;
5 | return a;
6 | }
7 |
8 | #define PM_SIZE 10240 + 4096 + 200
9 |
10 | __kernel void test(int size, global int* in, global int* out)
11 | {
12 | int idx = get_global_id(0);
13 | // out of bound kernel task for padding
14 |
15 | if (idx >= size) {
16 | return;
17 | }
18 |
19 | /*
20 | On Intel CPU, the private memroy limitation is 64 KB.
21 | */
22 | int ga[PM_SIZE] = {1};
23 |
24 | /*
25 | On Intel CPU, private memory will be used more efficient if the barrier below is used.
26 | That is, we can create larger ga.
27 | */
28 | // barrier(CLK_LOCAL_MEM_FENCE);
29 |
30 | out[idx] = ga[idx%PM_SIZE];
31 | }
32 |
--------------------------------------------------------------------------------
/OpenCLGA/ui/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "App",
3 | "icons": [
4 | {
5 | "src": "\/android-icon-36x36.png",
6 | "sizes": "36x36",
7 | "type": "image\/png",
8 | "density": "0.75"
9 | },
10 | {
11 | "src": "\/android-icon-48x48.png",
12 | "sizes": "48x48",
13 | "type": "image\/png",
14 | "density": "1.0"
15 | },
16 | {
17 | "src": "\/android-icon-72x72.png",
18 | "sizes": "72x72",
19 | "type": "image\/png",
20 | "density": "1.5"
21 | },
22 | {
23 | "src": "\/android-icon-96x96.png",
24 | "sizes": "96x96",
25 | "type": "image\/png",
26 | "density": "2.0"
27 | },
28 | {
29 | "src": "\/android-icon-144x144.png",
30 | "sizes": "144x144",
31 | "type": "image\/png",
32 | "density": "3.0"
33 | },
34 | {
35 | "src": "\/android-icon-192x192.png",
36 | "sizes": "192x192",
37 | "type": "image\/png",
38 | "density": "4.0"
39 | }
40 | ]
41 | }
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "App",
3 | "icons": [
4 | {
5 | "src": "\/android-icon-36x36.png",
6 | "sizes": "36x36",
7 | "type": "image\/png",
8 | "density": "0.75"
9 | },
10 | {
11 | "src": "\/android-icon-48x48.png",
12 | "sizes": "48x48",
13 | "type": "image\/png",
14 | "density": "1.0"
15 | },
16 | {
17 | "src": "\/android-icon-72x72.png",
18 | "sizes": "72x72",
19 | "type": "image\/png",
20 | "density": "1.5"
21 | },
22 | {
23 | "src": "\/android-icon-96x96.png",
24 | "sizes": "96x96",
25 | "type": "image\/png",
26 | "density": "2.0"
27 | },
28 | {
29 | "src": "\/android-icon-144x144.png",
30 | "sizes": "144x144",
31 | "type": "image\/png",
32 | "density": "3.0"
33 | },
34 | {
35 | "src": "\/android-icon-192x192.png",
36 | "sizes": "192x192",
37 | "type": "image\/png",
38 | "density": "4.0"
39 | }
40 | ]
41 | }
--------------------------------------------------------------------------------
/examples/algebra_expansion/kernel/expansion.cl:
--------------------------------------------------------------------------------
1 | float expansion_calc_difference(global __SimpleChromosome* chromosome,
2 | int x,
3 | int y)
4 | {
5 | float xy = 0.0 + x + y;
6 | float expected = pown(xy, 10);
7 | float calculated = 0.0;
8 |
9 | for (int i = 0; i < 11; i++) {
10 | calculated += (*chromosome).genes[i] * pown((float)x, 10 - i) * pown((float)y, i);
11 | }
12 | return fabs(expected - calculated);
13 | }
14 |
15 | void expansion_fitness(global __SimpleChromosome* chromosome,
16 | global float* fitnesses,
17 | int chromosome_size,
18 | int chromosome_count)
19 | {
20 | float diff = 0.0;
21 | for (int x = 1; x < 10; x++) {
22 | for (int y = 1; y < 10; y++) {
23 | diff += expansion_calc_difference(chromosome, x, y);
24 | }
25 | }
26 | // We should divide to 1,000,000 to prevent overflow of python float.
27 | *fitnesses = diff / 1000000;
28 | }
29 |
--------------------------------------------------------------------------------
/OpenCLGA/utilities/generaltaskthread/logger.py:
--------------------------------------------------------------------------------
1 | def logi(msg):
2 | print('[INFO] ' + msg + '\033[m')
3 | def logv(msg):
4 | print('\033[1;34m[VERBOSE] ' + msg + '\033[m')
5 | def logw(msg):
6 | print('\033[1;36m[WARNING] ' + msg + '\033[m')
7 | def loge(msg):
8 | print('\033[1;31m[ERROR] ' + msg + '\033[m')
9 |
10 | class Logger(object):
11 | MSG_INFO = 0x01
12 | MSG_WARNING = 0x02
13 | MSG_ERROR = 0x04
14 | MSG_VERBOSE = 0x08
15 | MSG_ALL = MSG_INFO | MSG_WARNING | MSG_ERROR | MSG_VERBOSE
16 | def __init__(self):
17 | self.logger_level = Logger.MSG_ALL
18 | def info(self, msg):
19 | if self.logger_level & Logger.MSG_INFO:
20 | logi(msg)
21 | def warning(self, msg):
22 | if self.logger_level & Logger.MSG_WARNING:
23 | logw(msg)
24 | def error(self, msg):
25 | if self.logger_level & Logger.MSG_ERROR:
26 | loge(msg)
27 | def verbose(self, msg):
28 | if self.logger_level & Logger.MSG_VERBOSE:
29 | logv(msg)
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Python OpenCL
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.
22 |
--------------------------------------------------------------------------------
/OpenCLGA/kernel/ocl_ga.cl:
--------------------------------------------------------------------------------
1 | #include "ga_utils.cl"
2 |
3 | /**
4 | * ocl_ga_calculate_fitness is a wrapper function to call specified fitness
5 | * function. To simplify the implementation of fitness calcuation, we handles
6 | * the multi-threading part and let implementor write the core calculation.
7 | * Note: this is a kernel function and will be called by python.
8 | *
9 | * @param *chromosomes (global) the chromosomes array
10 | * @param *fitness (global) the fitness array for each chromosomes.
11 | * @param FITNESS_ARGS the fitness arguments from ocl_ga options.
12 | */
13 | __kernel void ocl_ga_calculate_fitness(global int* chromosomes,
14 | global float* fitness FITNESS_ARGS)
15 | {
16 | int idx = get_global_id(0);
17 | // out of bound kernel task for padding
18 | if (idx >= POPULATION_SIZE) {
19 | return;
20 | }
21 | // calls the fitness function specified by user and gives the chromosome for
22 | // current thread.
23 | CALCULATE_FITNESS(((global CHROMOSOME_TYPE*) chromosomes) + idx,
24 | fitness + idx,
25 | CHROMOSOME_SIZE, POPULATION_SIZE FITNESS_ARGV);
26 | }
27 |
--------------------------------------------------------------------------------
/examples/grouping/grouping.cl:
--------------------------------------------------------------------------------
1 |
2 | float calc_linear_distance(float x1, float y1, float x2, float y2)
3 | {
4 | return sqrt(pown(x2 - x1, 2) + pown(y2 - y1, 2));
5 | }
6 |
7 | void grouping_fitness(global __SimpleChromosome* chromosome,
8 | global float* fitnesses,
9 | int chromosome_size,
10 | int chromosome_count,
11 | global int* numOfGroups,
12 | global float* pointX,
13 | global float* pointY)
14 | {
15 | float dist = 0.0;
16 | int group = numOfGroups[0];
17 | for (int i = 0; i < group; i++) {
18 | for (int j = 0; j < chromosome_size; j++) {
19 | for (int k = j+1; k < chromosome_size; k++) {
20 | // Calculate the sum of dist among all points in the same group.
21 | if (i == chromosome->genes[j] && i == chromosome->genes[k]) {
22 | dist += calc_linear_distance(pointX[j],
23 | pointY[j],
24 | pointX[k],
25 | pointY[k]);
26 | }
27 | }
28 | }
29 | }
30 | *fitnesses = dist;
31 | }
32 |
--------------------------------------------------------------------------------
/examples/tsp/kernel/simple_tsp.cl:
--------------------------------------------------------------------------------
1 |
2 | float calc_linear_distance(float x1, float y1, float x2, float y2)
3 | {
4 | return sqrt(pown(x2 - x1, 2) + pown(y2 - y1, 2));
5 | }
6 |
7 | void simple_tsp_fitness(global __ShufflerChromosome* chromosome,
8 | global float* fitnesses,
9 | int chromosome_size,
10 | int chromosome_count,
11 | global float* pointsX,
12 | global float* pointsY)
13 | {
14 | float dist = 0.0;
15 | for (int i = 0; i < chromosome_size-1; i++) {
16 | dist += calc_linear_distance(pointsX[chromosome->genes[i + 1]],
17 | pointsY[chromosome->genes[i + 1]],
18 | pointsX[chromosome->genes[i]],
19 | pointsY[chromosome->genes[i]]);
20 | }
21 | dist += calc_linear_distance(pointsX[chromosome->genes[0]],
22 | pointsY[chromosome->genes[0]],
23 | pointsX[chromosome->genes[chromosome_size - 1]],
24 | pointsY[chromosome->genes[chromosome_size - 1]]);
25 | *fitnesses = dist;
26 | }
27 |
--------------------------------------------------------------------------------
/OpenCLGA/utilities/httpwebsocketserver/README.md:
--------------------------------------------------------------------------------
1 | # httpwebsockethandler
2 | Python combines HTTP and WebSocketServer with SSL support
3 |
4 | ##command line options
5 |
6 | ```shell
7 | #assume ExampleWSServer.py and HTTPWebSocketsHandler.py are in the current directory
8 | nohup python ExampleWSServer.py 8000 secure username:mysecret >>ws.log&
9 | ```
10 |
11 | This uses SSL/https. Change username:mysecret in a username:password chosen by yourself. The websserver uses port 8000 by default, and can be changed by an optional parameter:
12 |
13 | `nohup python ExampleWSServer.py 8001 secure username:mysecret >>ws.log&`
14 |
15 | Providing a user:password is optional, as well as using SSL/https. When the website is only accessible within your LAN, then the server can be used as plain http, by omitting the secure parameter. The following parameter formats are valid:
16 |
17 | ```shell
18 | nohup python ExampleWSServer.py 8001 secure user:password >>ws.log&
19 |
20 | #no username and password requested
21 | nohup python ExampleWSServer.py 8000 secure >>ws.log&
22 |
23 | #plain http, with optional port
24 | nohup python ExampleWSServer.py 8002 >>ws.log&
25 |
26 | #plain http, default port 8000
27 | nohup python ExampleWSServer.py >>ws.log&
28 | ```
29 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | import os
3 | import sys
4 | from setuptools import setup, find_packages
5 |
6 | # We intend to support Python 3.5+, let's get rid of 2.x !
7 | if (sys.version_info[0], sys.version_info[1]) <= (3, 4):
8 | sys.exit('Sorry, only Python 3.5+ is supported')
9 |
10 | package_files_paths = []
11 | def package_files(directory):
12 | global package_files_paths
13 | for (path, directories, filenames) in os.walk(directory):
14 | for filename in filenames:
15 | if filename == '.gitignore':
16 | continue
17 | print(filename)
18 | package_files_paths.append(os.path.join('..', path, filename))
19 |
20 | package_files('OpenCLGA/ui')
21 | package_files('OpenCLGA/kernel')
22 |
23 | setup(name='OpenCLGA',
24 | version='0.1',
25 | description='Run a general purpose genetic algorithm on top of pyopencl.',
26 | url='https://github.com/PyOCL/OpenCLGA.git',
27 | author='John Hu(胡訓誠), Kilik Kuo(郭彥廷)',
28 | author_email='im@john.hu, kilik.kuo@gmail.com',
29 | license='MIT',
30 | include_package_data=True,
31 | packages=find_packages(),
32 | package_data={
33 | 'OpenCLGA': package_files_paths,
34 | },
35 | install_requires=[
36 | 'pybind11',
37 | 'matplotlib',
38 | 'numpy',
39 | 'pyopencl'
40 | ],
41 | zip_safe=False)
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 | *.pyc
6 |
7 | # C extensions
8 | *.so
9 |
10 | # Distribution / packaging
11 | .Python
12 | env/
13 | build/
14 | develop-eggs/
15 | dist/
16 | downloads/
17 | eggs/
18 | .eggs/
19 | lib/
20 | lib64/
21 | parts/
22 | sdist/
23 | var/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *,cover
47 | .hypothesis/
48 |
49 | # Translations
50 | *.mo
51 | *.pot
52 |
53 | # Django stuff:
54 | *.log
55 | local_settings.py
56 |
57 | # Flask stuff:
58 | instance/
59 | .webassets-cache
60 |
61 | # Scrapy stuff:
62 | .scrapy
63 |
64 | # Sphinx documentation
65 | docs/_build/
66 |
67 | # PyBuilder
68 | target/
69 |
70 | # IPython Notebook
71 | .ipynb_checkpoints
72 |
73 | # pyenv
74 | .python-version
75 |
76 | # celery beat schedule file
77 | celerybeat-schedule
78 |
79 | # dotenv
80 | .env
81 |
82 | # virtualenv
83 | .venv/
84 | venv/
85 | ENV/
86 |
87 | # Spyder project settings
88 | .spyderproject
89 |
90 | # Rope project settings
91 | .ropeproject
92 |
93 | # OpenCLGA tmp files
94 | final.cl
95 |
96 | # mac ds store
97 | .DS_Store
98 |
--------------------------------------------------------------------------------
/OpenCLGA/ui/index.html:
--------------------------------------------------------------------------------
1 |
OpenCLGA UI
--------------------------------------------------------------------------------
/examples/taiwan_travel/ui/index.html:
--------------------------------------------------------------------------------
1 | OpenCLGA UI
--------------------------------------------------------------------------------
/OpenCLGA/evaluation/type_casting/casting.py:
--------------------------------------------------------------------------------
1 | import pyopencl as cl
2 | import numpy as np
3 |
4 | def run(vector):
5 | ctx = cl.create_some_context()
6 | queue = cl.CommandQueue(ctx, properties=cl.command_queue_properties.PROFILING_ENABLE)
7 | f = open('casting_vector.c' if vector else 'casting.c', 'r')
8 | fstr = ''.join(f.readlines())
9 | f.close()
10 |
11 | data_size = 100;
12 | global_size = int(data_size / 4) if vector else data_size
13 |
14 | if vector:
15 | struct = 'typedef struct {\n'
16 | code = ' switch(id) {\n'
17 | codeTemp = ' case {0}:\n tsR->data{0} = tsA->data{0} + tsB->data{0};\n break;\n'
18 | for i in range(global_size):
19 | struct += ' float4 data' + str(i) + ';\n'
20 | code += codeTemp.format(i)
21 | struct += '} TypedStruct2;\n'
22 | code += ' }\n'
23 | fstr = fstr.replace('%code_generation%', code);
24 | fstr = '#define GLOBAL_SIZE ' + str(global_size) + '\n' + struct + fstr
25 | else:
26 | fstr = '#define GLOBAL_SIZE ' + str(global_size) + '\n' + fstr;
27 |
28 | print('=' * 50)
29 | print(fstr)
30 | print('-' * 50)
31 |
32 | a_np = np.random.rand(data_size).astype(np.float32)
33 | b_np = np.random.rand(data_size).astype(np.float32)
34 |
35 | mf = cl.mem_flags
36 | a_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a_np)
37 | b_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b_np)
38 |
39 | res_g = cl.Buffer(ctx, mf.WRITE_ONLY, a_np.nbytes)
40 |
41 | prg = cl.Program(ctx, fstr).build();
42 | exec_evt = prg.casting_test(queue, (global_size,), None, a_g, b_g, res_g)
43 | exec_evt.wait()
44 |
45 | res_np = np.empty_like(a_np)
46 | cl.enqueue_copy(queue, res_np, res_g).wait()
47 | print(res_np)
48 |
49 | elapsed = 1e-9 * (exec_evt.profile.end - exec_evt.profile.start)
50 | print('Vector: {0} => Execution time of test: {1}s'.format(vector, elapsed))
51 |
52 | if __name__ == '__main__':
53 | run(False)
54 | run(True)
55 |
--------------------------------------------------------------------------------
/OpenCLGA/utilities/httpwebsocketserver/ExampleWSServer.py:
--------------------------------------------------------------------------------
1 | #main program and imports for standalone purpose
2 | import sys
3 | import threading
4 | import ssl
5 | from base64 import b64encode
6 |
7 | VER = sys.version_info[0]
8 | if VER >= 3:
9 | from socketserver import ThreadingMixIn
10 | from http.server import HTTPServer
11 | from io import StringIO
12 | else:
13 | from SocketServer import ThreadingMixIn
14 | from BaseHTTPServer import HTTPServer
15 | from StringIO import StringIO
16 |
17 | from HTTPWebSocketsHandler import HTTPWebSocketsHandler
18 |
19 | if len(sys.argv) > 1:
20 | port = int(sys.argv[1])
21 | else:
22 | port = 8000
23 | if len(sys.argv) > 2:
24 | secure = str(sys.argv[2]).lower()=='secure'
25 | else:
26 | secure = False
27 | if len(sys.argv) > 3:
28 | credentials = str(sys.argv[3])
29 | else:
30 | credentials = ''
31 |
32 | class WSSimpleEcho(HTTPWebSocketsHandler):
33 | def on_ws_message(self, message):
34 | if message is None:
35 | message = ''
36 | # echo message back to client
37 | self.send_message(message)
38 | self.log_message('websocket received '%s'',str(message))
39 |
40 | def on_ws_connected(self):
41 | self.log_message('%s','websocket connected')
42 |
43 | def on_ws_closed(self):
44 | self.log_message('%s','websocket closed')
45 |
46 | class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
47 | '''Handle requests in a separate thread.'''
48 |
49 | def _ws_main():
50 | try:
51 | #Replace WSSimpleEcho with your own subclass of HTTPWebSocketHandler
52 | server = ThreadedHTTPServer(('', port), WSSimpleEcho)
53 | server.daemon_threads = True
54 | server.auth = b64encode(credentials.encode('ascii'))
55 | if secure:
56 | server.socket = ssl.wrap_socket (server.socket, certfile='./server.pem', server_side=True)
57 | print('started secure https server at port %d' % (port,))
58 | else:
59 | print('started http server at port %d' % (port,))
60 | server.serve_forever()
61 | except KeyboardInterrupt:
62 | print('^C received, shutting down server')
63 | server.socket.close()
64 |
65 | if __name__ == '__main__':
66 | _ws_main()
67 |
--------------------------------------------------------------------------------
/OpenCLGA/evaluation/memory_usage/test_local.c:
--------------------------------------------------------------------------------
1 |
2 | #define LM_SIZE 8192
3 |
4 | __kernel void test(int size, global int* in, global int* out)
5 | {
6 | int2 globalId = (int2)(get_global_id(0), get_global_id(1));
7 | int2 localId = (int2)(get_local_id(0), get_local_id(1));
8 | int2 groupId = (int2)(get_group_id (0), get_group_id (1));
9 | int2 globalSize = (int2)(get_global_size(0), get_global_size(1));
10 | int2 locallSize = (int2)(get_local_size(0), get_local_size(1));
11 | if (globalId.x + globalId.y * globalSize.x >= size) {
12 | return;
13 | }
14 |
15 | int gIdx = globalId.x + globalId.y * globalSize.x;
16 | /*
17 | * Device local memory size can be queired from
18 | import pyopencl as cl
19 | cl.Kernel.get_work_group_info(cl.kernel_work_group_info.LOCAL_MEM_SIZE, cl.Device)
20 | */
21 |
22 | // The local memory usage will be 4*LM_SIZE bytes.
23 | // You may adjust LM_SIZE to test if OUT OF RESOURCES while compiling.
24 | __local int lv[LM_SIZE];
25 | int lIdx = gIdx % LM_SIZE;
26 | lv[lIdx] = globalId.y + globalId.x * globalSize.y;
27 |
28 | /*
29 | * On Intel CPU, 128 bytes private memory is used for the barrier below.
30 | */
31 | // barrier(CLK_LOCAL_MEM_FENCE);
32 | out[gIdx] = lv[lIdx] - gIdx;
33 | }
34 |
35 | __kernel void test_input(int size, global int* in, global int* out, local int* lv, int lv_size)
36 | {
37 | int2 globalId = (int2)(get_global_id(0), get_global_id(1));
38 | int2 localId = (int2)(get_local_id(0), get_local_id(1));
39 | int2 groupId = (int2)(get_group_id (0), get_group_id (1));
40 | int2 globalSize = (int2)(get_global_size(0), get_global_size(1));
41 | int2 locallSize = (int2)(get_local_size(0), get_local_size(1));
42 | if (globalId.x + globalId.y * globalSize.x >= size) {
43 | return;
44 | }
45 |
46 | int gIdx = globalId.x + globalId.y * globalSize.x;
47 | /*
48 | * Device local memory size can be queired from
49 | import pyopencl as cl
50 | cl.Kernel.get_work_group_info(cl.kernel_work_group_info.LOCAL_MEM_SIZE, cl.Device)
51 | */
52 |
53 | // The local memory usage will be 4*LM_SIZE bytes.
54 | // You may adjust LM_SIZE to test if OUT OF RESOURCES while compiling.
55 | int lIdx = gIdx % lv_size;
56 | lv[lIdx] = globalId.y + globalId.x * globalSize.y;
57 | if (lIdx >= 512) {
58 | lv[lIdx] -= 128;
59 | }
60 | /*
61 | * On Intel CPU, 128 bytes private memory is used for the barrier below.
62 | */
63 | // barrier(CLK_LOCAL_MEM_FENCE);
64 | out[gIdx] = lv[lIdx] - gIdx;
65 | }
66 |
--------------------------------------------------------------------------------
/examples/scheduling - power station/power.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | import os
3 | import random
4 | from OpenCLGA import SimpleGene, SimpleChromosome, utils, OpenCLGA
5 |
6 | def show_generation_info(index, data_dict):
7 | print('{0}\t\t==> {1}'.format(index, data_dict['best']))
8 |
9 | def run(num_chromosomes, generations):
10 | random.seed()
11 |
12 | type1 = ['q12', 'q23', 'q34', 'q41']
13 | type2 = ['q1', 'q2', 'q3', 'q4']
14 |
15 | sample = SimpleChromosome([SimpleGene('q12', type1, 'unit-1'),
16 | SimpleGene('q12', type1, 'unit-2'),
17 | SimpleGene('q1', type2, 'unit-3'),
18 | SimpleGene('q1', type2, 'unit-4'),
19 | SimpleGene('q1', type2, 'unit-5'),
20 | SimpleGene('q1', type2, 'unit-6'),
21 | SimpleGene('q1', type2, 'unit-7')])
22 |
23 | self_path = os.path.dirname(os.path.abspath(__file__))
24 | f = open(os.path.join(self_path, 'power.cl'), 'r')
25 | fstr = ''.join(f.readlines())
26 | f.close()
27 |
28 | import threading
29 | evt = threading.Event()
30 | evt.clear()
31 | def state_changed(state):
32 | if 'stopped' == state:
33 | evt.set()
34 |
35 | ga_cl = OpenCLGA({'sample_chromosome': sample,
36 | 'termination': {
37 | 'type': 'count',
38 | 'count': generations
39 | },
40 | 'population': num_chromosomes,
41 | 'fitness_kernel_str': fstr,
42 | 'fitness_func': 'power_station_fitness',
43 | 'opt_for_max': 'max',
44 | 'debug': True,
45 | 'generation_callback': show_generation_info},
46 | action_callbacks = {'state' : state_changed})
47 |
48 | ga_cl.prepare()
49 |
50 | prob_mutate = 0.05
51 | prob_cross = 0.8
52 | ga_cl.run(prob_mutate, prob_cross)
53 | evt.wait()
54 |
55 | utils.plot_ga_result(ga_cl.get_statistics())
56 | print('run took', ga_cl.elapsed_time, 'seconds')
57 | best_chromosome, best_fitness, best_info = ga_cl.get_the_best()
58 | print('Best Fitness: %f'%(best_fitness))
59 | print('1 ~ 7 units are maintained at: ' + ', '.join(str(g.dna) for g in best_info.genes))
60 |
61 | if __name__ == '__main__':
62 | run(num_chromosomes=50, generations=100)
63 |
--------------------------------------------------------------------------------
/examples/tsp/simple_tsp.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | import os
3 | import random
4 | from OpenCLGA import SimpleGene, ShufflerChromosome, utils, OpenCLGA
5 |
6 | def show_generation_info(index, data_dict):
7 | print('{0}\t\t==> {1}'.format(index, data_dict['best']))
8 |
9 | def run(num_chromosomes, generations):
10 | num_cities = 20
11 | random.seed()
12 | city_ids = list(range(0, num_cities))
13 | city_info = {city_id: (random.random() * 100, random.random() * 100) for city_id in city_ids}
14 |
15 | sample = ShufflerChromosome([SimpleGene(v, city_ids) for v in city_ids])
16 |
17 | tsp_path = os.path.dirname(os.path.abspath(__file__))
18 | tsp_kernels = os.path.join(tsp_path, 'kernel')
19 |
20 | f = open(os.path.join(tsp_kernels, 'simple_tsp.cl'), 'r')
21 | fstr = ''.join(f.readlines())
22 | f.close()
23 |
24 | pointX = [str(city_info[v][0]) for v in city_info];
25 | pointY = [str(city_info[v][1]) for v in city_info]
26 |
27 | import threading
28 | evt = threading.Event()
29 | evt.clear()
30 | def state_changed(state):
31 | if 'stopped' == state:
32 | evt.set()
33 |
34 | tsp_ga_cl = OpenCLGA({'sample_chromosome': sample,
35 | 'termination': {
36 | 'type': 'count',
37 | 'count': generations
38 | },
39 | 'population': num_chromosomes,
40 | 'fitness_kernel_str': fstr,
41 | 'fitness_func': 'simple_tsp_fitness',
42 | 'fitness_args': [{'t': 'float', 'v': pointX, 'n': 'x'},
43 | {'t': 'float', 'v': pointY, 'n': 'y'}],
44 | 'opt_for_max': 'min',
45 | 'debug': True,
46 | 'generation_callback': show_generation_info},
47 | action_callbacks = {'state' : state_changed})
48 |
49 | tsp_ga_cl.prepare()
50 |
51 | prob_mutate = 0.1
52 | prob_cross = 0.8
53 | tsp_ga_cl.run(prob_mutate, prob_cross)
54 | evt.wait()
55 |
56 | utils.plot_ga_result(tsp_ga_cl.get_statistics())
57 | print('run took', tsp_ga_cl.elapsed_time, 'seconds')
58 | best_chromosome, best_fitness, best_info = tsp_ga_cl.get_the_best()
59 | print('Best Fitness: %f'%(best_fitness))
60 | print('Shortest Path: ' + ' => '.join(str(g) for g in best_chromosome))
61 | utils.plot_tsp_result(city_info, best_chromosome)
62 |
63 | if __name__ == '__main__':
64 | run(num_chromosomes=4000, generations=1000)
65 |
--------------------------------------------------------------------------------
/examples/grouping/grouping.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | import os
3 | import random
4 | from OpenCLGA import SimpleGene, SimpleChromosome, ShufflerChromosome, utils, OpenCLGA
5 |
6 | def show_generation_info(index, data_dict):
7 | print('{0}\t\t==> {1}'.format(index, data_dict['best']))
8 |
9 | def run(num_chromosomes, generations):
10 | random.seed()
11 |
12 | # The number of points randomly generated
13 | num_points = 100
14 | random.seed()
15 | point_ids = list(range(0, num_points))
16 | point_info = {point_id: (random.random() * 100, random.random() * 100) for point_id in point_ids}
17 | pointX = [str(point_info[v][0]) for v in point_info];
18 | pointY = [str(point_info[v][1]) for v in point_info]
19 |
20 | # The number of group you want to divide.
21 | numOfGroups = 10
22 | group_id_set = list(range(0, numOfGroups))
23 | group_ids = [random.randint(0,numOfGroups-1) for x in range(num_points)]
24 |
25 | sample = SimpleChromosome([SimpleGene(groupd_id, group_id_set) for groupd_id in group_ids])
26 |
27 | self_path = os.path.dirname(os.path.abspath(__file__))
28 | f = open(os.path.join(self_path, 'grouping.cl'), 'r')
29 | fstr = ''.join(f.readlines())
30 | f.close()
31 |
32 | import threading
33 | evt = threading.Event()
34 | evt.clear()
35 | def state_changed(state):
36 | if 'stopped' == state:
37 | evt.set()
38 |
39 | ga_cl = OpenCLGA({'sample_chromosome': sample,
40 | 'termination': { 'type': 'count',
41 | 'count': generations },
42 | 'population': num_chromosomes,
43 | 'fitness_kernel_str': fstr,
44 | 'fitness_func': 'grouping_fitness',
45 | 'fitness_args': [{'t': 'int', 'v': numOfGroups, 'n': 'numOfGroups'},
46 | {'t': 'float', 'v': pointX, 'n': 'x'},
47 | {'t': 'float', 'v': pointY, 'n': 'y'}],
48 | 'opt_for_max': 'min',
49 | 'debug': True,
50 | 'generation_callback': show_generation_info},
51 | action_callbacks = {'state' : state_changed})
52 |
53 | ga_cl.prepare()
54 |
55 | prob_mutate = 0.1
56 | prob_cross = 0.8
57 | ga_cl.run(prob_mutate, prob_cross)
58 | evt.wait()
59 |
60 | print('run took', ga_cl.elapsed_time, 'seconds')
61 | best_chromosome, best_fitness, best_info = ga_cl.get_the_best()
62 | print(best_chromosome)
63 | utils.plot_grouping_result(group_id_set, best_chromosome, point_info)
64 |
65 | if __name__ == '__main__':
66 | run(num_chromosomes=2000, generations=2000)
67 |
--------------------------------------------------------------------------------
/OpenCLGA/simple_gene.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | import random
3 | HUMAN_DNA_ELEMENTS = ['A','C','G','T']
4 |
5 | class SimpleGene:
6 |
7 | @staticmethod
8 | def clone_gene(g):
9 | # Clone a new gene containing the same dna symbol in g.
10 | return SimpleGene(g.dna, g.elements, g.name)
11 |
12 | # SimpleGene - is a Gene with only one DNA element.
13 | # dna - a single element picked from elements.
14 | # elements - a set of element which is the basic component of dna.
15 | def __init__(self, dna, elements=HUMAN_DNA_ELEMENTS, name=''):
16 | assert dna is not None
17 | assert type(elements) == list
18 | self.__elements = elements
19 | self.__name = name
20 | self.dna = dna
21 |
22 | @property
23 | def dna(self):
24 | return self.__dna
25 |
26 | @dna.setter
27 | def dna(self, dna):
28 | assert dna is not None
29 | self.__dna = dna
30 |
31 | @property
32 | def dna_in_kernel(self):
33 | return self._elements.index(self.dna)
34 |
35 | @property
36 | def length(self):
37 | # SimpleGene is designed to be only 1 dna element inside.
38 | return 1
39 |
40 | @property
41 | def name(self):
42 | # The name of this SimpleGene
43 | return self.__name
44 |
45 | @property
46 | def elements(self):
47 | # The list of dna elements.
48 | return self.__elements
49 |
50 | @property
51 | def elements_in_kernel(self):
52 | return list(range(0, len(self.__elements)))
53 |
54 | @property
55 | def kernel_file(self):
56 | # Kernel file which contains related operating functions for SimpleGene,
57 | # i.e. simple_gene_mutate()
58 | return 'simple_gene.cl'
59 |
60 | @property
61 | def elements_length(self):
62 | # The elements size of this SimpleGene.
63 | # Could be considered as the problem space represented by this SimpleGene.
64 | return len(self.__elements)
65 |
66 | @property
67 | def mutate_func_name(self):
68 | # Chromosome can use this function to execute built-in mutate function which choose an
69 | # excluded elments randomly.
70 | return 'simple_gene_mutate'
71 |
72 | @property
73 | def elements_in_kernel_str(self):
74 | # Chromosome can use this function to declare elements array
75 | elements_str = ', '.join([str(v) for v in self.elements_in_kernel])
76 | return '{' + elements_str + '}\n'
77 |
78 | def from_kernel_value(self, v):
79 | # Construct a SimpleGene object on system memory according to
80 | # the calculated index values 'v' on opencl(device) memory.
81 | assert 0 <= v < len(self.__elements)
82 | return SimpleGene(self.__elements[v], self.__elements, self.__name)
83 |
--------------------------------------------------------------------------------
/OpenCLGA/utilities/httpwebsocketserver/websocket.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | WebSocket Test
6 |
7 |
86 |
87 |
88 |
89 |
108 |