|
1 | 1 | import os
|
2 | 2 | import sys
|
| 3 | + |
3 | 4 | import numpy as np
|
4 | 5 | import pyopencl as cl
|
5 | 6 | from pyopencl import characterize
|
6 | 7 | from pyopencl import array
|
7 |
| -from functools import lru_cache |
8 | 8 | from ._device import get_device
|
9 | 9 |
|
10 | 10 | """ Below here, vendored from GPUtools
|
|
38 | 38 | """
|
39 | 39 |
|
40 | 40 |
|
41 |
| -class OCLProgram(cl.Program): |
42 |
| - """ a wrapper class representing a CPU/GPU Program |
43 |
| - example: |
44 |
| - prog = OCLProgram("mykernels.cl",build_options=["-D FLAG"]) |
45 |
| - """ |
46 |
| - _wait_for_kernel_finish = None |
47 |
| - |
48 |
| - def __init__(self, file_name=None, src_str=None, build_options=[], dev=None): |
49 |
| - if file_name is not None: |
50 |
| - with open(file_name, "r") as f: |
51 |
| - src_str = f.read() |
52 |
| - |
53 |
| - if src_str is None: |
54 |
| - raise ValueError("empty src_str! ") |
55 |
| - |
56 |
| - if dev is None: |
57 |
| - dev = get_device() |
58 | 41 |
|
59 |
| - self._dev = dev |
60 |
| - self._kernel_dict = {} |
61 |
| - super().__init__(self._dev.context, src_str) |
62 |
| - self.build(options=build_options) |
63 |
| - |
64 |
| - def run_kernel(self, name, global_size, local_size, *args, **kwargs): |
65 |
| - if name not in self._kernel_dict: |
66 |
| - self._kernel_dict[name] = getattr(self, name) |
67 |
| - |
68 |
| - self._kernel_dict[name]( |
69 |
| - self._dev.queue, global_size, local_size, *args, **kwargs |
70 |
| - ) |
71 |
| - if OCLProgram._wait_for_kernel_finish: |
72 |
| - self._dev.queue.finish() |
73 |
| - |
74 |
| - @classmethod |
75 |
| - @lru_cache(maxsize=128) |
76 |
| - def from_source(cls, source): |
77 |
| - return cls(src_str=source) |
78 | 42 |
|
79 | 43 |
|
80 | 44 | cl_image_datatype_dict = {
|
|
0 commit comments