Exemple #1
0
 def set_field_states(self, h_field_states):
     """Copy field states from host to device memory."""
     if not self.is_ready():
         raise Exception('CUDA has not been initialised')
     else:
         float_t = get_float_type(self.params.code)
         if str(h_field_states.dtype) != float_t:
             # TODO: ERROR!!
             pass
         set_field_states_fn = self._mod.get_function('set_field_states')
         timer = Timer("set_fs_cpy")
         cuda.memcpy_htod(self._d_field_states, h_field_states)
         timer = Timer("set_fs_fn")
         set_field_states_fn(self._d_field_states,
                             self._d_states,
                             block=self._get_block(),
                             grid=self._get_grid())
Exemple #2
0
 def set_field_states(self, h_field_states):
     if not self.is_ready():
         raise Exception("CUDA has not been initialised")
     else:
         float_t = get_float_type(self.params.code)
         if str(h_field_states.dtype) != float_t:
             # TODO: ERROR!!
             pass
         set_field_states_fn = self._mod.get_function("set_field_states")
         timer = Timer("set_fs_cpy")  # noqa: F841
         cuda.memcpy_htod(self._d_field_states, h_field_states)
         timer = Timer("set_fs_fn")  # noqa: F841
         set_field_states_fn(
             self._d_field_states,
             self._d_states,
             block=self._get_block(),
             grid=self._get_grid(),
         )
Exemple #3
0
 def forward(self, t, dt, update_host_states=False, synchronize=True):
     if not self.is_ready():
         raise Exception("CUDA has not been initialised")
     else:
         timer = Timer("calculate CUDA forward")
         args = [self._d_states, t, dt, self._d_parameters]
         field_parameters = self.params.code.parameters.field_parameters
         # FIXME: modelparameters needs a ListParam
         if len(field_parameters) != 1 or field_parameters[0] != "":
             args.append(self._d_field_parameters)
         args.append(np.uint32(self.num_nodes))
         self._forward_fn(*args,
                          block=self._get_block(),
                          grid=self._get_grid())
         if synchronize:
             self.ctx.synchronize()
         if update_host_states:
             timer = Timer("update host states")  # noqa: F841
             cuda.memcpy_dtoh(self._h_states, self._d_states)
Exemple #4
0
    def forward(self, t, dt, update_host_states=False, synchronize=True):
        """Solve one time step of the ODE system on GPU"""
        if not self.is_ready():
            raise Exception('CUDA has not been initialised')
        else:
            timer = Timer("calculate CUDA forward")
            args = [self._d_states, t, dt, self._d_parameters]
            field_parameters = self.params.code.parameters.field_parameters

            # FIXME: modelparameters needs a ListParam
            if not (len(field_parameters)==0 or (len(field_parameters) == 1 \
                                                 and field_parameters[0] == "")):
                args.append(self._d_field_parameters)
            args.append(np.uint32(self.num_nodes))
            self._forward_fn(*args,
                             block=self._get_block(),
                             grid=self._get_grid())
            if synchronize:
                self.ctx.synchronize()
            if update_host_states:
                timer = Timer("update host states")
                cuda.memcpy_dtoh(self._h_states, self._d_states)
Exemple #5
0
 def set_field_states(self, field_states=None):
     timer = Timer("set field states")  # noqa: F841
     field_states = field_states if field_states is not None else self.field_states
     if field_states is not None:
         self._cudahandler.set_field_states(field_states)
Exemple #6
0
 def set_field_states(self, field_states=None):
     """Copy current host field states onto the device."""
     timer = Timer("set field states")
     field_states = field_states if field_states is not None else self.field_states
     if field_states is not None:
         self._cudahandler.set_field_states(field_states)