Esempio n. 1
0
 def _allocate(self,
               where,
               obj=None,
               dtype=None,
               shape=None,
               strides=None,
               copy=True):
     if dtype:
         dtype = np.dtype(dtype)
     if where == 'host':
         if obj is not None:
             self._host = np.array(obj, dtype, copy=copy)
         else:
             self._host = np.empty(shape, dtype,
                                   _s2o(dtype, shape, strides))
     else:
         # Don't import this at module-scope as it may not be available
         # in all environments (e.g., CUDASIM)
         from numba.cuda.cudadrv import devicearray as da
         if obj is not None:
             # If 'obj' is an array-like object but not an ndarray,
             # construct an ndarray first to extract all the parameters we need.
             if not isinstance(obj, np.ndarray):
                 obj = np.array(obj, copy=False)
             self._gpu = da.from_array_like(obj)
         else:
             if strides is None:
                 strides = _o2s(dtype, shape, 'C')
             self._gpu = da.DeviceNDArray(shape, strides, dtype)
Esempio n. 2
0
 def _broadcast_add_axis(self, ary, newshape):
     newax = len(newshape) - len(ary.shape)
     # Add 0 strides for missing dimension
     newstrides = (0,) * newax + ary.strides
     return devicearray.DeviceNDArray(shape=newshape,
                                      strides=newstrides,
                                      dtype=ary.dtype,
                                      gpu_data=ary.gpu_data)
Esempio n. 3
0
    def test_devicearray_relaxed_strides(self):
        # From the reproducer in Issue #6824.

        # Construct a device array that is contiguous even though
        # the strides for the first axis (800) are not equal to
        # the strides * size (10 * 8 = 80) for the previous axis,
        # because the first axis size is 1.
        arr = devicearray.DeviceNDArray((1, 10), (800, 8), np.float64)

        # Ensure we still believe the array to be contiguous because
        # strides checking is relaxed.
        self.assertTrue(arr.flags['C_CONTIGUOUS'])
        self.assertTrue(arr.flags['F_CONTIGUOUS'])
Esempio n. 4
0
    def test_devicearray_strict_strides(self):
        # From the reproducer in Issue #6824.

        with override_config('NPY_RELAXED_STRIDES_CHECKING', 0):
            # Construct a device array that is not contiguous because
            # the strides for the first axis (800) are not equal to
            # the strides * size (10 * 8 = 80) for the previous axis.
            arr = devicearray.DeviceNDArray((1, 10), (800, 8), np.float64)

            # Ensure we don't believe the array to be contiguous becase strides
            # checking is strict.
            self.assertFalse(arr.flags['C_CONTIGUOUS'])
            self.assertFalse(arr.flags['F_CONTIGUOUS'])
Esempio n. 5
0
    def broadcast_device(self, ary, shape):
        ax_differs = [ax for ax in range(len(shape))
                      if ax >= ary.ndim
                      or ary.shape[ax] != shape[ax]]

        missingdim = len(shape) - len(ary.shape)
        strides = [0] * missingdim + list(ary.strides)

        for ax in ax_differs:
            strides[ax] = 0

        return devicearray.DeviceNDArray(shape=shape,
                                         strides=strides,
                                         dtype=ary.dtype,
                                         gpu_data=ary.gpu_data)
Esempio n. 6
0
 def _broadcast_scalar_input(self, ary, shape):
     return devicearray.DeviceNDArray(shape=shape,
                                      strides=(0,),
                                      dtype=ary.dtype,
                                      gpu_data=ary.gpu_data)