Skip to content

Commit

Permalink
Add compatability wrapper for pyopencl.
Browse files Browse the repository at this point in the history
This fixes pyopencl caching when executing in a bazel sandbox.

github.com//issues/65
  • Loading branch information
ChrisCummins committed Jan 2, 2020
1 parent e73c5ea commit 34cade5
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion datasets/benchmarks/jacobi_opencl/jacobi_opencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import typing

import numpy as np
import pyopencl as CL

from labm8.py import app
from third_party.py.pyopencl import pyopencl as CL

FLAGS = app.FLAGS

Expand Down
6 changes: 3 additions & 3 deletions experimental/dsmith/opencl/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def __repr__(self) -> str:

def platform_id(self):
""" return OpenCL platform index, or KeyError if platform not found """
import pyopencl as cl
from third_party.py.pyopencl import pyopencl as cl

for i, platform in enumerate(cl.get_platforms()):
if platform.get_info(cl.platform_info.NAME) == self.platform:
Expand All @@ -612,7 +612,7 @@ def platform_id(self):

def device_id(self):
""" return OpenCL device index, or KeyError if device not found """
import pyopencl as cl
from third_party.py.pyopencl import pyopencl as cl

platform = cl.get_platforms()[self.platform_id()]
ctx = cl.Context(properties=[(cl.context_properties.PLATFORM, platform)])
Expand Down Expand Up @@ -700,7 +700,7 @@ def from_env(

@staticmethod
def _get_ids(platform: str, device: str, driver: str) -> Tuple[int, int]:
import pyopencl as cl
from third_party.py.pyopencl import pyopencl as cl

# match platform ID:
for j, cl_platform in enumerate(cl.get_platforms()):
Expand Down
3 changes: 2 additions & 1 deletion experimental/dsmith/scrapheap/clgen_run_cl_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
from typing import Tuple

import progressbar
import pyopencl as cl
from dsmith import clsmith
from dsmith import db
from dsmith.db import *
from dsmith.lib import *

from third_party.py.pyopencl import pyopencl as cl


def get_platform_name(platform_id):
platform = cl.get_platforms()[platform_id]
Expand Down
2 changes: 1 addition & 1 deletion experimental/dsmith/scrapheap/clsmith_run_cl_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from typing import Tuple

import progressbar
import pyopencl as cl
from dsmith import clsmith
from dsmith import db
from dsmith.db import *
from dsmith.lib import *

from labm8.py import crypto
from third_party.py.pyopencl import pyopencl as cl


def get_platform_name(platform_id):
Expand Down
3 changes: 2 additions & 1 deletion experimental/dsmith/scrapheap/run_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from itertools import product
from subprocess import Popen

import pyopencl as cl
from dsmith import db
from dsmith.db import *

from third_party.py.pyopencl import pyopencl as cl


def get_platform_name(platform_id):
platform = cl.get_platforms()[platform_id]
Expand Down
2 changes: 1 addition & 1 deletion experimental/dsmith/scrapheap/run_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from collections import namedtuple
from typing import NewType

import pyopencl as cl
from dsmith.db import *
from dsmith.lib import *

from labm8.py import fs
from third_party.py.pyopencl import pyopencl as cl

# paths to clreduce library
CLREDUCE_DIR = fs.abspath("..", "lib", "clreduce")
Expand Down
3 changes: 1 addition & 2 deletions experimental/quicksilver/jacobi_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@
"""
import time

import pyopencl as CL

from datasets.benchmarks.jacobi_opencl import jacobi_opencl as jacobi
from labm8.py import app
from labm8.py import humanize
from labm8.py import prof
from third_party.py.pyopencl import pyopencl as CL

FLAGS = app.FLAGS

Expand Down
2 changes: 1 addition & 1 deletion gpu/omnitune/omnitune/opencl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyopencl as cl
from third_party.py.pyopencl import pyopencl as cl


def get_devices():
Expand Down
3 changes: 2 additions & 1 deletion third_party/py/pyopencl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ licenses(["notice"]) # MIT

py_library(
name = "pyopencl",
srcs = ["//third_party/py:empty.py"],
srcs = ["pyopencl.py"],
deps = [
requirement("pyopencl"),
requirement("pytools"), # Implicit dependency.
],
)
15 changes: 15 additions & 0 deletions third_party/py/pyopencl/pyopencl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""pyopencl module shim.
This is a drop-in replacement for pyopencl that enables support for execution
inside of bazel sandboxing.
"""
import os

# Switch out the default value for ~/.cache on Linux when executing in
# bazel sandbox. See:
# https://docs.bazel.build/versions/master/test-encyclopedia.html#initial-conditions
_BAZEL_TEST_TMPDIR = os.environ.get("TEST_TMPDIR")
if _BAZEL_TEST_TMPDIR:
os.environ["XDG_CACHE_HOME"] = _BAZEL_TEST_TMPDIR

from pyopencl import *

0 comments on commit 34cade5

Please sign in to comment.