def str2actf(s): sl = str(s).lower() if sl == "sigmoid" or sl == "sigmoidlayer": return F.sigmoid elif sl == "softmax" or sl == "softmaxlayer": return F.softmax elif sl == "relu" or sl == "relulayer": return F.relu elif sl == "tanh" or sl == "tanhlayer": return F.tanh elif sl == "linear" or sl == "linearlayer": return util.linear else: util.panic("Unknown activate function name %s \n" % s)
def do_all(dom, dir_path): forest = OrderedDict() for conf in config.iterate(dom): out, err, code = coverage.run(dir_path, conf) if code != 0: panic(err, code) locations = coverage.parse(out) dt.update_forest(forest, conf, locations) for location, tree in sorted(forest.items()): dt.pretty_print(tree, location)
def do_iter(dom, dir_path, iter_max): forest = OrderedDict() iter_i = 0 for conf in config.iterate(dom): out, err, code = coverage.run(dir_path, conf) if code != 0: panic(err, code) locations = coverage.parse(out) dt.update_forest(forest, conf, locations) iter_i += 1 if iter_i >= iter_max: break for location, tree in sorted(forest.items()): dt.pretty_print(tree, location)
def main(*args): import m5 import core import debug import defines import event import info import stats import trace from util import inform, fatal, panic, isInteractive if len(args) == 0: options, arguments = parse_options() elif len(args) == 2: options, arguments = args else: raise TypeError, "main() takes 0 or 2 arguments (%d given)" % len(args) m5.options = options def check_tracing(): if defines.TRACING_ON: return fatal("Tracing is not enabled. Compile with TRACING_ON") # Set the main event queue for the main thread. event.mainq = event.getEventQueue(0) event.setEventQueue(event.mainq) if not os.path.isdir(options.outdir): os.makedirs(options.outdir) # These filenames are used only if the redirect_std* options are set stdout_file = os.path.join(options.outdir, options.stdout_file) stderr_file = os.path.join(options.outdir, options.stderr_file) # Print redirection notices here before doing any redirection if options.redirect_stdout and not options.redirect_stderr: print "Redirecting stdout and stderr to", stdout_file else: if options.redirect_stdout: print "Redirecting stdout to", stdout_file if options.redirect_stderr: print "Redirecting stderr to", stderr_file # Now redirect stdout/stderr as desired if options.redirect_stdout: redir_fd = os.open(stdout_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) os.dup2(redir_fd, sys.stdout.fileno()) if not options.redirect_stderr: os.dup2(redir_fd, sys.stderr.fileno()) if options.redirect_stderr: redir_fd = os.open(stderr_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) os.dup2(redir_fd, sys.stderr.fileno()) done = False if options.build_info: done = True print 'Build information:' print print 'compiled %s' % defines.compileDate print 'build options:' keys = defines.buildEnv.keys() keys.sort() for key in keys: val = defines.buildEnv[key] print ' %s = %s' % (key, val) print if options.copyright: done = True print info.COPYING print if options.readme: done = True print 'Readme:' print print info.README print if options.debug_help: done = True check_tracing() debug.help() if options.list_sim_objects: import SimObject done = True print "SimObjects:" objects = SimObject.allClasses.keys() objects.sort() for name in objects: obj = SimObject.allClasses[name] print " %s" % obj params = obj._params.keys() params.sort() for pname in params: param = obj._params[pname] default = getattr(param, 'default', '') print " %s" % pname if default: print " default: %s" % default print " desc: %s" % param.desc print print if done: sys.exit(0) # setting verbose and quiet at the same time doesn't make sense if options.verbose > 0 and options.quiet > 0: options.usage(2) verbose = options.verbose - options.quiet if verbose >= 0: print "gem5 Simulator System. http://gem5.org" print brief_copyright print print "gem5 compiled %s" % defines.compileDate print "gem5 started %s" % \ datetime.datetime.now().strftime("%b %e %Y %X") print "gem5 executing on %s, pid %d" % \ (socket.gethostname(), os.getpid()) # in Python 3 pipes.quote() is moved to shlex.quote() import pipes print "command line:", " ".join(map(pipes.quote, sys.argv)) print # check to make sure we can find the listed script if not arguments or not os.path.isfile(arguments[0]): if arguments and not os.path.isfile(arguments[0]): print "Script %s not found" % arguments[0] options.usage(2) # tell C++ about output directory core.setOutputDir(options.outdir) # update the system path with elements from the -p option sys.path[0:0] = options.path # set stats options stats.addStatVisitor(options.stats_file) # Disable listeners unless running interactively or explicitly # enabled if options.listener_mode == "off": m5.disableAllListeners() elif options.listener_mode == "auto": if not isInteractive(): inform("Standard input is not a terminal, disabling listeners.") m5.disableAllListeners() elif options.listener_mode == "on": pass else: panic("Unhandled listener mode: %s" % options.listener_mode) if options.listener_loopback_only: m5.listenersLoopbackOnly() # set debugging options debug.setRemoteGDBPort(options.remote_gdb_port) for when in options.debug_break: debug.schedBreak(int(when)) if options.debug_flags: check_tracing() on_flags = [] off_flags = [] for flag in options.debug_flags: off = False if flag.startswith('-'): flag = flag[1:] off = True if flag not in debug.flags: print >> sys.stderr, "invalid debug flag '%s'" % flag sys.exit(1) if off: debug.flags[flag].disable() else: debug.flags[flag].enable() if options.debug_start: check_tracing() e = event.create(trace.enable, event.Event.Debug_Enable_Pri) event.mainq.schedule(e, options.debug_start) else: trace.enable() if options.debug_end: check_tracing() e = event.create(trace.disable, event.Event.Debug_Enable_Pri) event.mainq.schedule(e, options.debug_end) trace.output(options.debug_file) for ignore in options.debug_ignore: check_tracing() trace.ignore(ignore) sys.argv = arguments sys.path = [os.path.dirname(sys.argv[0])] + sys.path filename = sys.argv[0] filedata = file(filename, 'r').read() filecode = compile(filedata, filename, 'exec') scope = {'__file__': filename, '__name__': '__m5_main__'} # if pdb was requested, execfile the thing under pdb, otherwise, # just do the execfile normally if options.pdb: import pdb import traceback pdb = pdb.Pdb() try: pdb.run(filecode, scope) except SystemExit: print "The program exited via sys.exit(). Exit status: ", print sys.exc_info()[1] except: traceback.print_exc() print "Uncaught exception. Entering post mortem debugging" t = sys.exc_info()[2] while t.tb_next is not None: t = t.tb_next pdb.interaction(t.tb_frame, t) else: exec filecode in scope # once the script is done if options.interactive: interact(scope)
def main(*args): import m5 import core import debug import defines import event import info import stats import trace from util import inform, fatal, panic, isInteractive if len(args) == 0: options, arguments = parse_options() elif len(args) == 2: options, arguments = args else: raise TypeError, "main() takes 0 or 2 arguments (%d given)" % len(args) m5.options = options def check_tracing(): if defines.TRACING_ON: return fatal("Tracing is not enabled. Compile with TRACING_ON") # Set the main event queue for the main thread. event.mainq = event.getEventQueue(0) event.setEventQueue(event.mainq) if not os.path.isdir(options.outdir): os.makedirs(options.outdir) # These filenames are used only if the redirect_std* options are set stdout_file = os.path.join(options.outdir, options.stdout_file) stderr_file = os.path.join(options.outdir, options.stderr_file) # Print redirection notices here before doing any redirection if options.redirect_stdout and not options.redirect_stderr: print "Redirecting stdout and stderr to", stdout_file else: if options.redirect_stdout: print "Redirecting stdout to", stdout_file if options.redirect_stderr: print "Redirecting stderr to", stderr_file # Now redirect stdout/stderr as desired if options.redirect_stdout: redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) os.dup2(redir_fd, sys.stdout.fileno()) if not options.redirect_stderr: os.dup2(redir_fd, sys.stderr.fileno()) if options.redirect_stderr: redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC) os.dup2(redir_fd, sys.stderr.fileno()) done = False if options.build_info: done = True print 'Build information:' print print 'compiled %s' % defines.compileDate; print 'build options:' keys = defines.buildEnv.keys() keys.sort() for key in keys: val = defines.buildEnv[key] print ' %s = %s' % (key, val) print if options.copyright: done = True print info.COPYING print if options.readme: done = True print 'Readme:' print print info.README print if options.debug_help: done = True check_tracing() debug.help() if options.list_sim_objects: import SimObject done = True print "SimObjects:" objects = SimObject.allClasses.keys() objects.sort() for name in objects: obj = SimObject.allClasses[name] print " %s" % obj params = obj._params.keys() params.sort() for pname in params: param = obj._params[pname] default = getattr(param, 'default', '') print " %s" % pname if default: print " default: %s" % default print " desc: %s" % param.desc print print if done: sys.exit(0) # setting verbose and quiet at the same time doesn't make sense if options.verbose > 0 and options.quiet > 0: options.usage(2) verbose = options.verbose - options.quiet if verbose >= 0: print "gem5 Simulator System. http://gem5.org" print brief_copyright print print "gem5 compiled %s" % defines.compileDate; print "gem5 started %s" % \ datetime.datetime.now().strftime("%b %e %Y %X") print "gem5 executing on %s, pid %d" % \ (socket.gethostname(), os.getpid()) # in Python 3 pipes.quote() is moved to shlex.quote() import pipes print "command line:", " ".join(map(pipes.quote, sys.argv)) print # check to make sure we can find the listed script if not arguments or not os.path.isfile(arguments[0]): if arguments and not os.path.isfile(arguments[0]): print "Script %s not found" % arguments[0] options.usage(2) # tell C++ about output directory core.setOutputDir(options.outdir) # update the system path with elements from the -p option sys.path[0:0] = options.path # set stats options stats.addStatVisitor(options.stats_file) # Disable listeners unless running interactively or explicitly # enabled if options.listener_mode == "off": m5.disableAllListeners() elif options.listener_mode == "auto": if not isInteractive(): inform("Standard input is not a terminal, disabling listeners.") m5.disableAllListeners() elif options.listener_mode == "on": pass else: panic("Unhandled listener mode: %s" % options.listener_mode) if options.listener_loopback_only: m5.listenersLoopbackOnly() # set debugging options debug.setRemoteGDBPort(options.remote_gdb_port) for when in options.debug_break: debug.schedBreak(int(when)) if options.debug_flags: check_tracing() on_flags = [] off_flags = [] for flag in options.debug_flags: off = False if flag.startswith('-'): flag = flag[1:] off = True if flag not in debug.flags: print >>sys.stderr, "invalid debug flag '%s'" % flag sys.exit(1) if off: debug.flags[flag].disable() else: debug.flags[flag].enable() if options.debug_start: check_tracing() e = event.create(trace.enable, event.Event.Debug_Enable_Pri) event.mainq.schedule(e, options.debug_start) else: trace.enable() if options.debug_end: check_tracing() e = event.create(trace.disable, event.Event.Debug_Enable_Pri) event.mainq.schedule(e, options.debug_end) trace.output(options.debug_file) for ignore in options.debug_ignore: check_tracing() trace.ignore(ignore) sys.argv = arguments sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path filename = sys.argv[0] filedata = file(filename, 'r').read() filecode = compile(filedata, filename, 'exec') scope = { '__file__' : filename, '__name__' : '__m5_main__' } # if pdb was requested, execfile the thing under pdb, otherwise, # just do the execfile normally if options.pdb: import pdb import traceback pdb = pdb.Pdb() try: pdb.run(filecode, scope) except SystemExit: print "The program exited via sys.exit(). Exit status: ", print sys.exc_info()[1] except: traceback.print_exc() print "Uncaught exception. Entering post mortem debugging" t = sys.exc_info()[2] while t.tb_next is not None: t = t.tb_next pdb.interaction(t.tb_frame,t) else: exec filecode in scope # once the script is done if options.interactive: interact(scope)
if __name__=='__main__': args = docopt(__doc__) of = args["--of"] pick = args["--pick"] file = args["<file>"] nn, actfs = dataio.loadnn(file) p = [] if re.match(r"^\d$", pick): p = [ int(pick) ] elif re.match(r"^\d:\d$", pick): r = pick.rstrip().split(':') assert len(r) == 2 r = map(int, r) p = range(r[0], r[1]) else: util.panic("Pick up argument is Unknown format: %s" % pick) d = {} j = 0 for i in p: l = getattr(nn, 'l_' + str(i)) s = str(j) d['w_' + s] = l.W.data d['hbias_' + s] = l.b.data d['type_' + s] = actfs[i].__name__ j += 1 np.savez(of, **d)
if gpu: cuda.init() model.to_gpu() if otype == 'f4be': be = True save = savebin elif otype == 'f4ne' or otype == 'f4le': be = False save = savebin elif otype == 'text': be = False save = savetxt else: util.panic("Unknown endian type: " + endian) def forward(x_data): x = Variable(x_data) h = actfs[0](model.l_0(x)) for i in range(1, nlayer): l = getattr(model, 'l_'+str(i)) h = actfs[i](l(h)) return h ndata = data.shape[0] f = open(of, 'wb') for i in range(0, ndata, mbsize): x_batch = data[i:i+mbsize] if gpu: x_batch = cuda.to_gpu(x_batch)