Dolphin CudaBase
CudaBase
- class dolphin.CudaBase[source]
Bases:
object
This class is mainly used to access device information, such as maximum number of threads per block, size of grid etc… This is a base class used by many other classes. It has a lot of class attributes in order not to load the same things again and again in order to speed up execution.
- device: pycuda._driver.Device
Used device
- max_threads_per_block: int
Maximum number of threads per blocks. Usually, it is 1024
- max_grid_dim_x: int
Maximum number of blocks per grid x on dim
- max_grid_dim_y: int
Maximum number of blocks per grid y on dim
- max_grid_dim_z: int
Maximum number of blocks per grid z on dim
- warp_size: int
Warp size
- multiprocessor_count: int
Number of MP
- threads_blocks_per_mp: int
Number of threads per MP
- static GET_BLOCK_GRID_1D(n: int) Tuple[Tuple[int, int, int], Tuple[int, int]] [source]
In ordert to perform memory coalescing on 1D iterations, we need to efficiently compute the block & grid sizes.
- Parameters:
n (int) – Number of elements to process
- Returns:
block, grid
- Return type:
Tuple[Tuple[int, int, int], Tuple[int, int]]
- static GET_BLOCK_X_Y(Z: int) Tuple[int, int, int] [source]
Get the block size for a given Z. The block size is calculated using the following formula: (max(ceil(sqrt(MAX_THREADS_PER_BLOCKS/Z)),1), max(ceil(sqrt(MAX_THREADS_PER_BLOCKS/Z)),1), Z)
It is useful to quickly compute the block size that suits self._max_threads_per_block for a given Z which can be channels, depth, batch size, etc.
- Parameters:
Z (int) – Size of the third dimension
- Returns:
Optimal block size that ensure block[0]*block[1]*block[2] <= self._max_threads_per_block
- Return type:
tuple
- static GET_GRID_SIZE(size: tuple, block: tuple) Tuple[int, int] [source]
Get the grid size for a given size and block size. The grid size is calculated using the following formula: (max(ceil(sqrt(size/block[0])),1), max(ceil(sqrt(size/block[1])),1))
This function should be used when the width and height of the image are the same or can be swapped.
- Parameters:
size (tuple) – Total size of data
block (tuple) – Current value of the block size
- Returns:
Grid size
- Return type:
tuple
- static GET_GRID_SIZE_HW(size: tuple, block: tuple) Tuple[int, int] [source]
Get the grid size for a given size and block size. The grid size is calculated using the following formula: (max(ceil(sqrt(size[0]/block[0])),1), max(ceil(sqrt(size[1]/block[1])),1))
This function should be used when the width and height of the image are different and matter.
- Parameters:
size (tuple) – Height and width of the image
block (tuple) – Current value of the block size
- Returns:
Grid size
- Return type:
tuple