def __init__(self, gpuf, direction): common.check_type('gpuf', gpuf, gpu.Fields) common.check_value('direction', direction, ('+', '-', '+-')) if '+' in direction: self.getf_h = getf_h = gpu.GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0), (-1, -1, -1)) self.setf_e = gpu.SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) self.req_send_h = comm.Send_init(getf_h.host_array, rank + 1, tag=0) self.tmp_recv_e = tmp_recv_e = np.zeros(getf_h.host_array.shape, gpuf.dtype) self.req_recv_e = comm.Recv_init(tmp_recv_e, rank + 1, tag=1) if '-' in direction: self.getf_e = getf_e = gpu.GetFields(gpuf, ['ey', 'ez'], (0, 0, 0), (0, -1, -1)) self.setf_h = gpu.SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) self.req_send_e = comm.Send_init(getf_e.host_array, rank - 1, tag=1) self.tmp_recv_h = tmp_recv_h = np.zeros(getf_e.host_array.shape, gpuf.dtype) self.req_recv_h = comm.Recv_init(tmp_recv_h, rank - 1, tag=0) # global variables self.direction = direction
def __init__(self, gpuf, direction): common.check_type('gpuf', gpuf, gpu.Fields) common.check_value('direction', direction, ('+', '-', '+-')) qtask = cpu.QueueTask() if '+' in direction: self.cpuf_p = cpuf_p = cpu.Fields(qtask, 3, gpuf.ny, gpuf.nz, gpuf.coeff_use, gpuf.precision_float, use_cpu_core=0) self.gf_p_h = gpu.GetFields(gpuf, ['hy', 'hz'], (-2, 0, 0), (-2, -1, -1)) self.sf_p_h = cpu.SetFields(cpuf_p, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) self.gf_p_e = cpu.GetFields(cpuf_p, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) self.sf_p_e = gpu.SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) self.gf_h = cpu.GetFields(cpuf_p, ['hy', 'hz'], (1, 0, 0), (1, -1, -1)) self.sf_e = cpu.SetFields(cpuf_p, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) self.tmp_recv_e = np.zeros(self.gf_h.host_array.shape, gpuf.dtype) if '-' in direction: self.cpuf_m = cpuf_m = cpu.Fields(qtask, 3, gpuf.ny, gpuf.nz, gpuf.coeff_use, gpuf.precision_float, use_cpu_core=0) self.gf_m_e = gpu.GetFields(gpuf, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) self.sf_m_e = cpu.SetFields(cpuf_m, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) self.gf_m_h = cpu.GetFields(cpuf_m, ['hy', 'hz'], (1, 0, 0), (1, -1, -1)) self.sf_m_h = gpu.SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) self.gf_e = cpu.GetFields(cpuf_m, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) self.sf_h = cpu.SetFields(cpuf_m, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) self.tmp_recv_h = np.zeros(self.gf_e.host_array.shape, gpuf.dtype) # global variables self.direction = direction self.qtask = qtask
def __init__(self, node_fields, axis): """ """ common.check_type('node_fields', node_fields, NodeFields) common.check_value('axis', axis, ['x', 'y', 'z']) # local variables self.gpu = gpu self.cpu = cpu mainf_list = node_fields.mainf_list cpuf_dict = node_fields.cpuf_dict axis_id = {'x': 0, 'y': 1, 'z': 2}[axis] set_cpuf = set(cpuf_dict.keys()) for ax in ['x', 'y', 'z']: if not set_cpuf.isdisjoint([ax + '+', ax + '-']): raise ValueError, 'There are %s-axis buffer instances. The pbc_internal operation along %s-axis is not allowed.' % ( ax, ax) # create pbc instances f0 = mainf_list[0] f1 = mainf_list[-1] if axis == 'x': if f0 is not f1: setf_e = cpu.SetFields(f1, ['ey', 'ez'], \ (f1.nx-1, 0, 0), (f1.nx-1, f1.ny-2, f1.nz-2), True) getf_e = gpu.GetFields(f0, ['ey', 'ez'], \ (0, 0, 0), (0, f0.ny-2, f0.nz-2) ) setf_h = gpu.SetFields(f0, ['hy', 'hz'], \ (0, 1, 1), (0, f0.ny-1, f0.nz-1), True ) getf_h = cpu.GetFields(f1, ['hy', 'hz'], \ (f1.nx-1, 1, 1), (f1.nx-1, f1.ny-1, f1.nz-1) ) else: getattr(self, f0.device_type).Pbc(f0, axis) elif axis in ['y', 'z']: for f in mainf_list: getattr(self, f.device_type).Pbc(f, axis) # global variables and functions if axis == 'x' and f0 is not f1: self.setf_e = setf_e self.getf_e = getf_e self.setf_h = setf_h self.getf_h = getf_h self.update_e = self.update_e_actual self.update_h = self.update_h_actual else: self.update_e = lambda: None self.update_h = lambda: None
def __init__(self, gpuf, direction, tmax): common.check_type('gpuf', gpuf, gpu.Fields) common.check_value('direction', direction, ('+', '-', '+-')) qtask = cpu.QueueTask() if '+' in direction: self.cpuf_p = cpuf_p = cpu.Fields(qtask, 3, gpuf.ny, gpuf.nz, gpuf.coeff_use, gpuf.precision_float, use_cpu_core=1) self.gf_p_h = gpu.GetFields(gpuf, ['hy', 'hz'], (-2, 0, 0), (-2, -1, -1)) self.sf_p_h = cpu.SetFields(cpuf_p, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) self.gf_p_e = cpu.GetFields(cpuf_p, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) self.sf_p_e = gpu.SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) self.gf_h = gf_h = cpu.GetFields(cpuf_p, ['hy', 'hz'], (1, 0, 0), (1, -1, -1)) self.sf_e = cpu.SetFields(cpuf_p, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) self.req_send_h = comm.Send_init(gf_h.host_array, rank + 1, tag=0) self.tmp_recv_e_list = [ np.zeros(gf_h.host_array.shape, gpuf.dtype) for i in range(2) ] self.req_recv_e_list = [ comm.Recv_init(tmp_recv_e, rank + 1, tag=1) for tmp_recv_e in self.tmp_recv_e_list ] self.switch_e = 0 if '-' in direction: self.cpuf_m = cpuf_m = cpu.Fields(qtask, 3, gpuf.ny, gpuf.nz, gpuf.coeff_use, gpuf.precision_float, use_cpu_core=1) self.gf_m_e = gpu.GetFields(gpuf, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) self.sf_m_e = cpu.SetFields(cpuf_m, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) self.gf_m_h = cpu.GetFields(cpuf_m, ['hy', 'hz'], (1, 0, 0), (1, -1, -1)) self.sf_m_h = gpu.SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) self.gf_e = gf_e = cpu.GetFields(cpuf_m, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) self.sf_h = cpu.SetFields(cpuf_m, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) self.req_send_e = comm.Send_init(gf_e.host_array, rank - 1, tag=1) self.tmp_recv_h_list = [ np.zeros(gf_e.host_array.shape, gpuf.dtype) for i in range(2) ] self.req_recv_h_list = [ comm.Recv_init(tmp_recv_h, rank - 1, tag=0) for tmp_recv_h in self.tmp_recv_h_list ] self.switch_h = 0 # global variables self.direction = direction self.qtask = qtask self.tmax = tmax self.tstep = 1
def __init__(s, gpu_fields_list, position, target_rank, nx, ny, nz, dtype, coeff_use, use_cpu_core): cpu.Fields.__init__(nx, ny, nz, dtype, coeff_use, use_cpu_core) s.pos = position s.rank = target_rank # get, set from gpus fs = gpu_fields_list ny, nz = fs[0].ny, fs[0].nz if s.pos == 'x+': f = fs[-1] s.getfs = [gpu.GetFields(f, ['hy', 'hz'], (f.nx-1, 0, 0), (f.nx-1, ny-1, nz-1))] s.setfs = [gpu.SetFields(f, ['ey', 'ez'], (f.nx-1, 0, 0), (f.nx-1, ny-1, nz-1))] s.send_tag, s.recv_tag = 11, 12 elif s.pos == 'x-': f = fs[0] s.getfs = [gpu.GetFields(f, ['ey', 'ez'], (1, 0, 0), (1, ny-1, nz-1))] s.setfs = [gpu.SetFields(f, ['hy', 'hz'], (0, 0, 0), (0, ny-1, nz-1))] s.send_tag, s.recv_tag = 12, 11 elif s.pos == 'y+': s.getfs = [gpu.GetFields(fields, ['hx', 'hz'], (0, ny-2, 0), (f.nx-1, ny-2, nz-1)) for f in fs] s.setfs = [gpu.SetFields(fields, ['ex', 'ez'], (0, ny-1, 0), (f.nx-1, ny-1, nz-1)) for f in fs] s.send_tag, s.recv_tag = 21, 22 elif s.pos == 'y-': s.getfs = [gpu.GetFields(fields, ['ex', 'ez'], (0, 1, 0), (f.nx-1, 1, nz-1)) for f in fs] s.setfs = [gpu.SetFields(fields, ['hx', 'hz'], (0, 0, 0), (f.nx-1, 0, nz-1)) for f in fs] s.send_tag, s.recv_tag = 22, 21 elif s.pos == 'z+': s.getfs = [gpu.GetFields(fields, ['hx', 'hy'], (0, 0, nz-2), (f.nx-1, ny-1, nz-2)) for f in fs] s.setfs = [gpu.SetFields(fields, ['ex', 'ey'], (0, 0, nz-1), (f.nx-1, ny-1, nz-1)) for f in fs] s.send_tag, s.recv_tag = 31, 32 elif s.pos == 'z-': s.getfs = [gpu.GetFields(fields, ['ex', 'ey'], (0, 0, 1), (f.nx-1, ny-1, 1)) for f in fs] s.setfs = [gpu.SetFields(fields, ['hx', 'hy'], (0, 0, 0), (f.nx-1, ny-1, 0)) for f in fs] s.send_tag, s.recv_tag = 32, 31 # slice for one-to-many exchange if s.pos in ['x+', 'x-']: idxs = [0, f.nx] elif s.pos in ['y+', 'y-', 'z+', 'z-']: idxs = [0] for i, nx in [f.nx for f in fs]: idxs.append(idxs[i] + nx - i) s.sls = [ slice(idxs[i], idxs[i+1]) for i, idx in enumerate(idxs[:-1])) ] if s.pos == 'x+': s.to_gpu_e_idx = 0 else: s.to_gpu_e_idx = 1 # requests for persistent mpi communications if '-' in s.pos: s.req_send = comm.Send_init(s.ey[1,:,:], dest=s.rank, tag=s.send_tag) s.req_send = comm.Send_init(s.ez[1,:,:], dest=s.rank, tag=s.send_tag) s.req_recv = comm.Recv_init(s.hy[0,:,:], dest=s.rank, tag=s.recv_tag) s.req_recv = comm.Recv_init(s.hz[0,:,:], dest=s.rank, tag=s.recv_tag) # arguments for update if '-' in s.pos: s.e_args_pre = s.e_args[:3] + [np.int32(ny*nz), np.int32(2*ny*nz)] + s.e_args[5:] s.e_args_mid = s.e_args[:3] + [np.int32(2*ny*nz), np.int32((nx*ny-1)*nz)] + s.e_args[5:] s.e_args_post = s.e_args[:3] + [np.int32(0), np.int32(ny*nz)] + s.e_args[5:] elif '+' in s.pos: s.h_args_pre = s.h_args[:3] + [np.int32((nx-2)*ny*nz), np.int32((nx-1)*ny*nz)] + s.h_args[5:] s.h_args_mid = s.h_args[:3] + [np.int32(nz), np.int32((nx-2)*ny*nz)] + s.h_args[5:] s.h_args_post = s.h_args[:3] + [np.int32((nx-1)*ny*nz), np.int32(nx*ny*nz)] + s.h_args[5:]
def __init__(self, gpuf, direction, tmax, ny, nz, coeff_use, precision_float): """ """ super(BufferFields, self).__init__(3, ny, nz, coeff_use, precision_float, use_cpu_core=0) common.check_type('gpuf', gpuf, gpu.Fields) common.check_value('direction', direction, ('x+', 'x-')) if direction == 'x+': gf0 = gpu.GetFields(gpuf, ['hy', 'hz'], (-2, 0, 0), (-2, -1, -1)) sf0 = cpu.SetFields(self, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) gf1 = cpu.GetFields(self, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) sf1 = gpu.SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) gf2 = cpu.GetFields(self, ['hy', 'hz'], (1, 0, 0), (1, -1, -1)) sf2 = cpu.SetFields(self, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) target_rank = rank + 1 tag_send, tag_recv = 0, 1 elif direction == 'x-': gf0 = gpu.GetFields(gpuf, ['ey', 'ez'], (2, 0, 0), (2, -1, -1)) sf0 = cpu.SetFields(self, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) gf1 = cpu.GetFields(self, ['hy', 'hz'], (1, 0, 0), (1, -1, -1)) sf1 = gpu.SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) gf2 = cpu.GetFields(self, ['ey', 'ez'], (1, 0, 0), (1, -1, -1)) sf2 = cpu.SetFields(self, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True) target_rank = rank - 1 tag_send, tag_recv = 1, 0 req_send = comm.Send_init(gf2.host_array, target_rank, tag=tag_send) tmp_recv_list = [ np.zeros(gf2.host_array.shape, gpuf.dtype) for i in range(2) ] req_recv_list = [ comm.Recv_init(tmp_recv, target_rank, tag=tag_recv) for tmp_recv in tmp_recv_list ] # global variables self.direction = direction self.gf0 = gf0 self.sf0 = sf0 self.gf1 = gf1 self.sf1 = sf1 self.gf2 = gf2 self.sf2 = sf2 self.req_send = req_send self.req_recv_list = req_recv_list self.tmp_recv_list = tmp_recv_list self.switch = 0 self.tmax = tmax self.tstep = 1 # global functions if direction == 'x+': self.update_e = self.update_e_xp self.update_h = self.update_h_xp elif direction == 'x-': self.update_e = self.update_e_xm self.update_h = self.update_h_xm