spikingjelly.activation_based.cuda_utils package
Module contents
- spikingjelly.activation_based.cuda_utils.cpu_timer(f: Callable, *args, **kwargs)[源代码]
-
计算在CPU上执行
f(*args, **kwargs)所需的时间- 参数
f (Callable) – 函数
- 返回
用时,单位是毫秒
- 返回类型
Returns the used time for calling
f(*args, **kwargs)in CPU- 参数
f (Callable) – a function
- 返回
used time in milliseconds
- 返回类型
- spikingjelly.activation_based.cuda_utils.cuda_timer(device: device, f: Callable, *args, **kwargs)[源代码]
-
计算在CUDA上执行
f(*args, **kwargs)所需的时间- 参数
device (torch.device or int) –
f运行的CUDA设备f (Callable) – 函数
- 返回
用时,单位是毫秒
- 返回类型
Returns the used time for calling
f(*args, **kwargs)in CUDA- 参数
device (torch.device or int) – on which cuda device that
fis runningf (Callable) – a function
- 返回
used time in milliseconds
- 返回类型
- spikingjelly.activation_based.cuda_utils.cal_fun_t(n: int, device: str, f: Callable, *args, **kwargs)[源代码]
-
测量在
device上执行n次f(*args, **kwargs)的平均用时备注
当
n > 1时,实际上会执行2n次,然后返回后n次的平均用时,以减小误差。- 参数
n (int) – 重复的次数
device (str or torch.device or int) –
f执行的设备,可以为 ‘cpu’ 或CUDA设备f (Callable) – 函数
- 返回
用时,单位是毫秒
- 返回类型
Returns the used time averaged by calling
f(*args, **kwargs)overntimesNote
If
n > 1, this function will callffor2ntimes and return the average used time by the lastntimes to reduce the measure error.- 参数
n (int) – repeat times
device (str or torch.device or int) – on which cuda device that
fis running. It can be ‘cpu’ or a cuda deivcef (Callable) – function
- 返回
used time in milliseconds
- 返回类型
- spikingjelly.activation_based.cuda_utils.cal_blocks(numel: int, threads: int = -1)[源代码]
-
- 参数
- 返回
blocks的数量
- 返回类型
此函数返回 blocks的数量,用来按照
kernel((blocks,), (configure.cuda_threads,), ...)调用cupy.RawKernel- 参数
- 返回
the number of blocks
- 返回类型
Returns the number of blocks to call
cupy.RawKernelbykernel((blocks,), (threads,), ...)
- spikingjelly.activation_based.cuda_utils.get_contiguous(*args)[源代码]
-
将
*args中所有的torch.Tensor或cupy.ndarray进行连续化。备注
连续化的操作无法in-place,因此本函数返回一个新的list。
- 返回
一个元素全部为连续的
torch.Tensor或cupy.ndarray的list- 返回类型
- 返回
a list that contains the contiguous
torch.Tensororcupy.ndarray- 返回类型
Makes
torch.Tensororcupy.ndarrayin*argsto be contiguousNote
The making contiguous operation can not be done in-place. Hence, this function will return a new list.
- spikingjelly.activation_based.cuda_utils.wrap_args_to_raw_kernel(device: int, *args)[源代码]
-
此函数可以包装
torch.Tensor和cupy.ndarray并将其作为cupy.RawKernel.__call__的args- 参数
device (int) – on which CUDA device the raw kernel will run
- 返回
a
tuplethat contains args to callcupy.RawKernel- 返回类型
This function can wrap
torch.Tensororcupy.ndarraytoargsincupy.RawKernel.__call__
- class spikingjelly.activation_based.cuda_utils.DeviceEnvironment(device: int)[源代码]
基类:
object这个模块可以被用作在指定的
device上执行CuPy函数的上下文,用来避免 torch.cuda.current_device() 被CuPy意外改变( https://github.com/cupy/cupy/issues/6569 )。代码示例:
with DeviceEnvironment(device): kernel((blocks,), (configure.cuda_threads,), ...)
- 参数
device (int) – the CUDA device
This module is used as a context to make CuPy use the specific device, and avoids torch.cuda.current_device() is changed by CuPy ( https://github.com/cupy/cupy/issues/6569 ).
Codes example:
with DeviceEnvironment(device): kernel((blocks,), (configure.cuda_threads,), ...)