Пример #1
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:
        logging.warning('%s', e)
        result.outcome = deepsmith_pb2.Result.UNKNOWN
    finally:
        fs.rm(path)
    return result
Пример #2
0
 def _create_lock():
     lockfile = lockfile_pb2.LockFile(
         owner_process_id=os.getpid() if pid is None else pid,
         owner_process_argv=' '.join(sys.argv),
         date_acquired_utc_epoch_ms=labdate.MillisecondsTimestamp(
             labdate.GetUtcMillisecondsNow()),
         owner_hostname=system.HOSTNAME,
         owner_user=system.USERNAME)
     pbutil.ToFile(lockfile, self.path, assume_filename='LOCK.pbtxt')
Пример #3
0
    def RunTestcaseOnTestbed(self, testcase: deepsmith_pb2.Testcase,
                             testbed: deepsmith_pb2.Testbed) -> \
        deepsmith_pb2.Result:
        start_time = labdate.GetUtcMillisecondsNow()
        # ~~ Begin 'exec' timed region. ~~~
        # TODO: Popen something.
        # ~~~ End 'exec' timed region. ~~~
        end_time = labdate.GetUtcMillisecondsNow()

        # Create the result.
        result = deepsmith_pb2.Result()
        result.testcase = testcase
        result.testbed = testbed
        result.returncode = 0

        # Create profiling events.
        exec_time = result.profiling_events.add()
        exec_time.client = system.HOSTNAME
        exec_time.type = 'exec'
        exec_time.duration_ms = end_time - start_time
        exec_time.event_start_epoch_ms = start_time

        return result
Пример #4
0
def GetRepositoryMetadata(
        repo: Repository.Repository) -> scrape_repos_pb2.GitHubRepoMetadata():
    """Get metadata about a GitHub repository.

  Args:
    repo: A Repository instance.

  Returns:
    A GitHubRepoMetadata instance.
  """
    meta = scrape_repos_pb2.GitHubRepoMetadata()
    meta.scraped_utc_epoch_ms = labdate.MillisecondsTimestamp(
        labdate.GetUtcMillisecondsNow())
    meta.owner = repo.owner.login
    meta.name = repo.name
    meta.num_watchers = repo.watchers_count
    meta.num_forks = repo.forks_count
    meta.num_stars = repo.stargazers_count
    meta.clone_from_url = repo.clone_url
    return meta
Пример #5
0
def CreatePackageManifest(
        package_root: pathlib.Path,
        contents: typing.List[pathlib.Path]) -> dpack_pb2.DataPackage:
    """Create a DataPackage message for the contents of a package.

  Args:
    package_root: The root of the package.
    contents: A list of relative paths to files to include.

  Returns:
    A DataPackage instance with attributes set.
  """
    manifest = dpack_pb2.DataPackage()
    manifest.comment = ''
    manifest.utc_epoch_ms_packaged = labdate.MillisecondsTimestamp(
        labdate.GetUtcMillisecondsNow())
    for path in contents:
        f = manifest.file.add()
        SetDataPackageFileAttributes(package_root, path, f)
        f.comment = f.comment or ''
    return manifest
Пример #6
0
        (not raised if force option is used).
    """

    def _create_lock():
      lockfile = lockfile_pb2.LockFile(
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD:labm8/py/lockfile.py
=======
>>>>>>> 4242aed2a... Automated code format.
=======
>>>>>>> 4242aed2a... Automated code format.
        owner_process_id=os.getpid() if pid is None else pid,
        owner_process_argv=" ".join(sys.argv),
        date_acquired_utc_epoch_ms=labdate.MillisecondsTimestamp(
          labdate.GetUtcMillisecondsNow(),
        ),
        owner_hostname=system.HOSTNAME,
        owner_user=system.USERNAME,
<<<<<<< HEAD
<<<<<<< HEAD
      )
      pbutil.ToFile(lockfile, self.path, assume_filename="LOCK.pbtxt")
=======
          owner_process_id=os.getpid() if pid is None else pid,
          owner_process_argv=' '.join(sys.argv),
          date_acquired_utc_epoch_ms=labdate.MillisecondsTimestamp(
              labdate.GetUtcMillisecondsNow(),),
          owner_hostname=system.HOSTNAME,
          owner_user=system.USERNAME,
      )
Пример #7
0
def test_GetRepositoryMetadata_timestamp():
    """Test that the timestamp in metadata is set to (aprox) now."""
    now_ms = labdate.MillisecondsTimestamp(labdate.GetUtcMillisecondsNow())
    meta = scraper.GetRepositoryMetadata(MockRepository())
    assert now_ms - meta.scraped_utc_epoch_ms <= 1000
Пример #8
0
def test_GetUtcMillisecondsNow_millisecond_precision():
    # Test that milliseconds datetimes have no microseconds.
    now = labdate.GetUtcMillisecondsNow()
    assert not now.microsecond % 1000
Пример #9
0
def test_default_timestamp_datetime_equivalence():
    now = labdate.GetUtcMillisecondsNow()
    timestamp = labdate.MillisecondsTimestamp()
    date_out = labdate.DatetimeFromMillisecondsTimestamp(timestamp)
    assert now.date() == date_out.date()
Пример #10
0
def test_timestamp_datetime_equivalence():
    date_in = labdate.GetUtcMillisecondsNow()
    timestamp = labdate.MillisecondsTimestamp(date_in)
    date_out = labdate.DatetimeFromMillisecondsTimestamp(timestamp)
    assert date_in == date_out
Пример #11
0
def test_Testcase_ToProto():
    now = labdate.GetUtcMillisecondsNow()

    testcase = deeplearning.deepsmith.testcase.Testcase(
        toolchain=deeplearning.deepsmith.toolchain.Toolchain(string='cpp'),
        generator=deeplearning.deepsmith.generator.Generator(name='generator'),
        harness=deeplearning.deepsmith.harness.Harness(name='harness'),
        inputset=[
            deeplearning.deepsmith.testcase.TestcaseInput(
                name=deeplearning.deepsmith.testcase.TestcaseInputName(
                    string='src'),
                value=deeplearning.deepsmith.testcase.TestcaseInputValue(
                    string='void main() {}'),
            ),
            deeplearning.deepsmith.testcase.TestcaseInput(
                name=deeplearning.deepsmith.testcase.TestcaseInputName(
                    string='data'),
                value=deeplearning.deepsmith.testcase.TestcaseInputValue(
                    string='[1,2]'),
            ),
        ],
        invariant_optset=[
            deeplearning.deepsmith.testcase.TestcaseInvariantOpt(
                name=deeplearning.deepsmith.testcase.TestcaseInvariantOptName(
                    string='config'),
                value=deeplearning.deepsmith.testcase.
                TestcaseInvariantOptValue(string='opt'),
            ),
        ],
        profiling_events=[
            deeplearning.deepsmith.profiling_event.TestcaseProfilingEvent(
                client=deeplearning.deepsmith.client.Client(
                    string='localhost'),
                type=deeplearning.deepsmith.profiling_event.ProfilingEventType(
                    string='generate', ),
                duration_ms=100,
                event_start=now,
            ),
            deeplearning.deepsmith.profiling_event.TestcaseProfilingEvent(
                client=deeplearning.deepsmith.client.Client(
                    string='localhost'),
                type=deeplearning.deepsmith.profiling_event.ProfilingEventType(
                    string='foo', ),
                duration_ms=100,
                event_start=now,
            ),
        ])
    proto = testcase.ToProto()
    assert proto.toolchain == 'cpp'
    assert proto.generator.name == 'generator'
    assert proto.harness.name == 'harness'
    assert len(proto.inputs) == 2
    assert proto.inputs['src'] == 'void main() {}'
    assert proto.inputs['data'] == '[1,2]'
    assert len(proto.invariant_opts) == 1
    assert proto.invariant_opts['config'] == 'opt'
    assert len(proto.profiling_events) == 2
    assert (proto.profiling_events[0].event_start_epoch_ms ==
            labdate.MillisecondsTimestamp(now))
    assert proto.profiling_events[0].client == 'localhost'
    assert proto.profiling_events[0].type == 'generate'
    assert proto.profiling_events[0].client == 'localhost'