def main(): """The test runner entrypoint.""" parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', action='count', default=0) flags, remainder = parser.parse_known_args() plaidml._internal_set_vlog(flags.verbose) unittest.main(argv=sys.argv[:1] + remainder, verbosity=flags.verbose + 1)
def plaidbench(ctx, verbose, examples, blanket_run, results, callgrind, epochs, batch_size, timeout_secs, warmup, print_stacktraces, kernel_timing): """PlaidML Machine Learning Benchmarks plaidbench runs benchmarks for a variety of ML framework, framework backend, and neural network combinations. For more information, see http://www.github.com/plaidml/plaidbench """ runner = ctx.ensure_object(core.Runner) if blanket_run: runner.param_builder = core.BlanketParamBuilder(epochs) runner.reporter = core.BlanketReporter(os.path.expanduser(results)) runner.reporter.configuration['train'] = False else: runner.param_builder = core.ExplicitParamBuilder( batch_size, epochs, examples) runner.reporter = core.ExplicitReporter(results) if verbose: plaidml._internal_set_vlog(verbose) runner.verbose = verbose runner.callgrind = callgrind runner.warmup = warmup runner.kernel_timing = kernel_timing runner.print_stacktraces = print_stacktraces runner.timeout_secs = timeout_secs
def main(): parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', action='count', default=0) args = parser.parse_args() plaidml._internal_set_vlog(args.verbose) print_devices('Stable configurations', False) print_devices('Experimental configurations', True)
def _set_plaidml_logger(self) -> None: """ Set PlaidMLs default logger to Faceswap Logger, prevent propagation and set the correct log level. """ self._log("debug", "Setting PlaidML Default Logger") plaidml.DEFAULT_LOG_HANDLER = logging.getLogger("plaidml_root") plaidml.DEFAULT_LOG_HANDLER.propagate = 0 numeric_level = getattr(logging, self._log_level, None) if numeric_level < 10: # DEBUG Logging plaidml._internal_set_vlog(1) # pylint:disable=protected-access elif numeric_level < 20: # INFO Logging plaidml._internal_set_vlog(0) # pylint:disable=protected-access else: # WARNING LOGGING plaidml.quiet()
def set_verbosity(loglevel): """ Set the PlaidML Verbosity """ if _LOGGER: _LOGGER.debug("Setting PlaidML Loglevel: %s", loglevel) if isinstance(loglevel, int): numeric_level = loglevel else: numeric_level = getattr(logging, loglevel.upper(), None) if numeric_level < 10: # DEBUG Logging plaidml._internal_set_vlog(1) # pylint:disable=protected-access elif numeric_level < 20: # INFO Logging plaidml._internal_set_vlog(0) # pylint:disable=protected-access else: # WARNING Logging plaidml.quiet()
def _set_verbosity(cls, log_level): """ Set the PlaidML logging verbosity log_level: str The requested Faceswap log level. Also dictates the level that PlaidML logging is set at. """ if _LOGGER: _LOGGER.debug("Setting PlaidML Loglevel: %s", log_level) if isinstance(log_level, int): numeric_level = log_level else: numeric_level = getattr(logging, log_level.upper(), None) if numeric_level < 10: # DEBUG Logging plaidml._internal_set_vlog(1) # pylint:disable=protected-access elif numeric_level < 20: # INFO Logging plaidml._internal_set_vlog(0) # pylint:disable=protected-access else: # WARNING Logging plaidml.quiet()
# Hack to avoid using the plaidml.keras submodule when trying to load keras sys.path = sys.path[1:] + [sys.path[0]] from keras.backend import tensorflow_backend as tf from keras.backend import floatx sys.path = [sys.path[-1]] + sys.path[:-1] import plaidml from plaidml.keras import backend as pkb if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--fp16', action='store_true') parser.add_argument('-v', '--verbose', action='count', default=0) args, remainder = parser.parse_known_args() plaidml._internal_set_vlog(args.verbose) if args.fp16: pkb.set_floatx('float16') DEFAULT_TOL = 1e-2 DEFAULT_ATOL = 1e-5 else: pkb.set_floatx('float32') DEFAULT_TOL = 1e-3 DEFAULT_ATOL = 1e-8 def opTest(in_data, tol=DEFAULT_TOL, atol=DEFAULT_ATOL, skip_tensorflow=False, verbose=False,
from collections import OrderedDict import numpy as np import plaidml import plaidml.keras plaidml.keras.install_backend() import keras.backend as K def main(code, tensor_A, tensor_B, output_shape): print(K.backend()) op = K._Op('sandbox_op', A.dtype, output_shape, code, OrderedDict([('A', tensor_A), ('B', tensor_B)]), ['O']) print(op.eval()) if __name__ == '__main__': plaidml._internal_set_vlog(3) A = K.variable(np.array([[1., 2., 3.], [4., 5., 6.]])) B = K.variable(np.array([-7., -1., 2.])) # code = """function (A[N, M], B[M]) -> (O) { # O[i, j: N, M] = =(A[i, j] + B[j]), i/2 + j/2 + 1/2 < 2; # }""" # out_shape = (2, 3) code = """function (A[N, M], B[M]) -> (O) { O[i: N] = +(A[i - j, 0] + B[0]), j < N; }""" out_shape = (3, ) main(code, A, B, out_shape)
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")