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: Union[device, int], f: Callable, *args, **kwargs)[源代码]
-
计算在CUDA上执行
f(*args, **kwargs)
所需的时间- 参数:
device (Union[torch.device, int]) –
f
运行的CUDA设备f (Callable) – 函数
- 返回:
用时,单位是毫秒
- 返回类型:
Returns the used time for calling
f(*args, **kwargs)
in CUDA- 参数:
device (Union[torch.device, int]) – on which cuda device that
f
is runningf (Callable) – a function
- 返回:
used time in milliseconds
- 返回类型:
- spikingjelly.activation_based.cuda_utils.cal_fun_t(n: int, device: Union[str, device, int], f: Callable, *args, **kwargs)[源代码]
-
测量在
device
上执行n
次f(*args, **kwargs)
的平均用时备注
当
n > 1
时,实际上会执行2n
次,然后返回后n
次的平均用时,以减小误差。- 参数:
n (int) – 重复的次数
device (Union[str, torch.device, int]) –
f
执行的设备,可以为 ‘cpu’ 或CUDA设备f (Callable) – 函数
- 返回:
用时,单位是毫秒
- 返回类型:
Returns the used time averaged by calling
f(*args, **kwargs)
overn
timesNote
If
n > 1
, this function will callf
for2n
times and return the average used time by the lastn
times to reduce the measure error.- 参数:
n (int) – repeat times
device (Union[str, torch.device, int]) – on which cuda device that
f
is 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.RawKernel
bykernel((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.Tensor
orcupy.ndarray
- 返回类型:
Makes
torch.Tensor
orcupy.ndarray
in*args
to 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
tuple
that contains args to callcupy.RawKernel
- 返回类型:
This function can wrap
torch.Tensor
orcupy.ndarray
toargs
incupy.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,), ...)