Skip to content

Commit

Permalink
Merge pull request #50 from ROCm/hipify_runtime
Browse files Browse the repository at this point in the history
Hipify runtime API
  • Loading branch information
lcskrishna authored Apr 16, 2024
2 parents ea4910c + 8d7cc14 commit 9251fd2
Show file tree
Hide file tree
Showing 38 changed files with 1,373 additions and 1,747 deletions.
5 changes: 4 additions & 1 deletion cupy/_core/_accelerator.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime


cdef list _elementwise_accelerators = []
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/_cub_reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ from cupy._core cimport internal
from cupy.cuda cimport cub
from cupy.cuda cimport function
from cupy.cuda cimport memory
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime

import math
import string
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/_dtype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ cimport cython # NOQA
import numpy
import warnings

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime


all_type_chars = '?bhilqBHILQefdFD'
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/_fusion_kernel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ from cupy._core.core cimport _ndarray_base
from cupy._core cimport internal
from cupy._core cimport _routines_manipulation as _manipulation
from cupy_backends.cuda.api cimport driver
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime

import cupy as _cupy
from cupy._core import _dtype
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/_kernel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ from cupy._core.core cimport _ndarray_init
from cupy._core.core cimport compile_with_cache
from cupy._core.core cimport _ndarray_base
from cupy._core cimport internal
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime

try:
import cupy_backends.cuda.libs.cutensor as cuda_cutensor
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/_reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ from cupy._core.core cimport _ndarray_base
from cupy._core cimport internal
from cupy.cuda cimport device
from cupy.cuda cimport function
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime

import math
import string
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/_routines_linalg.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ from cupy._core cimport _memory_range
from cupy._core cimport _routines_manipulation as _manipulation
from cupy._core cimport _routines_math as _math
from cupy.cuda cimport device
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime


cdef extern from '../../cupy_backends/cupy_complex.h':
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/_routines_math.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import cupy._core.core as core
from cupy._core cimport internal
from cupy import _util

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy._core cimport _accelerator
from cupy._core._dtype cimport get_dtype
from cupy._core.core cimport _ndarray_init
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ from cupy.cuda cimport pinned_memory
from cupy.cuda cimport memory
from cupy.cuda cimport stream as stream_module
from cupy_backends.cuda cimport stream as _stream_module
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime


# If rop of cupy.ndarray is called, cupy's op is the last chance.
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/dlpack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ from libc.stdint cimport uint64_t
from libc.stdint cimport intptr_t
from libcpp.vector cimport vector

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy_backends.cuda cimport stream as stream_module
from cupy._core.core cimport _ndarray_base
from cupy.cuda cimport memory
Expand Down
5 changes: 4 additions & 1 deletion cupy/_core/raw.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import pickle
import cupy

from cupy_backends.cuda.api cimport driver
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy.cuda.function cimport Function, Module


Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/common.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy.cuda cimport device

import numpy
Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/cub.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from cpython cimport sequence
from libc.stdint cimport intptr_t

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy._core.core cimport _internal_ascontiguousarray
from cupy._core.internal cimport _contig_axes, is_in
from cupy.cuda cimport common
Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import threading

from cupy._core import syncdetect
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy_backends.cuda.api import runtime as runtime_module
from cupy import _util

Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ from libcpp cimport vector
from cupy._core cimport _carray
from cupy._core.core cimport _ndarray_base
from cupy_backends.cuda.api cimport driver
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy.cuda cimport stream as stream_module
from cupy.cuda.memory cimport MemoryPointer
from cupy.cuda.texture cimport TextureObject, SurfaceObject
Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/graph.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy_backends.cuda cimport stream as stream_module


Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/memory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ from cupy.cuda cimport device
from cupy.cuda cimport memory_hook
from cupy.cuda cimport stream as stream_module
from cupy_backends.cuda.api cimport driver
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime

from cupy_backends.cuda.api.runtime import CUDARuntimeError
from cupy import _util
Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/pinned_memory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ from fastrlock cimport rlock
from cupy_backends.cuda.api import runtime

from cupy._core cimport internal
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy import _util


Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/stream.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import threading

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy_backends.cuda cimport stream as backends_stream
from cupy.cuda cimport graph

Expand Down
5 changes: 4 additions & 1 deletion cupy/cuda/texture.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import numpy

from cupy._core.core cimport _ndarray_base
from cupy._core.core cimport _internal_ascontiguousarray
from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy_backends.cuda.api.runtime cimport Array, \
ChannelFormatDesc, ChannelFormatKind, \
Memcpy3DParms, MemoryKind, PitchedPtr, ResourceDesc, ResourceType, \
Expand Down
5 changes: 4 additions & 1 deletion cupy/fft/_cache.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import gc
import warnings
import weakref

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime

import threading

Expand Down
5 changes: 4 additions & 1 deletion cupy/fft/_callback.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from libc.stdint cimport intptr_t

from cupy_backends.cuda.api cimport runtime
IF CUPY_HIP_VERSION > 0:
from cupy_backends.cuda.api cimport runtime_hip as runtime
ELSE:
from cupy_backends.cuda.api cimport runtime
from cupy._core.core cimport _ndarray_base
from cupy.cuda.device cimport get_compute_capability

Expand Down
13 changes: 9 additions & 4 deletions cupy_backends/cuda/api/_runtime_enum.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ cpdef enum:
cudaLimitStackSize = 0x00
cudaLimitPrintfFifoSize = 0x01
cudaLimitMallocHeapSize = 0x02
cudaLimitDevRuntimeSyncDepth = 0x03
cudaLimitDevRuntimePendingLaunchCount = 0x04
cudaLimitMaxL2FetchGranularity = 0x05

# cudaChannelFormatKind
cudaChannelFormatKindSigned = 0
Expand Down Expand Up @@ -94,7 +91,6 @@ cpdef enum:
# cudaMemLocationType
cudaMemLocationTypeDevice = 1


# This was a legacy mistake: the prefix "cuda" should have been removed
# so that we can directly assign their C counterparts here. Now because
# of backward compatibility and no flexible Cython macro (IF/ELSE), we
Expand Down Expand Up @@ -228,6 +224,10 @@ IF CUPY_HIP_VERSION > 0:
ELSE:
# For CUDA/RTD
cpdef enum:
cudaLimitDevRuntimeSyncDepth = 0x03
cudaLimitDevRuntimePendingLaunchCount = 0x04
cudaLimitMaxL2FetchGranularity = 0x05

cudaDevAttrMaxThreadsPerBlock = 1
cudaDevAttrMaxBlockDimX
cudaDevAttrMaxBlockDimY
Expand Down Expand Up @@ -343,3 +343,8 @@ ELSE:
cudaDevAttrGPUDirectRDMAFlushWritesOptions
cudaDevAttrGPUDirectRDMAWritesOrdering
cudaDevAttrMemoryPoolSupportedHandleTypes

IF CUPY_HIP_VERSION > 0:
cpdef enum:
hipIpcMemLazyEnablePeerAccess = 1
hipMemAttachGlobal = 1
3 changes: 3 additions & 0 deletions cupy_backends/cuda/api/_runtime_typedef.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ cdef extern from *:
ctypedef int MemAllocationType 'cudaMemAllocationType'
ctypedef int MemAllocationHandleType 'cudaMemAllocationHandleType'
ctypedef int MemLocationType 'cudaMemLocationType'
IF CUPY_HIP_VERSION > 0:
ctypedef int MemoryType 'hipMemoryType'

IF CUPY_CUDA_VERSION > 0:
# This is for the annoying nested struct, which is not
# perfectly supprted in Cython
Expand Down
Loading

0 comments on commit 9251fd2

Please sign in to comment.