def Exec(opencl_environment: env.OpenCLEnvironment, *opts, timeout_seconds: int = 60, env: typing.Dict[str, str] = None) -> subprocess.Popen: """Execute cl_launcher. This creates a Popen process, executes it, and sets the stdout and stderr attributes to the process output. Args: opencl_environment: The OpenCL environment to execute cl_launcher with. opts: A list of arguments to pass to the cl_launcher binary. timeout_seconds: The maximum number of seconds to execute cl_launcher for. env: An optional environment to run cl_launcher under. Returns: A Popen instance, with string stdout and stderr attributes set. """ if system.is_linux(): env = env or {} env['LD_PRELOAD'] = PrependToPath(str(LIBOPENCL_SO), env.get('LD_PRELOAD')) with fs.TemporaryWorkingDir(prefix='cl_launcher_') as d: for src in CL_LAUNCHER_RUN_FILES: os.symlink(src, str(d / src.name)) cmd = ['timeout', '-s9', str(timeout_seconds), str(CL_LAUNCHER), '-i', str(d)] + list(opts) process = opencl_environment.Exec(cmd, env=env) return process
def test_OpenClDeviceMappingsDataset_cfgs_df_count( opencl_dataset: datasets.OpenClDeviceMappingsDataset): """Test that dataset has expected number of rows.""" # The clang binaries used by Linux and macOS produce slightly different # results. if system.is_linux(): assert len(opencl_dataset.cfgs_df) == 191 else: assert len(opencl_dataset.cfgs_df) == 189
def gpuverify(src: str, args: list, id: str = 'anon', timeout: int = 60) -> str: """ Run GPUverify over kernel. Parameters ---------- src : str OpenCL source. id : str, optional OpenCL source name. Returns ------- str OpenCL source. Raises ------ GPUVerifyException If GPUverify finds a bug. InternalError If GPUverify fails. """ # FIXME: GPUVerify support on macOS. from labm8 import system if not system.is_linux(): raise clgen.InternalError("GPUVerify only supported on Linux!") # GPUverify can't read from stdin. with NamedTemporaryFile('w', suffix='.cl') as tmp: tmp.write(src) tmp.flush() cmd = ['timeout', '-s9', str(timeout), native.GPUVERIFY, tmp.name] + args process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() if process.returncode == -9: # timeout signal raise GPUVerifyTimeoutException( f"GPUveryify failed to complete with {timeout} seconds") elif process.returncode != 0: raise GPUVerifyException(stderr.decode('utf-8')) return src
import typing from absl import app from absl import flags from absl import logging from compilers.llvm import llvm from labm8 import bazelutil from labm8 import system FLAGS = flags.FLAGS flags.DEFINE_integer('opt_timeout_seconds', 60, 'The maximum number of seconds to allow process to run.') _LLVM_REPO = 'llvm_linux' if system.is_linux() else 'llvm_mac' # Path to opt binary. OPT = bazelutil.DataPath(f'{_LLVM_REPO}/bin/opt') # The list of LLVM opt transformation passes. # See: https://llvm.org/docs/Passes.html#transform-passes TRANSFORM_PASSES = { '-aa', '-aa-eval', '-aarch64-a57-fp-load-balancing', '-aarch64-ccmp', '-aarch64-collect-loh', '-aarch64-condopt', '-aarch64-copyelim', '-aarch64-dead-defs',
import pytest from experimental import dsmith from labm8 import fs from labm8 import system from labm8 import tar class Data404(Exception): pass # test decorators needs_cuda = pytest.mark.skipif(not dsmith.USE_CUDA, reason="no CUDA support") needs_linux = pytest.mark.skipif(not system.is_linux(), reason="not linux") skip_on_travis = pytest.mark.skipif(os.environ.get("TRAVIS") == 'true', reason="skip on Travis CI") def data_path(*components, exists=True) -> str: """ Return absolute path to unittest data file. Data files are located in <package>/test/data. Arguments: *components (str): Relative path. exists (bool, optional): If True, require that file exists. Returns: str: Absolute path.
bazel run //gpu/oclgrind [-- -- <args>] """ import subprocess import sys import typing from absl import app from absl import flags from gpu.clinfo.proto import clinfo_pb2 from labm8 import bazelutil from labm8 import system FLAGS = flags.FLAGS _OCLGRIND_PKG = 'oclgrind_linux' if system.is_linux() else 'oclgrind_mac' # The path to the oclgrind binary. OCLGRIND_PATH = bazelutil.DataPath(f'{_OCLGRIND_PKG}/bin/oclgrind') # The clinfo description of the local Oclgrind binary. CLINFO_DESCRIPTION = clinfo_pb2.OpenClDevice( name='Emulator|Oclgrind|Oclgrind_Simulator|Oclgrind_18.3|1.2', platform_name='Oclgrind', device_name='Oclgrind Simulator', driver_version='Oclgrind 18.3', opencl_version='1.2', device_type='Emulator', platform_id=0, device_id=0, )
def CompileDriver(src: str, output_path: pathlib.Path, platform_id: int, device_id: int, timeout_seconds: int = 60, cflags: typing.List[str] = None) -> pathlib.Path: """Compile driver binary from source. Args: src: The C source code to compile. output_path: The path to the binary to generate. platform_id: The OpenCL platform ID. device_id: The OpenCL device ID. timeout_seconds: The number of seconds to allow for compilation. Returns: The path to the generated binary, same as output_path. Raises: DriverCompilationError: In case compilation fails. """ cmd = [ 'timeout', '-s9', str(timeout_seconds), str(CLANG_PATH), '-xc', '-', '-o', str(output_path), f'-DPLATFORM_ID={platform_id}', f'-DDEVICE_ID={device_id}', '-ferror-limit=1', '-std=c99', '-Wno-deprecated-declarations', # Add OpenCL headers. '-isystem', str(OPENCL_HEADERS_DIR), # Link against libcxx. f'-L{LIBCXX_LIB_DIR}', f'-Wl,-rpath,{LIBCXX_LIB_DIR}', '-nodefaultlibs', '-stdlib=libc++', '-lc++', '-lc++abi', '-lm', '-lc', ] if system.is_linux(): cmd += [ # Additional libraries required to link against libcxxx. '-lgcc_s', '-lgcc', '-ldl', '-lpthread', # Link against libOpenCL. f'-L{LIBOPENCL_DIR}', f'-Wl,-rpath,{LIBOPENCL_DIR}', '-lOpenCL' ] elif system.is_mac(): cmd += ['-framework', 'OpenCL'] # Add any additional cflags. if cflags: cmd += cflags # logging.debug('$ %s', ' '.join(cmd)) proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) stdout, stderr = proc.communicate(src) if not proc.returncode == 0: argv = ' '.join(cmd) raise DriverCompilationError( f'Driver compilation failed with returncode {proc.returncode}.\n' f'Command: {argv}\n' f'Stdout:\n{stdout}\n' f'Stderr:\n{stderr}\n' f'Driver source:\n{src}') return output_path
from deeplearning.deepsmith.proto import deepsmith_pb2 from deeplearning.deepsmith.proto import harness_pb2 from deeplearning.deepsmith.proto import harness_pb2_grpc from deeplearning.deepsmith.proto import service_pb2 from gpu.cldrive import cgen from gpu.cldrive import data from gpu.cldrive import driver from gpu.cldrive import env from labm8 import bazelutil from labm8 import fs from labm8 import labdate from labm8 import system FLAGS = flags.FLAGS _UNAME = 'linux' if system.is_linux() else 'mac' # Path to clang binary. CLANG_PATH = bazelutil.DataPath(f'llvm_{_UNAME}/bin/clang') # Flags for compiling with libcxx. LIBCXX_LIB_DIR = bazelutil.DataPath(f'llvm_{_UNAME}/lib') # Path to OpenCL headers. OPENCL_HEADERS_DIR = bazelutil.DataPath('opencl_120_headers') if system.is_linux(): LIBOPENCL_DIR = bazelutil.DataPath('libopencl') class DriverCompilationError(OSError): """Exception raised in case driver compilation fails.""" pass
bazelutil.DataPath('CLSmith/runtime/custom_limits.h'), bazelutil.DataPath('CLSmith/runtime/custom_stdint_x86.h'), bazelutil.DataPath('CLSmith/runtime/platform_avr.h'), bazelutil.DataPath('CLSmith/runtime/platform_generic.h'), bazelutil.DataPath('CLSmith/runtime/platform_msp430.h'), bazelutil.DataPath('CLSmith/runtime/random_inc.h'), bazelutil.DataPath('CLSmith/runtime/safe_abbrev.h'), bazelutil.DataPath('CLSmith/runtime/stdint_avr.h'), bazelutil.DataPath('CLSmith/runtime/stdint_ia32.h'), bazelutil.DataPath('CLSmith/runtime/stdint_ia64.h'), bazelutil.DataPath('CLSmith/runtime/stdint_msp430.h'), bazelutil.DataPath('CLSmith/runtime/volatile_runtime.h') ] # The path to libOpenCL.so, needed on Linux. if system.is_linux(): LIBOPENCL_SO = bazelutil.DataPath('libopencl/libOpenCL.so') def PrependToPath(path_to_prepend: str, path: typing.Optional[str]) -> str: """Prepend a path to a path environment variable. This uses ':' to separate path components, as used in system $PATH variables. Args: path_to_prepend: The path to prepend. path: The environment variable. Returns: A concatenation of the path to prepend and the existing path. """