Ejemplo n.º 1
0
    def _get_fallback_devices(self) -> List[plaidml._DeviceConfig]:
        """ Called if a GPU has not been discovered. Return any devices we can run on.

        Returns
        -------
        list:
            The :class:`pladml._DeviceConfig` fallaback objects that PlaidML has discovered.
        """
        # Try get a supported device
        experimental_setting = plaidml.settings.experimental
        plaidml.settings.experimental = False
        devices = plaidml.devices(self._ctx, limit=100, return_all=True)[0]

        # Try get any device
        if not devices:
            plaidml.settings.experimental = True
            devices = plaidml.devices(self._ctx, limit=100, return_all=True)[0]

        plaidml.settings.experimental = experimental_setting

        if not devices:
            raise RuntimeError("No valid devices could be found for plaidML.")

        self._log("warning", f"PlaidML could not find a GPU. Falling back to: "
                  f"{[d.id.decode('utf-8') for d in devices]}")
        return devices
Ejemplo n.º 2
0
    def available_devices(self) -> List[Device]:
        plaidml.settings.experimental = False
        devices, _ = plaidml.devices(self.ctx, limit=100, return_all=True)
        std_device_ids = set(dev.id for dev in devices)

        plaidml.settings.experimental = True
        exp_devices, _ = plaidml.devices(self.ctx, limit=100, return_all=True)
        devices = [self._to_dev(dev, False) for dev in devices] + [
            self._to_dev(dev, True)
            for dev in exp_devices if not dev.id in std_device_ids
        ]
        return devices
Ejemplo n.º 3
0
    def _get_all_devices(self) -> List[plaidml._DeviceConfig]:
        """ Obtain all available (experimental and supported) GPU devices from PlaidML.

        Returns
        -------
        list
            The :class:`pladml._DeviceConfig` objects for GPUs that PlaidML has discovered.
        """
        experimental_setting = plaidml.settings.experimental

        plaidml.settings.experimental = True
        devices = plaidml.devices(self._ctx, limit=100, return_all=True)[0]

        plaidml.settings.experimental = experimental_setting

        experi = [
            d for d in devices if d.details and json.loads(
                d.details.decode("utf-8")).get("type", "cpu").lower() == "gpu"
        ]

        self._log("debug", f"Obtained experimental Devices: {experi}")

        all_devices = experi + self._supported_devices

        self._log("debug", f"Obtained all Devices: {all_devices}")
        return all_devices
Ejemplo n.º 4
0
def get_plaidml_devices(gpu=False):
    prepare_plaidml()

    import plaidml

    ctx = plaidml.Context()
    plaidml.settings._setup_for_test(plaidml.settings.user_settings)
    plaidml.settings.experimental = True
    devices, _ = plaidml.devices(ctx, limit=100, return_all=True)
    out_devices = []
    for device in devices:
        points = 0
        if b"cuda" in device.description.lower():
            points += 1
        if b"opencl" in device.description.lower():
            points += 1
        if b"nvidia" in device.description.lower():
            points += 1
        if b"amd" in device.description.lower():
            points += 1
        out_devices.append((points, device))

    out_devices.sort(reverse=True)
    return {
        device.description.decode("utf8"): device.id.decode("utf8")
        for points, device in out_devices
    }
Ejemplo n.º 5
0
def get_plaidML_devices():
    global plaidML_devices
    global has_nvidia_device
    if plaidML_devices is None:
        plaidML_devices = []
        # Using plaidML OpenCL backend to determine system devices and has_nvidia_device
        try:
            os.environ[
                'PLAIDML_EXPERIMENTAL'] = 'false'  #this enables work plaidML without run 'plaidml-setup'
            import plaidml
            ctx = plaidml.Context()
            for d in plaidml.devices(ctx, return_all=True)[0]:
                details = json.loads(d.details)
                if details['type'] == 'CPU':  #skipping opencl-CPU
                    continue
                if 'nvidia' in details['vendor'].lower():
                    has_nvidia_device = True
                plaidML_devices += [{
                    'id':
                    d.id,
                    'globalMemSize':
                    int(details['globalMemSize']),
                    'description':
                    d.description.decode()
                }]
            ctx.shutdown()
        except:
            pass
    return plaidML_devices
Ejemplo n.º 6
0
 def validateConfig(self, config_filename):
     print('Validating %s' % (config_filename,))
     ctx = plaidml.Context()
     with open(config_filename) as config_file:
         config = config_file.read()
     try:
         for conf in plaidml.devices(ctx, config):
             print('Found device %s: %s' % (conf.name, conf.description))
     except plaidml.exceptions.NotFound:
         print('No devices found matching %s' % (config_filename,))
Ejemplo n.º 7
0
def print_devices(heading, flag):
    print(heading)
    ctx = plaidml.Context()
    plaidml.settings.experimental = flag
    matched, unmatched = plaidml.devices(ctx, limit=100, return_all=True)
    for dev in matched:
        print('{0}   {1: >50} : {2}'.format('*', dev.id.decode(),
                                            dev.description.decode()))
    for dev in unmatched:
        print('{0}   {1: >50} : {2}'.format(' ', dev.id.decode(),
                                            dev.description.decode()))
Ejemplo n.º 8
0
    def get_supported_devices(self):
        """ Return a list of supported devices """
        experimental_setting = plaidml.settings.experimental
        plaidml.settings.experimental = False
        devices, _ = plaidml.devices(self.ctx, limit=100, return_all=True)
        plaidml.settings.experimental = experimental_setting

        supported = [device for device in devices
                     if json.loads(device.details.decode()).get("type", "cpu").lower() == "gpu"]
        if _LOGGER:
            _LOGGER.debug(supported)
        return supported
Ejemplo n.º 9
0
    def get_all_devices(self):
        """ Return list of supported and experimental devices """
        experimental_setting = plaidml.settings.experimental
        plaidml.settings.experimental = True
        devices, _ = plaidml.devices(self.ctx, limit=100, return_all=True)
        plaidml.settings.experimental = experimental_setting

        experimental = [device for device in devices
                        if json.loads(device.details.decode()).get("type", "cpu").lower() == "gpu"]
        if _LOGGER:
            _LOGGER.debug("Experimental Devices: %s", experimental)
        all_devices = experimental + self.supported_devices
        if _LOGGER:
            _LOGGER.debug(all_devices)
        return all_devices
Ejemplo n.º 10
0
 def testDeviceEnumeratorWithNoDevices(self):
     ctx = plaidml.Context()
     with self.assertRaises(plaidml.exceptions.PlaidMLError):
         plaidml.settings.config = """{
               "platform": {
                 "@type": "type.vertex.ai/vertexai.tile.local_machine.proto.Platform",
                 "hals": [
                   {
                     "@type": "type.vertex.ai/vertexai.tile.hal.opencl.proto.Driver",
                   }
                 ]
               }
             }"""
         for conf in plaidml.devices(ctx):
             pass
Ejemplo n.º 11
0
def _get_device_configs(ctx):
    configs = {}
    type_indicies = {}
    for config in plaidml.devices(ctx):
        details = json.loads(config.details)
        ty = details['type']
        if ty in type_indicies:
            idx = type_indicies[ty] + 1
            devid = '{}:{}'.format(ty, idx)
        else:
            idx = 0
            devid = ty
        type_indicies[ty] = idx
        configs[devid] = _DevConf(config, details)
    return configs
Ejemplo n.º 12
0
def get_plaidml_devices(gpu=False, _id=0):
    import plaidml
    ctx = plaidml.Context()
    plaidml.settings._setup_for_test(plaidml.settings.user_settings)
    plaidml.settings.experimental = True
    devices, _ = plaidml.devices(ctx, limit=100, return_all=True)
    if gpu:
        for device in devices:
            if b'cuda' in device.description.lower():
                return device
        for device in devices:
            if b'opencl' in device.description.lower() and device.id.endswith(
                    b'%d' % _id):
                return device
    for device in devices:
        if b'llvm' in device.description.lower():
            return device
Ejemplo n.º 13
0
    def _get_supported_devices(self):
        """ Obtain GPU devices from PlaidML that are marked as "supported".

        Returns
        -------
        list
            The :class:`pladml._DeviceConfig` objects for GPUs that PlaidML has discovered.
        """
        experimental_setting = plaidml.settings.experimental
        plaidml.settings.experimental = False
        devices = plaidml.devices(self._ctx, limit=100, return_all=True)[0]
        plaidml.settings.experimental = experimental_setting

        supported = [
            device for device in devices
            if device.details and json.loads(device.details.decode()).get(
                "type", "cpu").lower() == "gpu"
        ]
        if _LOGGER:
            _LOGGER.debug(supported)
        return supported
Ejemplo n.º 14
0
    def _get_supported_devices(self) -> List[plaidml._DeviceConfig]:
        """ Obtain GPU devices from PlaidML that are marked as "supported".

        Returns
        -------
        list_LOGGER.
            The :class:`plaidml._DeviceConfig` objects for all supported GPUs that PlaidML has
            discovered.
        """
        experimental_setting = plaidml.settings.experimental

        plaidml.settings.experimental = False
        devices = plaidml.devices(self._ctx, limit=100, return_all=True)[0]
        plaidml.settings.experimental = experimental_setting

        supported = [d for d in devices
                     if d.details
                     and json.loads(d.details.decode("utf-8")).get("type", "cpu").lower() == "gpu"]

        self._log("debug", f"Obtained supported devices: {supported}")
        return supported
Ejemplo n.º 15
0
    def _get_all_devices(self):
        """ Obtain all available (experimental and supported) GPU devices from PlaidML.

        Returns
        -------
        list
            The :class:`pladml._DeviceConfig` objects for GPUs that PlaidML has discovered.
        """
        experimental_setting = plaidml.settings.experimental
        plaidml.settings.experimental = True
        devices, _ = plaidml.devices(self._ctx, limit=100, return_all=True)
        plaidml.settings.experimental = experimental_setting

        experi = [
            device for device in devices
            if device.details and json.loads(device.details.decode()).get(
                "type", "cpu").lower() == "gpu"
        ]
        if _LOGGER:
            _LOGGER.debug("Experimental Devices: %s", experi)
        all_devices = experi + self._supported_devices
        if _LOGGER:
            _LOGGER.debug(all_devices)
        return all_devices
Ejemplo n.º 16
0
 def testDeviceEnumeratorInvalidConfig(self):
     ctx = plaidml.Context()
     with self.assertRaises(plaidml.exceptions.InvalidArgument):
         plaidml.settings.config = 'An invalid configuration'
         for conf in plaidml.devices(ctx):
             pass
Ejemplo n.º 17
0
 def testDeviceEnumerator(self):
     ctx = plaidml.Context()
     for conf in plaidml.devices(ctx, limit=100):
         pass
Ejemplo n.º 18
0
def main():
    ctx = plaidml.Context()
    plaidml.quiet()

    def choice_prompt(question, choices, default):
        inp = ""
        while not inp in choices:
            inp = input("{0}? ({1})[{2}]:".format(question, ",".join(choices), default))
            if not inp:
                inp = default
            elif inp not in choices:
                print("Invalid choice: {}".format(inp))
        return inp

    print("""
PlaidML Setup ({0})

Thanks for using PlaidML!

Some Notes:
  * Bugs and other issues: https://github.com/plaidml/plaidml
  * Questions: https://stackoverflow.com/questions/tagged/plaidml
  * Say hello: https://groups.google.com/forum/#!forum/plaidml-dev
  * PlaidML is licensed under the GNU AGPLv3
 """.format(plaidml.__version__))

    # Operate as if nothing is set
    plaidml.settings._setup_for_test(plaidml.settings.user_settings)

    plaidml.settings.experimental = False
    devices, _ = plaidml.devices(ctx, limit=100, return_all=True)
    plaidml.settings.experimental = True
    exp_devices, unmatched = plaidml.devices(ctx, limit=100, return_all=True)

    if not (devices or exp_devices):
        if not unmatched:
            print("""
No OpenCL devices found. Check driver installation.
Read the helpful, easy driver installation instructions from our README:
http://github.com/plaidml/plaidml
""")
        else:
            print("""
No supported devices found. Run 'clinfo' and file an issue containing the full output.
""")
        sys.exit(-1)

    print("Default Config Devices:")
    if not devices:
        print("   No devices.")
    for dev in devices:
        print("   {0} : {1}".format(dev.id.decode(), dev.description.decode()))

    print("\nExperimental Config Devices:")
    if not exp_devices:
        print("   No devices.")
    for dev in exp_devices:
        print("   {0} : {1}".format(dev.id.decode(), dev.description.decode()))

    print(
        "\nUsing experimental devices can cause poor performance, crashes, and other nastiness.\n")
    exp = choice_prompt("Enable experimental device support", ["y", "n"], "n")
    plaidml.settings.experimental = exp == "y"
    try:
        devices = plaidml.devices(ctx, limit=100)
    except plaidml.exceptions.PlaidMLError:
        print("\nNo devices available in chosen config. Rerun plaidml-setup.")
        sys.exit(-1)

    if len(devices) > 1:
        print("""
Multiple devices detected (You can override by setting PLAIDML_DEVICE_IDS).
Please choose a default device:
""")
        devrange = range(1, len(devices) + 1)
        for i in devrange:
            print("   {0} : {1}".format(i, devices[i - 1].id.decode()))
        dev = choice_prompt("\nDefault device", [str(i) for i in devrange], "1")
        plaidml.settings.device_ids = [devices[int(dev) - 1].id.decode()]

    print("\nSelected device:\n    {0}".format(plaidml.devices(ctx)[0]))
    print("""
PlaidML sends anonymous usage statistics to help guide improvements.
We'd love your help making it better.
""")

    tel = choice_prompt("Enable telemetry reporting", ["y", "n"], "y")
    plaidml.settings.telemetry = tel == "y"

    print("\nAlmost done. Multiplying some matrices...")
    # Reinitialize to send a usage report
    print("Tile code:")
    print("  function (B[X,Z], C[Z,Y]) -> (A) { A[x,y : X,Y] = +(B[x,z] * C[z,y]); }")
    with plaidml.open_first_device(ctx) as dev:
        matmul = plaidml.Function(
            "function (B[X,Z], C[Z,Y]) -> (A) { A[x,y : X,Y] = +(B[x,z] * C[z,y]); }")
        shape = plaidml.Shape(ctx, plaidml.DType.FLOAT32, 3, 3)
        a = plaidml.Tensor(dev, shape)
        b = plaidml.Tensor(dev, shape)
        c = plaidml.Tensor(dev, shape)
        plaidml.run(ctx, matmul, inputs={"B": b, "C": c}, outputs={"A": a})
    print("Whew. That worked.\n")

    sav = choice_prompt("Save settings to {0}".format(plaidml.settings.user_settings), ["y", "n"],
                        "y")
    if sav == "y":
        plaidml.settings.save(plaidml.settings.user_settings)
    print("Success!\n")
Ejemplo n.º 19
0
def main():
    ctx = plaidml.Context()
    plaidml.quiet()

    def choice_prompt(question, choices, default):
        inp = ""
        while not inp in choices:
            inp = input("{0}? ({1})[{2}]:".format(question, ",".join(choices),
                                                  default))
            if not inp:
                inp = default
            elif inp not in choices:
                print("Invalid choice: {}".format(inp))
        return inp

    print("""
PlaidML Setup ({0})

Thanks for using PlaidML!

The feedback we have received from our users indicates an ever-increasing need
for performance, programmability, and portability. During the past few months,
we have been restructuring PlaidML to address those needs.  To make all the
changes we need to make while supporting our current user base, all development
of PlaidML has moved to a branch — plaidml-v1. We will continue to maintain and
support the master branch of PlaidML and the stable 0.7.0 release.

Read more here: https://github.com/plaidml/plaidml 

Some Notes:
  * Bugs and other issues: https://github.com/plaidml/plaidml/issues
  * Questions: https://stackoverflow.com/questions/tagged/plaidml
  * Say hello: https://groups.google.com/forum/#!forum/plaidml-dev
  * PlaidML is licensed under the Apache License 2.0
 """.format(plaidml.__version__))

    # Placeholder env var
    if os.getenv("PLAIDML_VERBOSE"):
        # change verbose settings to PLAIDML_VERBOSE, or 4 if PLAIDML_VERBOSE is invalid
        try:
            arg_verbose = int(os.getenv("PLAIDML_VERBOSE"))
        except ValueError:
            arg_verbose = 4
        plaidml._internal_set_vlog(arg_verbose)
        print("INFO:Verbose logging has been enabled - verbose level",
              arg_verbose, "\n")
        if plaidml.settings.default_config:
            (cfg_path,
             cfg_file) = os.path.split(plaidml.settings.default_config)
        else:
            (cfg_path, cfg_file) = ("Unknown", "Unknown")
        if plaidml.settings.experimental_config:
            (exp_path,
             exp_file) = os.path.split(plaidml.settings.experimental_config)
        else:
            (exp_path, exp_file) = ("Unknown", "Unknown")

    # Operate as if nothing is set
    plaidml.settings._setup_for_test(plaidml.settings.user_settings)

    plaidml.settings.experimental = False
    devices, _ = plaidml.devices(ctx, limit=100, return_all=True)
    plaidml.settings.experimental = True
    exp_devices, unmatched = plaidml.devices(ctx, limit=100, return_all=True)

    if not (devices or exp_devices):
        if not unmatched:
            print("""
No OpenCL devices found. Check driver installation.
Read the helpful, easy driver installation instructions from our README:
http://github.com/plaidml/plaidml
""")
        else:
            print("""
No supported devices found. Run 'clinfo' and file an issue containing the full output.
""")
        sys.exit(-1)

    if devices and os.getenv("PLAIDML_VERBOSE"):
        print("Default Config File Location:")
        print("   {0}/".format(cfg_path))

    print("\nDefault Config Devices:")
    if not devices:
        print("   No devices.")
    for dev in devices:
        print("   {0} : {1}".format(dev.id.decode(), dev.description.decode()))

    if exp_devices and os.getenv("PLAIDML_VERBOSE"):
        print("\nExperimental Config File Location:")
        print("   {0}/".format(exp_path))

    print("\nExperimental Config Devices:")
    if not exp_devices:
        print("   No devices.")
    for dev in exp_devices:
        print("   {0} : {1}".format(dev.id.decode(), dev.description.decode()))

    print(
        "\nUsing experimental devices can cause poor performance, crashes, and other nastiness.\n"
    )
    exp = choice_prompt("Enable experimental device support", ["y", "n"], "n")
    plaidml.settings.experimental = exp == "y"
    try:
        devices = plaidml.devices(ctx, limit=100)
    except plaidml.exceptions.PlaidMLError:
        print("\nNo devices available in chosen config. Rerun plaidml-setup.")
        sys.exit(-1)

    if devices:
        dev = 1
        if len(devices) > 1:
            print("""
Multiple devices detected (You can override by setting PLAIDML_DEVICE_IDS).
Please choose a default device:
""")
            devrange = range(1, len(devices) + 1)
            for i in devrange:
                print("   {0} : {1}".format(i, devices[i - 1].id.decode()))
            dev = choice_prompt("\nDefault device", [str(i) for i in devrange],
                                "1")
        plaidml.settings.device_ids = [devices[int(dev) - 1].id.decode()]

    print("\nSelected device:\n    {0}".format(plaidml.devices(ctx)[0]))

    print("\nAlmost done. Multiplying some matrices...")
    # Reinitialize to send a usage report
    print("Tile code:")
    print(
        "  function (B[X,Z], C[Z,Y]) -> (A) { A[x,y : X,Y] = +(B[x,z] * C[z,y]); }"
    )
    with plaidml.open_first_device(ctx) as dev:
        matmul = plaidml.Function(
            "function (B[X,Z], C[Z,Y]) -> (A) { A[x,y : X,Y] = +(B[x,z] * C[z,y]); }"
        )
        shape = plaidml.Shape(ctx, plaidml.DType.FLOAT32, 3, 3)
        a = plaidml.Tensor(dev, shape)
        b = plaidml.Tensor(dev, shape)
        c = plaidml.Tensor(dev, shape)
        plaidml.run(ctx, matmul, inputs={"B": b, "C": c}, outputs={"A": a})
    print("Whew. That worked.\n")

    sav = choice_prompt(
        "Save settings to {0}".format(plaidml.settings.user_settings),
        ["y", "n"], "y")
    if sav == "y":
        plaidml.settings.save(plaidml.settings.user_settings)
    print("Success!\n")
Ejemplo n.º 20
0
has_nvml_cap = False

#use force_has_nvidia_device=1 if
#- your NVIDIA cannot be seen by OpenCL
#- CUDA build of DFL
has_nvidia_device = os.environ.get("force_has_nvidia_device", "0") == "1"

plaidML_devices = []

# Using plaidML OpenCL backend to determine system devices and has_nvidia_device
try:
    os.environ[
        'PLAIDML_EXPERIMENTAL'] = 'false'  #this enables work plaidML without run 'plaidml-setup'
    import plaidml
    ctx = plaidml.Context()
    for d in plaidml.devices(ctx, return_all=True)[0]:
        details = json.loads(d.details)
        if details['type'] == 'CPU':  #skipping opencl-CPU
            continue
        if 'nvidia' in details['vendor'].lower():
            has_nvidia_device = True
        plaidML_devices += [{
            'id': d.id,
            'globalMemSize': int(details['globalMemSize']),
            'description': d.description.decode()
        }]
    ctx.shutdown()
except:
    pass

plaidML_devices_count = len(plaidML_devices)
Ejemplo n.º 21
0
 def setUpClass(cls):
     testing.plaidml_config.unittest_config()
     cls._ctx = plaidml.Context()
     cls._dev = plaidml.Device(cls._ctx,
                               plaidml.devices(cls._ctx, limit=10)[0])
Ejemplo n.º 22
0
def _get_device_configs(ctx):
    configs = {}
    type_indicies = {}
    for config in plaidml.devices(ctx):
        configs[config.id.decode()] = config
    return configs
Ejemplo n.º 23
0
def _inner_run(reports,
               frontend,
               network_names,
               params,
               warmup,
               kernel_timing,
               callgrind,
               print_stacktraces,
               tile=None):
    import plaidbench.cli as pb
    model = frontend.model(params)
    click.secho(
        'Running {0} examples with {1}, batch size {2}, on backend {3}'.format(
            params.examples, params.network_name, params.batch_size,
            params.backend_name),
        fg='magenta')

    if params.backend_name == 'plaid_edsl':
        # Don't do kernel timing with PlaidML EDSL
        kernel_timing = False
    else:
        device = plaidml.devices(plaidml.Context())[0]
        if 'metal' in str(device):
            kernel_timing = False

    benchmark_results = {}
    model_output = None

    if params.examples % params.batch_size != 0:
        raise ValueError(
            'The number of examples must be divisible by the batch size.')
    try:
        model.validate()
        model.setup()

        stop_watch = StopWatch(callgrind)
        compile_stop_watch = StopWatch(callgrind)

        click.echo('Compiling network...', nl=False)
        compile_stop_watch.start_outer()
        stop_watch.start_outer()

        model.compile()
        model_output, overrides = model.run(once=True)
        if tile:
            click.echo(' Saving Tile to {}...'.format(tile), nl=False)
            model.model.predict_function._invoker.save(tile)

        compile_stop_watch.stop()

        # Run a few more warmups -- this seems to improve the variability of the
        # benchmark results.
        if warmup:
            click.echo(' Warming up...', nl=False)
            model.run(warmup=True)
        click.echo(' Running...')

        # Plaid currently doesn't make it easy to get at metrics,
        # So we steal them from the logs
        timef = ProgramTimeFilter()
        og = logging.getLogger(plaidml.__name__)
        if kernel_timing:
            plaidml._lib()._internal_set_vlog(1)
            if og.level is logging.NOTSET:
                plaidml.DEFAULT_LOG_HANDLER.setLevel(logging.WARNING)
            og.setLevel(logging.DEBUG)
        og.addFilter(timef)

        stop_watch.start()
        _, overrides = model.run()
        stop_watch.stop()

        og.removeFilter(timef)
        # Record stopwatch times
        execution_duration = overrides.get('time', stop_watch.elapsed())
        tile_exec_per_example = 1e-9 + timef.tot_time_ns / 10.0**9 / params.examples
        exec_per_example = execution_duration / params.examples
        compile_duration = compile_stop_watch.elapsed()
        flops = overrides.get('flops', None)
        gflops = None
        if flops:
            gflops = (flops / 10.0**9 / exec_per_example)
            benchmark_results['GFLOP/s'] = gflops
            benchmark_results['flops'] = flops

        benchmark_results['compile_duration'] = compile_duration
        benchmark_results['duration_per_example'] = exec_per_example
        benchmark_results['tile_duration_per_example'] = tile_exec_per_example
        benchmark_results['examples'] = params.examples
        benchmark_results['batch_size'] = params.batch_size
        benchmark_results['model'] = params.network_name
        benchmark_results['backend'] = params.backend_name

        resstr = 'Example finished, elapsed: {:.3f}s (compile), {:.3f}s (execution)\n'.format(
            compile_duration, execution_duration)
        if gflops:
            resstr += ', {:.2f} (GFLOP/s)'.format(gflops)
        click.secho(resstr, fg='cyan', bold=True)
        if frontend.name == 'plaidml' and 'metal' in str(device):
            tile_exec_per_example = exec_per_example
        print(
            "-----------------------------------------------------------------------------------------"
        )
        print("%-20s %-25s %-20s" %
              ("Network Name", "Inference Latency", "Time / FPS"))
        print(
            "-----------------------------------------------------------------------------------------"
        )
        print("%-20s %-25s %-20s" %
              (params.network_name, "%.2f ms" %
               (exec_per_example * 1000), "%.2f ms / %.2f fps" %
               (tile_exec_per_example * 1000, 1.0 / tile_exec_per_example)))

        (golden_output, precision) = model.golden_output()
        (correct, max_error, max_abs_error,
         fail_ratio) = Runner._check_correctness(golden_output, model_output,
                                                 precision.value)
        benchmark_results['correct'] = correct
        benchmark_results['max_error'] = float(max_error)
        benchmark_results['max_abs_error'] = float(max_abs_error)
        benchmark_results['fail_ratio'] = fail_ratio
        if correct:
            status = 'PASS'
        else:
            status = 'FAIL'
        click.secho(
            'Correctness: {}, max_error: {}, max_abs_error: {}, fail_ratio: {}'
            .format(status, max_error, max_abs_error, fail_ratio),
            fg='green' if status == 'PASS' else 'red')
    except GoldenOutputNotAvailableError:
        click.echo(
            'Correctness: untested. Could not find golden data to compare against.'
        )
    except NoCorrectnessDesired:
        pass

    # Error handling
    except Exception as ex:
        # click.echo statements
        click.echo(ex)
        click.echo('Set --print-stacktraces to see the entire traceback')

        # Record error
        benchmark_results['exception'] = str(ex)

        if print_stacktraces:
            raise

    finally:
        reports.append((params, benchmark_results, model_output))
Ejemplo n.º 24
0
def main():
    # set intial exit status
    exit_status = 0

    # intialize and run arguement parser
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--results',
        default='/tmp/plaidbench_results',
        help=
        'system path to blanket runs will be looked for and output that will be graphed'
    )
    parser.add_argument('--prospector',
                        action='store_true',
                        default=False,
                        help='seek out golden paths')
    parser.add_argument('--gflops', default=2000, help='set card gflops')
    args = parser.parse_args()
    args.results = os.path.expanduser(args.results)
    args.gflops = int(args.gflops)

    # intialize variables
    plot_maker = plotter()
    data = {}

    # open results file
    try:
        os.makedirs(args.results)
    except OSError as ex:
        if ex.errno != errno.EEXIST:
            print(ex)
            return
    from os import listdir
    from os.path import isfile, join
    files = [
        f for f in listdir(args.results) if isfile(join(args.results, f))
        if f.endswith('json')
    ]
    for file in files:
        data = None
        with open(os.path.join(args.results, file), 'r') as saved_file:
            data = json.load(saved_file)
        # creating dict with completed runs
        runs = {}
        for key, value in data.items():
            if 'results' in value:
                if 'duration_per_example' in value['results']:
                    runs[key] = value['results']
                else:
                    pass

        for sz in ['sml', 'med', 'lrg']:
            # sort runs dictionary
            models_list = []
            executions_list = []
            batch_list2 = []
            name = []
            for x, y in sorted(runs.items()):
                if sz in y['model']:
                    models_list.append(y['model'])
                    executions_list.append(y['GFLOP/s'])
                    batch_list2.append(y['batch_size'])
                    name.append(y['model'] + " : " + str(y['batch_size']))
            if not models_list:
                continue
                # setting up data frame
            uber_list = pd.DataFrame()
            uber_list['model'] = models_list
            uber_list['GFLOP/s'] = executions_list
            uber_list['batch'] = batch_list2
            uber_list['name'] = name
            isTrain = (data['run_configuration']['train'])

            # attempting to get info about users env
            userSys = platform.uname()
            userPyV = platform.python_version()
            machine_info = []
            for info in userSys:
                machine_info.append(info)
            machine_info.append(userPyV)
            ctx = plaidml.Context()
            devices, _ = plaidml.devices(ctx, limit=100, return_all=True)
            for dev in devices:
                plt.suptitle(str(dev))
                machine_info.append(str(dev))

            plot_maker.generate_plot("{}_{}".format(file[:-5], sz), uber_list,
                                     args, isTrain)
    shutil.copyfile('compare.html.template',
                    os.path.join(args.results, 'compare.html'))