def load_and_analyze(args_tuple): fn, args, dataset, entrystart, entrystop, ismc, ichunk = args_tuple this_worker = get_worker_wrapper() NUMPY_LIB, backend = hepaccelerate.choose_backend(args.use_cuda) print("Loading {0}".format(fn)) ds, timing_results = load_dataset( args.datapath, fn, ismc, args.nthreads, args.skim, NUMPY_LIB, backend, entrystart, entrystop, ) t0 = time.time() ret = run_analysis(ds, "{0}_{1}".format(dataset, ichunk), this_worker.dnnmodel, args.use_cuda, ismc) t1 = time.time() ret["timing"] = Results(timing_results) ret["timing"]["run_analysis"] = t1 - t0 ret["timing"]["num_events"] = ds.numevents() return ret
def multiprocessing_initializer(args, gpu_id=None): this_worker = get_worker_wrapper() # Set up tensorflow import tensorflow as tf config = tf.compat.v1.ConfigProto() config.intra_op_parallelism_threads = args.nthreads config.inter_op_parallelism_threads = args.nthreads os.environ["NUMBA_NUM_THREADS"] = str(args.nthreads) os.environ["OMP_NUM_THREADS"] = str(args.nthreads) if not args.use_cuda: os.environ["CUDA_VISIBLE_DEVICES"] = "-1" else: if not gpu_id is None: os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu_id) config.gpu_options.allow_growth = False gpu_memory_fraction = 0.2 config.gpu_options.per_process_gpu_memory_fraction = gpu_memory_fraction from keras.backend.tensorflow_backend import set_session this_worker.session = tf.Session(config=config) set_session(this_worker.session) NUMPY_LIB, backend = hepaccelerate.choose_backend(args.use_cuda) this_worker.dnnmodel = DNNModel(NUMPY_LIB) this_worker.NUMPY_LIB = NUMPY_LIB this_worker.backend = backend # Import kernels that are specific to this analysis if args.use_cuda: import cuda_kernels as kernels else: import cpu_kernels as kernels this_worker.kernels = kernels this_worker.graph = tf.get_default_graph() # Create random vectors as placeholders of lepton pt event weights this_worker.electron_weights = NUMPY_LIB.zeros((100, 2), dtype=NUMPY_LIB.float32) this_worker.electron_weights[:, 0] = NUMPY_LIB.linspace( 0, 200, this_worker.electron_weights.shape[0])[:] this_worker.electron_weights[:, 1] = 1.0 # Create random vectors as placeholders of pt-dependent jet energy corrections this_worker.jecs_bins = NUMPY_LIB.zeros(100, dtype=NUMPY_LIB.float32) this_worker.jecs_up = NUMPY_LIB.zeros((99, args.njec), dtype=NUMPY_LIB.float32) this_worker.jecs_down = NUMPY_LIB.zeros((99, args.njec), dtype=NUMPY_LIB.float32) this_worker.jecs_bins[:] = NUMPY_LIB.linspace( 0, 200, this_worker.jecs_bins.shape[0])[:] for i in range(args.njec): this_worker.jecs_up[:, i] = 0.3 * (float(i + 1) / float(args.njec)) this_worker.jecs_down[:, i] = -0.3 * (float(i + 1) / float(args.njec))