summaryrefslogtreecommitdiff
path: root/silx/opencl/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/opencl/utils.py')
-rw-r--r--silx/opencl/utils.py71
1 files changed, 40 insertions, 31 deletions
diff --git a/silx/opencl/utils.py b/silx/opencl/utils.py
index 58becb0..f558c1b 100644
--- a/silx/opencl/utils.py
+++ b/silx/opencl/utils.py
@@ -1,30 +1,30 @@
-#!/usr/bin/env python
# -*- coding: utf-8 -*-
+# /*##########################################################################
+# Copyright (C) 2017 European Synchrotron Radiation Facility
#
-# Project: Sift implementation in Python + OpenCL
-# https://github.com/silx-kit/silx
+# 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:
#
-# 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 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.
#
-# 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.
-
+# ############################################################################*/
+"""
+Project: Sift implementation in Python + OpenCL
+ https://github.com/silx-kit/silx
+"""
from __future__ import division
@@ -32,12 +32,12 @@ __authors__ = ["Jérôme Kieffer", "Pierre Paleo"]
__contact__ = "jerome.kieffer@esrf.eu"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
-__date__ = "15/03/2017"
-__status__ = "Production"
+__date__ = "06/09/2017"
+__status__ = "Production"
import os
import numpy
-from ..resources import resource_filename
+from .. import resources
from math import log, ceil
@@ -77,14 +77,22 @@ def sizeof(shape, dtype="uint8"):
return cnt * itemsize
-def get_cl_file(filename):
- """get the full path of a openCL file
+def get_cl_file(resource):
+ """get the full path of a openCL resource file
+
+ The resource name can be prefixed by the name of a resource directory. For
+ example "silx:foo.png" identify the resource "foo.png" from the resource
+ directory "silx".
+ See also :func:`silx.resources.register_resource_directory`.
+ :param str resource: Resource name. File name contained if the `opencl`
+ directory of the resources.
:return: the full path of the openCL source file
"""
- if not filename.endswith(".cl"):
- filename += ".cl"
- return resource_filename(os.path.join("opencl", filename))
+ if not resource.endswith(".cl"):
+ resource += ".cl"
+ return resources._resource_filename(resource,
+ default_directory="opencl")
def read_cl_file(filename):
@@ -97,6 +105,7 @@ def read_cl_file(filename):
lines = [i for i in f.readlines() if not i.startswith("#include ")]
return "".join(lines)
+
get_opencl_code = read_cl_file
@@ -109,4 +118,4 @@ def concatenate_cl_kernel(filenames):
this method concatenates all the kernel from the list
"""
- return os.linesep.join(read_cl_file(fn) for fn in filenames)
+ return os.linesep.join(read_cl_file(fn) for fn in filenames)