Skip to content
Snippets Groups Projects
Commit 2f5711a4 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Add cl.enable_debugging()

parent 4d3cf9be
No related branches found
No related tags found
No related merge requests found
...@@ -61,8 +61,46 @@ def compiler_output(text): ...@@ -61,8 +61,46 @@ def compiler_output(text):
"to see more.", CompilerWarning) "to see more.", CompilerWarning)
# {{{ find pyopencl shipped source code
def _find_pyopencl_include_path():
from pkg_resources import Requirement, resource_filename
return resource_filename(Requirement.parse("pyopencl"), "pyopencl/cl")
# }}}
# {{{ Program (including caching support) # {{{ Program (including caching support)
_DEFAULT_BUILD_OPTIONS = []
_DEFAULT_INCLUDE_OPTIONS = ["-I", _find_pyopencl_include_path()]
# map of platform.name to build options list
_PLAT_BUILD_OPTIONS = {}
def enable_debugging(platform_or_context):
"""Enables debugging for all code subsequently compiled by
PyOpenCL on the passed *platform*. Alternatively, a context
may be passed.
"""
if isinstance(platform_or_context, Context):
platform = platform_or_context.devices[0].platform
else:
platform = platform_or_context
if "AMD Accelerated" in platform.name:
_PLAT_BUILD_OPTIONS.setdefault(platform.name, []).extend(
["-g", "-O0"])
import os
os.environ["CPU_MAX_COMPUTE_UNITS"] = "1"
else:
from warnings import warn
warn("do not know how to enable debugging on '%s'"
% platform.name)
class Program(object): class Program(object):
def __init__(self, arg1, arg2=None, arg3=None): def __init__(self, arg1, arg2=None, arg3=None):
if arg2 is None: if arg2 is None:
...@@ -138,7 +176,11 @@ class Program(object): ...@@ -138,7 +176,11 @@ class Program(object):
if isinstance(options, str): if isinstance(options, str):
options = [options] options = [options]
options = options + ["-I", _find_pyopencl_include_path()] options = (options
+ _DEFAULT_BUILD_OPTIONS
+ _DEFAULT_INCLUDE_OPTIONS
+ _PLAT_BUILD_OPTIONS.get(
self._context.devices[0].platform.name, []))
import os import os
forced_options = os.environ.get("PYOPENCL_BUILD_OPTIONS") forced_options = os.environ.get("PYOPENCL_BUILD_OPTIONS")
...@@ -716,15 +758,6 @@ def _add_functionality(): ...@@ -716,15 +758,6 @@ def _add_functionality():
_add_functionality() _add_functionality()
# {{{ find pyopencl shipped source code
def _find_pyopencl_include_path():
from pkg_resources import Requirement, resource_filename
return resource_filename(Requirement.parse("pyopencl"), "pyopencl/cl")
# }}}
# {{{ convenience # {{{ convenience
def create_some_context(interactive=True, answers=None): def create_some_context(interactive=True, answers=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment