torch.cuda

torch.cuda

表1 torch.cuda

序号

API名称

npu对应API名称

是否支持

1

torch.cuda.current_blas_handle

torch.npu.current_blas_handle

2

torch.cuda.current_device

torch.npu.current_device

3

torch.cuda.current_stream

torch_npu.npu.current_stream

4

torch.cuda.default_stream

torch.npu.default_stream

5

torch.cuda.device

torch_npu.npu.device

6

torch.cuda.device_count

torch.npu.device_count

7

torch.cuda.device_of

torch_npu.npu.device_of

8

torch.cuda.get_device_capability

torch.npu.get_device_capability

9

torch.cuda.get_device_name

torch.npu.get_device_name

10

torch.cuda.init

torch.npu.init

11

torch.cuda.ipc_collect

torch.npu.ipc_collect

12

torch.cuda.is_available

torch.npu.is_available

13

torch.cuda.is_initialized

torch.npu.is_initialized

14

torch.cuda.set_device

torch.npu.set_device

部分支持

15

torch.cuda.stream

torch.npu.stream

16

torch.cuda.synchronize

torch.npu.synchronize

torch.npu.set_device()接口只支持在程序开始的位置通过set_device进行指定,不支持多次指定和with torch.npu.device(id)方式的device切换

Random Number Generator

表2 Random Number Generator

序号

API名称

npu对应API名称

是否支持

1

torch.cuda.get_rng_state

torch.npu.get_rng_state

2

torch.cuda.get_rng_state_all

torch.npu.get_rng_state_all

3

torch.cuda.initial_seed

torch_npu.npu.initial_seed

4

torch.cuda.manual_seed

torch.npu.manual_seed

5

torch.cuda.manual_seed_all

torch_npu.npu.manual_seed_all

6

torch.cuda.seed

torch.npu.seed

7

torch.cuda.seed_all

torch_npu.npu.seed_all

8

torch.cuda.set_rng_state

torch.npu.set_rng_state

9

torch.cuda.set_rng_state_all

torch_npu.npu.set_rng_state_all

Communication collectives

表3 Communication collectives

序号

API名称

npu对应API名称

是否支持

1

torch.cuda.comm.broadcast

torch.npu.comm.broadcast

2

torch.cuda.comm.broadcast_coalesced

torch_npu.npu.comm.broadcast_coalesced

3

torch.cuda.comm.gather

torch.npu.comm.gather

4

torch.cuda.comm.reduce_add

torch_npu.npu.comm.reduce_add

5

torch.cuda.comm.scatter

torch.npu.comm.scatter

Streams and events

表4 Streams and events

序号

API名称

npu对应API名称

是否支持

1

torch.cuda.Event

torch_npu.npu.Event

是,不支持from_ipc_handle和ipc_handle

2

torch.cuda.Stream

torch.npu.Stream

Memory management

表5 Memory management

序号

API名称

npu对应API名称

是否支持

1

torch.cuda.empty_cache

torch_npu.npu.empty_cache

2

torch.cuda.max_memory_allocated

torch.npu.max_memory_allocated

3

torch.cuda.max_memory_cached

torch_npu.npu.max_memory_cached

4

torch.cuda.max_memory_reserved

torch.npu.max_memory_reserved

5

torch.cuda.memory_allocated

torch_npu.npu.memory_allocated

6

torch.cuda.memory_cached

torch.npu.memory_cached

7

torch.cuda.memory_reserved

torch.npu.memory_reserved

8

torch.cuda.memory_snapshot

torch_npu.npu.memory_snapshot

9

torch.cuda.memory_stats

torch.npu.memory_stats

10

torch.cuda.memory_summary

torch.npu.memory_summary

11

torch.cuda.reset_max_memory_allocated

torch_npu.npu.reset_max_memory_allocated

12

torch.cuda.reset_max_memory_cached

torch.npu.reset_max_memory_cached

NVIDIA Tools Extension (NVTX)

表6 NVIDIA Tools Extension

序号

API名称

npu对应API名称

是否支持

1

torch.cuda.nvtx.mark

torch.npu.nvtx.mark

2

torch.cuda.nvtx.range_pop

torch_npu.npu.nvtx.range_pop

3

torch.cuda.nvtx.range_push

torch.npu.nvtx.range_push