Beispiel #1
0
def test_DriveToDataFrame_device_not_found(device: env.OpenCLEnvironment):
  device.name = "nope"
  device.platform_name = "not a real platform"
  device.device_name = "not a real device"
  with test.Raises(api.CldriveCrash):
    api.DriveToDataFrame(
      _MakeInstance(
        device, "kernel void A(global int* a) { a[get_global_id(0)] *= 2; }"
      )
    )
Beispiel #2
0
def RunTestcase(
    opencl_environment: env.OpenCLEnvironment,
    testbed: deepsmith_pb2.Testbed,
    testcase: deepsmith_pb2.Testcase,
    cflags: typing.List[str],
) -> deepsmith_pb2.Result:
    """Run a testcase."""
    if testcase.toolchain != "opencl":
        raise ValueError(
            f"Unsupported testcase toolchain: '{testcase.toolchain}'")
    if testcase.harness.name != "cldrive":
        raise ValueError(
            f"Unsupported testcase harness: '{testcase.harness.name}'")
    result = deepsmith_pb2.Result()
    result.testbed.CopyFrom(testbed)
    platform_id, device_id = opencl_environment.ids()
    driver = MakeDriver(
        testcase, True if testbed.opts["opencl_opt"] == "enabled" else False)
    # MakeDriver() annotates the testcase, so we must only set the testcase field
    # of the output result after we have called it.
    result.testcase.CopyFrom(testcase)
    # Get a temporary file to write and run the driver from.
    with tempfile.NamedTemporaryFile(prefix="deepsmith_", delete=False) as f:
        path = pathlib.Path(f.name)
    try:
        CompileDriver(driver, path, platform_id, device_id, cflags=cflags)
        timeout = testcase.harness.opts.get("timeout_seconds", "60")
        cmd = ["timeout", "-s9", timeout, f.name]
        start_time = labdate.GetUtcMillisecondsNow()
        proc = opencl_environment.Exec(cmd)
        end_time = labdate.GetUtcMillisecondsNow()
        # Build result message.
        result.returncode = proc.returncode
        result.outputs["stdout"] = proc.stdout
        result.outputs["stderr"] = proc.stderr
        runtime = result.profiling_events.add()
        runtime.client = system.HOSTNAME
        runtime.type = "runtime"
        runtime.duration_ms = int(
            round((end_time - start_time).total_seconds() * 1000))
        runtime.event_start_epoch_ms = labdate.MillisecondsTimestamp(
            start_time)
        result.outcome = GetResultOutcome(result)
    except DriverCompilationError as e:
        app.Warning("%s", e)
        result.outcome = deepsmith_pb2.Result.UNKNOWN
    finally:
        fs.rm(path)
    return result
Beispiel #3
0
def RunLibceclExecutable(
  command: typing.List[str],
  env: cldrive_env.OpenCLEnvironment,
  os_env: typing.Optional[typing.Dict[str, str]] = None,
  record_outputs: bool = True,
) -> libcecl_pb2.LibceclExecutableRun:
  """Run executable using libcecl and log output."""
  timestamp = labdate.MillisecondsTimestamp()

  os_env = RunEnv(env, os_env)
  start_time = time.time()
  process = env.Exec(command, env=os_env)
  elapsed = time.time() - start_time

  stderr_lines, cecl_lines, program_sources = SplitStderrComponents(
    process.stderr
  )

  return libcecl_pb2.LibceclExecutableRun(
    ms_since_unix_epoch=timestamp,
    returncode=process.returncode,
    stdout=process.stdout if record_outputs else "",
    stderr="\n".join(stderr_lines) if record_outputs else "",
    cecl_log="\n".join(cecl_lines) if record_outputs else "",
    device=env.proto,
    kernel_invocation=KernelInvocationsFromCeclLog(
      cecl_lines,
      expected_devtype=env.device_type,
      expected_device_name=env.device_name,
    ),
    elapsed_time_ns=int(elapsed * 1e9),
    opencl_program_source=program_sources,
  )
Beispiel #4
0
def ExecClsmithSource(
    opencl_environment: env.OpenCLEnvironment,
    src: str,
    gsize: driver.NDRange,
    lsize: driver.NDRange,
    *opts,
    timeout_seconds: int = 60,
    env: typing.Dict[str, str] = None,
) -> subprocess.Popen:
    """Execute a CLsmith source program using 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.
    src: The CLSmith program src.
    gsize: Kernel global size.
    lsize: Kernel local size.
    opts: A list of optional command line flags.
    timeout_seconds: The maximum number of seconds to execute cl_launcher for.
    env: An optional environment to run the program under.

  Returns:
    A Popen instance, with string stdout and stderr attributes set.
  """
    platform_id, device_id = opencl_environment.ids()
    with fs.TemporaryWorkingDir(prefix="cl_launcher_") as d:
        with open(d / "CLProg.c", "w") as f:
            f.write(src)
        proc = Exec(
            opencl_environment,
            "-f",
            str(d / "CLProg.c"),
            "-g",
            gsize.ToString(),
            "-l",
            lsize.ToString(),
            "-p",
            str(platform_id),
            "-d",
            str(device_id),
            *opts,
            timeout_seconds=timeout_seconds,
            env=env,
        )
    return proc
Beispiel #5
0
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.
  """
    # On linux we must set the LD_PRELOAD to point to the libOpenCL.so.
    if system.is_linux():
        env = env or os.environ.copy()
        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