torch_utils.h 816 Bytes
Newer Older
1
2
3
#pragma once

#include <torch/csrc/inductor/aoti_torch/c/shim.h>
4
#include <torch/csrc/stable/accelerator.h>
5
#include <torch/csrc/stable/ops.h>
6
#include <torch/csrc/stable/tensor.h>
7
8
#include <torch/headeronly/util/shim_utils.h>

9
10
#include <cuda_runtime.h>

11
12
13
14
// Stable ABI equivalent of TORCH_CHECK_NOT_IMPLEMENTED.
#define STD_TORCH_CHECK_NOT_IMPLEMENTED(cond, ...) \
  STD_TORCH_CHECK(cond, "NotImplementedError: ", __VA_ARGS__)

15
16
// Utility to get the current CUDA stream for a given device using stable APIs.
// Returns a cudaStream_t for use in kernel launches.
17
inline cudaStream_t get_current_cuda_stream(int32_t device_index = -1) {
18
19
20
21
22
  void* stream_ptr = nullptr;
  TORCH_ERROR_CODE_CHECK(
      aoti_torch_get_current_cuda_stream(device_index, &stream_ptr));
  return reinterpret_cast<cudaStream_t>(stream_ptr);
}