Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jerrrrry
infinicore
Commits
9bc9ca91
Commit
9bc9ca91
authored
Feb 17, 2025
by
Pan Zezhong
Browse files
issue/42: 创建infiniop handle不再传入device_id
parent
643fdd2b
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
89 additions
and
109 deletions
+89
-109
include/infiniop/handle.h
include/infiniop/handle.h
+1
-1
src/infiniop/devices/ascend/ascend_handle.cc
src/infiniop/devices/ascend/ascend_handle.cc
+4
-10
src/infiniop/devices/ascend/ascend_handle.h
src/infiniop/devices/ascend/ascend_handle.h
+1
-2
src/infiniop/devices/ascend/common_ascend.h
src/infiniop/devices/ascend/common_ascend.h
+7
-0
src/infiniop/devices/bang/bang_handle.cc
src/infiniop/devices/bang/bang_handle.cc
+3
-8
src/infiniop/devices/bang/bang_handle.h
src/infiniop/devices/bang/bang_handle.h
+1
-2
src/infiniop/devices/bang/common_bang.h
src/infiniop/devices/bang/common_bang.h
+1
-1
src/infiniop/devices/cuda/common_cuda.cuh
src/infiniop/devices/cuda/common_cuda.cuh
+48
-50
src/infiniop/devices/cuda/cuda_handle.cu
src/infiniop/devices/cuda/cuda_handle.cu
+6
-14
src/infiniop/devices/cuda/cuda_handle.h
src/infiniop/devices/cuda/cuda_handle.h
+1
-1
src/infiniop/devices/handle.cc
src/infiniop/devices/handle.cc
+4
-10
src/infiniop/ops/matmul/bang/matmul_cnnl.cc
src/infiniop/ops/matmul/bang/matmul_cnnl.cc
+4
-4
src/infiniop/ops/matmul/bang/matmul_cnnl.h
src/infiniop/ops/matmul/bang/matmul_cnnl.h
+1
-1
src/infiniop/ops/matmul/cuda/matmul_cuda.cu
src/infiniop/ops/matmul/cuda/matmul_cuda.cu
+2
-2
src/infiniop/ops/matmul/cuda/matmul_cuda.cuh
src/infiniop/ops/matmul/cuda/matmul_cuda.cuh
+1
-1
src/infiniop/ops/matmul/cuda/matmul_cuda_kernel.cu
src/infiniop/ops/matmul/cuda/matmul_cuda_kernel.cu
+1
-1
test/infiniop/libinfiniop/utils.py
test/infiniop/libinfiniop/utils.py
+2
-0
test/infiniop/matmul.py
test/infiniop/matmul.py
+1
-1
No files found.
include/infiniop/handle.h
View file @
9bc9ca91
...
@@ -11,7 +11,7 @@ typedef struct InfiniopHandle {
...
@@ -11,7 +11,7 @@ typedef struct InfiniopHandle {
typedef
InfiniopHandle
*
infiniopHandle_t
;
typedef
InfiniopHandle
*
infiniopHandle_t
;
__C
__export
infiniopStatus_t
infiniopCreateHandle
(
infiniopHandle_t
*
handle_ptr
,
infiniDevice_t
device
,
int
device_id
);
__C
__export
infiniopStatus_t
infiniopCreateHandle
(
infiniopHandle_t
*
handle_ptr
,
infiniDevice_t
device
);
__C
__export
infiniopStatus_t
infiniopDestroyHandle
(
infiniopHandle_t
handle
);
__C
__export
infiniopStatus_t
infiniopDestroyHandle
(
infiniopHandle_t
handle
);
...
...
src/infiniop/devices/ascend/ascend_handle.cc
View file @
9bc9ca91
#include "common_ascend.h"
#include "common_ascend.h"
infiniopStatus_t
createAscendHandle
(
infiniopAscendHandle_t
*
handle_ptr
,
infiniopStatus_t
createAscendHandle
(
infiniopAscendHandle_t
*
handle_ptr
)
{
int
device_id
)
{
int
device_id
=
0
;
uint32_t
device_count
;
auto
ret
=
aclrtGetDevice
(
&
device_id
);
aclrtGetDeviceCount
(
&
device_count
);
if
(
device_id
>=
static_cast
<
int
>
(
device_count
))
{
return
INFINIOP_STATUS_BAD_DEVICE
;
}
auto
ret
=
aclrtSetDevice
(
device_id
);
CHECK_RET
(
ret
==
ACL_SUCCESS
,
CHECK_RET
(
ret
==
ACL_SUCCESS
,
LOG_
PRINT
(
"aclrt
S
etDevice failed. ERROR: %d
\n
"
,
ret
));
LOG_
ERROR
(
"aclrt
G
etDevice failed. ERROR: %d
\n
"
,
ret
));
*
handle_ptr
=
new
InfiniopAscendHandle
{
INFINI_DEVICE_ASCEND
,
device_id
};
*
handle_ptr
=
new
InfiniopAscendHandle
{
INFINI_DEVICE_ASCEND
,
device_id
};
...
...
src/infiniop/devices/ascend/ascend_handle.h
View file @
9bc9ca91
...
@@ -7,8 +7,7 @@
...
@@ -7,8 +7,7 @@
struct
InfiniopAscendHandle
;
struct
InfiniopAscendHandle
;
typedef
struct
InfiniopAscendHandle
*
infiniopAscendHandle_t
;
typedef
struct
InfiniopAscendHandle
*
infiniopAscendHandle_t
;
infiniopStatus_t
createAscendHandle
(
infiniopAscendHandle_t
*
handle_ptr
,
infiniopStatus_t
createAscendHandle
(
infiniopAscendHandle_t
*
handle_ptr
);
int
device_id
);
infiniopStatus_t
destroyAscendHandle
(
infiniopAscendHandle_t
handle_ptr
);
infiniopStatus_t
destroyAscendHandle
(
infiniopAscendHandle_t
handle_ptr
);
...
...
src/infiniop/devices/ascend/common_ascend.h
View file @
9bc9ca91
...
@@ -28,6 +28,13 @@ extern "C" {
...
@@ -28,6 +28,13 @@ extern "C" {
printf(message, ##__VA_ARGS__); \
printf(message, ##__VA_ARGS__); \
} while (0)
} while (0)
#define LOG_ERROR(message, ...) \
do { \
printf(message, ##__VA_ARGS__); \
return INFINIOP_STATUS_INTERNAL_ERROR; \
} while (0)
#ifdef __cplusplus
#ifdef __cplusplus
};
};
#endif
#endif
...
...
src/infiniop/devices/bang/bang_handle.cc
View file @
9bc9ca91
...
@@ -2,18 +2,13 @@
...
@@ -2,18 +2,13 @@
#include "common_bang.h"
#include "common_bang.h"
#include <memory>
#include <memory>
infiniopStatus_t
createBangHandle
(
infiniopBangHandle_t
*
handle_ptr
,
infiniopStatus_t
createBangHandle
(
infiniopBangHandle_t
*
handle_ptr
)
{
int
device_id
)
{
int
device_id
=
0
;
unsigned
int
device_count
;
if
(
cnrtGetDevice
(
&
device_id
)
!=
cnrtSuccess
)
{
cnrtGetDeviceCount
(
&
device_count
);
if
(
device_id
>=
static_cast
<
int
>
(
device_count
))
{
return
INFINIOP_STATUS_BAD_DEVICE
;
return
INFINIOP_STATUS_BAD_DEVICE
;
}
}
auto
pool
=
std
::
make_shared
<
Pool
<
cnnlHandle_t
>>
();
auto
pool
=
std
::
make_shared
<
Pool
<
cnnlHandle_t
>>
();
if
(
cnrtSetDevice
(
device_id
)
!=
cnrtSuccess
)
{
return
INFINIOP_STATUS_BAD_DEVICE
;
}
cnnlHandle_t
handle
;
cnnlHandle_t
handle
;
cnnlCreate
(
&
handle
);
cnnlCreate
(
&
handle
);
pool
->
push
(
std
::
move
(
handle
));
pool
->
push
(
std
::
move
(
handle
));
...
...
src/infiniop/devices/bang/bang_handle.h
View file @
9bc9ca91
...
@@ -6,8 +6,7 @@
...
@@ -6,8 +6,7 @@
struct
InfiniopBangHandle
;
struct
InfiniopBangHandle
;
typedef
struct
InfiniopBangHandle
*
infiniopBangHandle_t
;
typedef
struct
InfiniopBangHandle
*
infiniopBangHandle_t
;
infiniopStatus_t
createBangHandle
(
infiniopBangHandle_t
*
handle_ptr
,
infiniopStatus_t
createBangHandle
(
infiniopBangHandle_t
*
handle_ptr
);
int
device_id
);
infiniopStatus_t
destroyBangHandle
(
infiniopBangHandle_t
handle
);
infiniopStatus_t
destroyBangHandle
(
infiniopBangHandle_t
handle
);
#endif
#endif
src/infiniop/devices/bang/common_bang.h
View file @
9bc9ca91
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
struct
InfiniopBangHandle
{
struct
InfiniopBangHandle
{
infiniDevice_t
device
;
infiniDevice_t
device
;
int
device_id
;
int
device_id
;
std
::
shared_ptr
<
Pool
<
cnnlHandle_t
>>
cnnl_handle
s
;
std
::
shared_ptr
<
Pool
<
cnnlHandle_t
>>
cnnl_handle
_pool
;
};
};
inline
cnnlDataType_t
cnnlDataTypeConvert
(
infiniDtype_t
dataType
)
{
inline
cnnlDataType_t
cnnlDataTypeConvert
(
infiniDtype_t
dataType
)
{
...
...
src/infiniop/devices/cuda/common_cuda.cuh
View file @
9bc9ca91
...
@@ -7,91 +7,89 @@
...
@@ -7,91 +7,89 @@
#include <iostream>
#include <iostream>
#define
checkCudaErrorWithCode
(call, errorCode) \
#define
CHECK_CUDA_OR_RETURN
(call, errorCode)
\
do {
\
do { \
if (auto status = call; status != cudaSuccess) {
\
if (auto status = call; status != cudaSuccess) { \
std::cerr << "CUDA error: " << cudaGetErrorString(status)
\
std::cerr << "CUDA error: " << cudaGetErrorString(status) \
<< " in file " << __FILE__ << ", function " << __func__
\
<< " in file " << __FILE__ << ", function " << __func__ \
<< ", line " << __LINE__ << std::endl;
\
<< ", line " << __LINE__ << std::endl; \
return errorCode;
\
return errorCode; \
}
\
} \
} while (0)
} while (0)
#define
checkCudaError(call) checkCudaErrorWithCode
(call, INFINIOP_STATUS_
BAD_DEVICE
)
#define
CHECK_CUDA(call) CHECK_CUDA_OR_RETURN
(call, INFINIOP_STATUS_
INTERNAL_ERROR
)
#define
checkCudnnError
(call) \
#define
CHECK_CUDNN
(call)
\
do {
\
do { \
if (auto status = call; status != CUDNN_STATUS_SUCCESS) {
\
if (auto status = call; status != CUDNN_STATUS_SUCCESS) { \
std::cerr << "CUDNN error: " << cudnnGetErrorString(status)
\
std::cerr << "CUDNN error: " << cudnnGetErrorString(status) \
<< " in file " << __FILE__ << ", function " << __func__
\
<< " in file " << __FILE__ << ", function " << __func__ \
<< ", line " << __LINE__ << std::endl;
\
<< ", line " << __LINE__ << std::endl; \
return INFINIOP_STATUS_INTERNAL_ERROR;
\
return INFINIOP_STATUS_INTERNAL_ERROR; \
}
\
} \
} while (0)
} while (0)
#include "infinicore.h"
#include <cudnn.h>
#include <cublas_v2.h>
#include <memory>
#include "../pool.h"
#include "../pool.h"
#include "cuda_handle.h"
#include "cuda_handle.h"
#include "infinicore.h"
#include <cublas_v2.h>
#include <cuda_fp16.h>
#include <cuda_fp16.h>
#include <cudnn.h>
#include <memory>
struct
InfiniopCudaHandle
{
struct
InfiniopCudaHandle
{
infiniDevice_t
device
;
infiniDevice_t
device
;
int
device_id
;
int
device_id
;
std
::
shared_ptr
<
Pool
<
cublasHandle_t
>>
cublas_handle
s_t
;
std
::
shared_ptr
<
Pool
<
cublasHandle_t
>>
cublas_handle
_pool
;
std
::
shared_ptr
<
Pool
<
cudnnHandle_t
>>
cudnn_handle
s_t
;
std
::
shared_ptr
<
Pool
<
cudnnHandle_t
>>
cudnn_handle
_pool
;
cudaDeviceProp
prop
;
cudaDeviceProp
prop
;
int
compute_capability_major
;
int
compute_capability_major
;
int
compute_capability_minor
;
int
compute_capability_minor
;
};
};
template
<
typename
T
>
template
<
typename
T
>
void
use_cublas
(
std
::
shared_ptr
<
Pool
<
cublasHandle_t
>>
cublas_handle
s_t
,
int
device_id
,
cudaStream_t
stream
,
T
const
&
f
)
{
void
use_cublas
(
std
::
shared_ptr
<
Pool
<
cublasHandle_t
>>
cublas_handle
_pool
,
int
device_id
,
cudaStream_t
stream
,
T
const
&
f
)
{
auto
handle
=
cublas_handle
s_t
->
pop
();
auto
handle
=
cublas_handle
_pool
->
pop
();
if
(
!
handle
)
{
if
(
!
handle
)
{
cudaSetDevice
(
device_id
);
cublasCreate
(
&
(
*
handle
));
cublasCreate
(
&
(
*
handle
));
}
}
cublasSetStream
(
*
handle
,
(
cudaStream_t
)
stream
);
cublasSetStream
(
*
handle
,
(
cudaStream_t
)
stream
);
f
(
*
handle
);
f
(
*
handle
);
cublas_handle
s_t
->
push
(
std
::
move
(
*
handle
));
cublas_handle
_pool
->
push
(
std
::
move
(
*
handle
));
}
}
template
<
typename
T
>
template
<
typename
T
>
cudnnStatus_t
use_cudnn
(
std
::
shared_ptr
<
Pool
<
cudnnHandle_t
>>
cudnn_handle
s_t
,
int
device_id
,
cudaStream_t
stream
,
T
const
&
f
)
{
cudnnStatus_t
use_cudnn
(
std
::
shared_ptr
<
Pool
<
cudnnHandle_t
>>
cudnn_handle
_pool
,
int
device_id
,
cudaStream_t
stream
,
T
const
&
f
)
{
auto
handle
=
cudnn_handle
s_t
->
pop
();
auto
handle
=
cudnn_handle
_pool
->
pop
();
if
(
!
handle
)
{
if
(
!
handle
)
{
cudaSetDevice
(
device_id
);
cudnnCreate
(
&
(
*
handle
));
cudnnCreate
(
&
(
*
handle
));
}
}
cudnnSetStream
(
*
handle
,
stream
);
cudnnSetStream
(
*
handle
,
stream
);
cudnnStatus_t
status
=
f
(
*
handle
);
cudnnStatus_t
status
=
f
(
*
handle
);
cudnn_handle
s_t
->
push
(
std
::
move
(
*
handle
));
cudnn_handle
_pool
->
push
(
std
::
move
(
*
handle
));
return
status
;
return
status
;
}
}
inline
cudnnDataType_t
getCudnnDtype
(
infiniDtype_t
dt
)
{
inline
cudnnDataType_t
getCudnnDtype
(
infiniDtype_t
dt
)
{
switch
(
dt
)
{
switch
(
dt
)
{
case
INFINI_DTYPE_F16
:
case
INFINI_DTYPE_F16
:
return
CUDNN_DATA_HALF
;
return
CUDNN_DATA_HALF
;
case
INFINI_DTYPE_F32
:
case
INFINI_DTYPE_F32
:
return
CUDNN_DATA_FLOAT
;
return
CUDNN_DATA_FLOAT
;
case
INFINI_DTYPE_F64
:
case
INFINI_DTYPE_F64
:
return
CUDNN_DATA_DOUBLE
;
return
CUDNN_DATA_DOUBLE
;
case
INFINI_DTYPE_BF16
:
case
INFINI_DTYPE_BF16
:
return
CUDNN_DATA_BFLOAT16
;
return
CUDNN_DATA_BFLOAT16
;
case
INFINI_DTYPE_I8
:
case
INFINI_DTYPE_I8
:
return
CUDNN_DATA_INT8
;
return
CUDNN_DATA_INT8
;
case
INFINI_DTYPE_I32
:
case
INFINI_DTYPE_I32
:
return
CUDNN_DATA_INT32
;
return
CUDNN_DATA_INT32
;
case
INFINI_DTYPE_I64
:
case
INFINI_DTYPE_I64
:
return
CUDNN_DATA_INT64
;
return
CUDNN_DATA_INT64
;
case
INFINI_DTYPE_U8
:
case
INFINI_DTYPE_U8
:
return
CUDNN_DATA_UINT8
;
return
CUDNN_DATA_UINT8
;
default:
default:
return
CUDNN_DATA_FLOAT
;
return
CUDNN_DATA_FLOAT
;
}
}
}
}
...
@@ -120,4 +118,4 @@ inline __device__ __host__ size_t indexToOffset(size_t flat_index, size_t ndim,
...
@@ -120,4 +118,4 @@ inline __device__ __host__ size_t indexToOffset(size_t flat_index, size_t ndim,
return
res
;
return
res
;
}
}
#endif
// __INFINIOP_COMMON_CUDA_H__
#endif// __INFINIOP_COMMON_CUDA_H__
src/infiniop/devices/cuda/cuda_handle.cu
View file @
9bc9ca91
#include "./common_cuda.cuh"
#include "./common_cuda.cuh"
infiniopStatus_t
createCudaHandle
(
infiniopCudaHandle_t
*
handle_ptr
,
int
device_id
,
infiniDevice_t
cuda_device_type
)
{
infiniopStatus_t
createCudaHandle
(
infiniopCudaHandle_t
*
handle_ptr
,
infiniDevice_t
cuda_device_type
)
{
// Check if device_id is valid
int
device_count
;
cudaGetDeviceCount
(
&
device_count
);
if
(
device_id
>=
device_count
)
{
return
INFINIOP_STATUS_BAD_DEVICE
;
}
// Create a new cublas handle pool
// Create a new cublas handle pool
int
device_id
=
0
;
CHECK_CUDA
(
cudaGetDevice
(
&
device_id
));
auto
pool
=
std
::
make_shared
<
Pool
<
cublasHandle_t
>>
();
auto
pool
=
std
::
make_shared
<
Pool
<
cublasHandle_t
>>
();
if
(
cudaSetDevice
(
device_id
)
!=
cudaSuccess
)
{
return
INFINIOP_STATUS_BAD_DEVICE
;
}
cublasHandle_t
handle
;
cublasHandle_t
handle
;
cublasCreate
(
&
handle
);
cublasCreate
(
&
handle
);
pool
->
push
(
std
::
move
(
handle
));
pool
->
push
(
std
::
move
(
handle
));
...
@@ -20,7 +12,7 @@ infiniopStatus_t createCudaHandle(infiniopCudaHandle_t *handle_ptr, int device_i
...
@@ -20,7 +12,7 @@ infiniopStatus_t createCudaHandle(infiniopCudaHandle_t *handle_ptr, int device_i
// create a cudnn handle pool
// create a cudnn handle pool
auto
cudnn_pool
=
std
::
make_shared
<
Pool
<
cudnnHandle_t
>>
();
auto
cudnn_pool
=
std
::
make_shared
<
Pool
<
cudnnHandle_t
>>
();
cudnnHandle_t
cudnn_handle
;
cudnnHandle_t
cudnn_handle
;
checkCudnnError
(
cudnnCreate
(
&
cudnn_handle
));
CHECK_CUDNN
(
cudnnCreate
(
&
cudnn_handle
));
cudnn_pool
->
push
(
std
::
move
(
cudnn_handle
));
cudnn_pool
->
push
(
std
::
move
(
cudnn_handle
));
// set CUDA device property
// set CUDA device property
...
@@ -47,8 +39,8 @@ infiniopStatus_t createCudaHandle(infiniopCudaHandle_t *handle_ptr, int device_i
...
@@ -47,8 +39,8 @@ infiniopStatus_t createCudaHandle(infiniopCudaHandle_t *handle_ptr, int device_i
}
}
infiniopStatus_t
destroyCudaHandle
(
infiniopCudaHandle_t
handle_ptr
)
{
infiniopStatus_t
destroyCudaHandle
(
infiniopCudaHandle_t
handle_ptr
)
{
handle_ptr
->
cublas_handle
s_t
=
nullptr
;
handle_ptr
->
cublas_handle
_pool
=
nullptr
;
handle_ptr
->
cudnn_handle
s_t
=
nullptr
;
handle_ptr
->
cudnn_handle
_pool
=
nullptr
;
delete
handle_ptr
;
delete
handle_ptr
;
return
INFINIOP_STATUS_SUCCESS
;
return
INFINIOP_STATUS_SUCCESS
;
...
...
src/infiniop/devices/cuda/cuda_handle.h
View file @
9bc9ca91
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
struct
InfiniopCudaHandle
;
struct
InfiniopCudaHandle
;
typedef
struct
InfiniopCudaHandle
*
infiniopCudaHandle_t
;
typedef
struct
InfiniopCudaHandle
*
infiniopCudaHandle_t
;
infiniopStatus_t
createCudaHandle
(
infiniopCudaHandle_t
*
handle_ptr
,
int
device_id
,
infiniDevice_t
cuda_device_type
);
infiniopStatus_t
createCudaHandle
(
infiniopCudaHandle_t
*
handle_ptr
,
infiniDevice_t
cuda_device_type
);
infiniopStatus_t
destroyCudaHandle
(
infiniopCudaHandle_t
handle_ptr
);
infiniopStatus_t
destroyCudaHandle
(
infiniopCudaHandle_t
handle_ptr
);
...
...
src/infiniop/devices/handle.cc
View file @
9bc9ca91
...
@@ -13,14 +13,10 @@
...
@@ -13,14 +13,10 @@
#endif
#endif
__C
infiniopStatus_t
infiniopCreateHandle
(
infiniopHandle_t
*
handle_ptr
,
__C
infiniopStatus_t
infiniopCreateHandle
(
infiniopHandle_t
*
handle_ptr
,
infiniDevice_t
device
,
infiniDevice_t
device
)
{
int
device_id
)
{
if
(
handle_ptr
==
nullptr
)
{
if
(
handle_ptr
==
nullptr
)
{
return
INFINIOP_STATUS_NULL_POINTER
;
return
INFINIOP_STATUS_NULL_POINTER
;
}
}
if
(
device_id
<
0
)
{
return
INFINIOP_STATUS_BAD_DEVICE
;
}
switch
(
device
)
{
switch
(
device
)
{
#ifdef ENABLE_CPU_API
#ifdef ENABLE_CPU_API
...
@@ -29,19 +25,17 @@ __C infiniopStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr,
...
@@ -29,19 +25,17 @@ __C infiniopStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr,
#endif
#endif
#ifdef ENABLE_CUDA_API
#ifdef ENABLE_CUDA_API
case
INFINI_DEVICE_NVIDIA
:
{
case
INFINI_DEVICE_NVIDIA
:
{
return
createCudaHandle
((
infiniopCudaHandle_t
*
)
handle_ptr
,
device_id
,
return
createCudaHandle
((
infiniopCudaHandle_t
*
)
handle_ptr
,
device
);
device
);
}
}
#endif
#endif
#ifdef ENABLE_CAMBRICON_API
#ifdef ENABLE_CAMBRICON_API
case
INFINI_DEVICE_CAMBRICON
:
{
case
INFINI_DEVICE_CAMBRICON
:
{
return
createBangHandle
((
infiniopBangHandle_t
*
)
handle_ptr
,
device_id
);
return
createBangHandle
((
infiniopBangHandle_t
*
)
handle_ptr
);
}
}
#endif
#endif
#ifdef ENABLE_ASCEND_API
#ifdef ENABLE_ASCEND_API
case
INFINI_DEVICE_ASCEND
:
{
case
INFINI_DEVICE_ASCEND
:
{
return
createAscendHandle
((
infiniopAscendHandle_t
*
)
handle_ptr
,
return
createAscendHandle
((
infiniopAscendHandle_t
*
)
handle_ptr
);
device_id
);
}
}
#endif
#endif
}
}
...
...
src/infiniop/ops/matmul/bang/matmul_cnnl.cc
View file @
9bc9ca91
...
@@ -31,7 +31,7 @@ infiniopStatus_t bangCreateMatmulDescriptor(
...
@@ -31,7 +31,7 @@ infiniopStatus_t bangCreateMatmulDescriptor(
cnnlSetMatMulDescAttr
(
opDesc
,
CNNL_MATMUL_USE_STRIDE
,
&
use_stride
,
cnnlSetMatMulDescAttr
(
opDesc
,
CNNL_MATMUL_USE_STRIDE
,
&
use_stride
,
sizeof
(
int32_t
));
sizeof
(
int32_t
));
int
count
=
0
;
int
count
=
0
;
use_cnnl
(
handle
->
cnnl_handle
s
,
[
&
](
cnnlHandle_t
_handle
)
{
use_cnnl
(
handle
->
cnnl_handle
_pool
,
[
&
](
cnnlHandle_t
_handle
)
{
cnnlGetBatchMatMulAlgoHeuristic
(
_handle
,
opDesc
,
aDesc
,
bDesc
,
cDesc
,
cnnlGetBatchMatMulAlgoHeuristic
(
_handle
,
opDesc
,
aDesc
,
bDesc
,
cDesc
,
NULL
,
1
,
&
algoResult
,
&
count
);
NULL
,
1
,
&
algoResult
,
&
count
);
});
});
...
@@ -42,7 +42,7 @@ infiniopStatus_t bangCreateMatmulDescriptor(
...
@@ -42,7 +42,7 @@ infiniopStatus_t bangCreateMatmulDescriptor(
handle
->
device_id
,
handle
->
device_id
,
info
,
info
,
c_desc
->
dtype
,
c_desc
->
dtype
,
handle
->
cnnl_handle
s
,
handle
->
cnnl_handle
_pool
,
aDesc
,
aDesc
,
bDesc
,
bDesc
,
cDesc
,
cDesc
,
...
@@ -61,7 +61,7 @@ infiniopStatus_t bangGetMatmulWorkspaceSize(infiniopMatmulBangDescriptor_t desc,
...
@@ -61,7 +61,7 @@ infiniopStatus_t bangGetMatmulWorkspaceSize(infiniopMatmulBangDescriptor_t desc,
infiniopStatus_t
infiniopStatus_t
bangDestroyMatmulDescriptor
(
infiniopMatmulBangDescriptor_t
desc
)
{
bangDestroyMatmulDescriptor
(
infiniopMatmulBangDescriptor_t
desc
)
{
desc
->
cnnl_handle
s
=
nullptr
;
desc
->
cnnl_handle
_pool
=
nullptr
;
cnnlDestroyTensorDescriptor
(
desc
->
aDesc
);
cnnlDestroyTensorDescriptor
(
desc
->
aDesc
);
cnnlDestroyTensorDescriptor
(
desc
->
bDesc
);
cnnlDestroyTensorDescriptor
(
desc
->
bDesc
);
cnnlDestroyTensorDescriptor
(
desc
->
cDesc
);
cnnlDestroyTensorDescriptor
(
desc
->
cDesc
);
...
@@ -80,7 +80,7 @@ void bangMatmulCnnl(infiniopMatmulBangDescriptor_t desc, void *workspace, void *
...
@@ -80,7 +80,7 @@ void bangMatmulCnnl(infiniopMatmulBangDescriptor_t desc, void *workspace, void *
std
::
swap
(
a
,
b
);
std
::
swap
(
a
,
b
);
}
}
use_cnnl
(
desc
->
cnnl_handle
s
,
(
cnrtQueue_t
)
stream
,
[
&
](
cnnlHandle_t
handle
)
{
use_cnnl
(
desc
->
cnnl_handle
_pool
,
(
cnrtQueue_t
)
stream
,
[
&
](
cnnlHandle_t
handle
)
{
cnnlBatchMatMulBCast_v2
(
handle
,
desc
->
opDesc
,
desc
->
algo
,
&
alpha
,
cnnlBatchMatMulBCast_v2
(
handle
,
desc
->
opDesc
,
desc
->
algo
,
&
alpha
,
desc
->
aDesc
,
a
,
desc
->
bDesc
,
b
,
&
beta
,
desc
->
aDesc
,
a
,
desc
->
bDesc
,
b
,
&
beta
,
desc
->
cDesc
,
c
,
workspace
,
desc
->
cDesc
,
c
,
workspace
,
...
...
src/infiniop/ops/matmul/bang/matmul_cnnl.h
View file @
9bc9ca91
...
@@ -9,7 +9,7 @@ struct InfiniopMatmulBangDescriptor {
...
@@ -9,7 +9,7 @@ struct InfiniopMatmulBangDescriptor {
int
device_id
;
int
device_id
;
MatmulInfo
info
;
MatmulInfo
info
;
infiniDtype_t
dtype
;
infiniDtype_t
dtype
;
std
::
shared_ptr
<
Pool
<
cnnlHandle_t
>>
cnnl_handle
s
;
std
::
shared_ptr
<
Pool
<
cnnlHandle_t
>>
cnnl_handle
_pool
;
cnnlTensorDescriptor_t
aDesc
;
cnnlTensorDescriptor_t
aDesc
;
cnnlTensorDescriptor_t
bDesc
;
cnnlTensorDescriptor_t
bDesc
;
cnnlTensorDescriptor_t
cDesc
;
cnnlTensorDescriptor_t
cDesc
;
...
...
src/infiniop/ops/matmul/cuda/matmul_cuda.cu
View file @
9bc9ca91
...
@@ -23,7 +23,7 @@ infiniopStatus_t cudaCreateMatmulDescriptor(infiniopCudaHandle_t handle,
...
@@ -23,7 +23,7 @@ infiniopStatus_t cudaCreateMatmulDescriptor(infiniopCudaHandle_t handle,
dtype
,
dtype
,
handle
->
device_id
,
handle
->
device_id
,
info
,
info
,
handle
->
cublas_handle
s_t
};
handle
->
cublas_handle
_pool
};
return
INFINIOP_STATUS_SUCCESS
;
return
INFINIOP_STATUS_SUCCESS
;
}
}
...
@@ -33,7 +33,7 @@ infiniopStatus_t cudaGetMatmulWorkspaceSize(infiniopMatmulCudaDescriptor_t desc,
...
@@ -33,7 +33,7 @@ infiniopStatus_t cudaGetMatmulWorkspaceSize(infiniopMatmulCudaDescriptor_t desc,
}
}
infiniopStatus_t
cudaDestroyMatmulDescriptor
(
infiniopMatmulCudaDescriptor_t
desc
)
{
infiniopStatus_t
cudaDestroyMatmulDescriptor
(
infiniopMatmulCudaDescriptor_t
desc
)
{
desc
->
cublas_handle
s_t
=
nullptr
;
desc
->
cublas_handle
_pool
=
nullptr
;
delete
desc
;
delete
desc
;
return
INFINIOP_STATUS_SUCCESS
;
return
INFINIOP_STATUS_SUCCESS
;
}
}
src/infiniop/ops/matmul/cuda/matmul_cuda.cuh
View file @
9bc9ca91
...
@@ -11,7 +11,7 @@ typedef struct InfiniopMatmulCudaDescriptor {
...
@@ -11,7 +11,7 @@ typedef struct InfiniopMatmulCudaDescriptor {
infiniDtype_t
dtype
;
infiniDtype_t
dtype
;
int
device_id
;
int
device_id
;
MatmulInfo
info
;
MatmulInfo
info
;
std
::
shared_ptr
<
Pool
<
cublasHandle_t
>>
cublas_handle
s_t
;
std
::
shared_ptr
<
Pool
<
cublasHandle_t
>>
cublas_handle
_pool
;
}
InfiniopMatmulCudaDescriptor
;
}
InfiniopMatmulCudaDescriptor
;
#endif// __INFINIOP_MATMUL_CUDA_H__
#endif// __INFINIOP_MATMUL_CUDA_H__
src/infiniop/ops/matmul/cuda/matmul_cuda_kernel.cu
View file @
9bc9ca91
...
@@ -26,7 +26,7 @@ infiniopStatus_t cudaMatmulCublas(infiniopMatmulCudaDescriptor_t desc, void *c,
...
@@ -26,7 +26,7 @@ infiniopStatus_t cudaMatmulCublas(infiniopMatmulCudaDescriptor_t desc, void *c,
auto
op_a
=
info
.
a_matrix
.
row_stride
==
1
?
CUBLAS_OP_N
:
CUBLAS_OP_T
;
auto
op_a
=
info
.
a_matrix
.
row_stride
==
1
?
CUBLAS_OP_N
:
CUBLAS_OP_T
;
auto
op_b
=
info
.
b_matrix
.
row_stride
==
1
?
CUBLAS_OP_N
:
CUBLAS_OP_T
;
auto
op_b
=
info
.
b_matrix
.
row_stride
==
1
?
CUBLAS_OP_N
:
CUBLAS_OP_T
;
use_cublas
(
desc
->
cublas_handle
s_t
,
desc
->
device_id
,
(
cudaStream_t
)
stream
,
use_cublas
(
desc
->
cublas_handle
_pool
,
desc
->
device_id
,
(
cudaStream_t
)
stream
,
[
&
](
cublasHandle_t
handle
)
{
cublasGemmStridedBatchedEx
(
[
&
](
cublasHandle_t
handle
)
{
cublasGemmStridedBatchedEx
(
handle
,
handle
,
op_a
,
op_a
,
...
...
test/infiniop/libinfiniop/utils.py
View file @
9bc9ca91
...
@@ -378,7 +378,9 @@ def get_test_devices(args):
...
@@ -378,7 +378,9 @@ def get_test_devices(args):
import
torch_mlu
import
torch_mlu
devices_to_test
.
append
(
InfiniDeviceEnum
.
CAMBRICON
)
devices_to_test
.
append
(
InfiniDeviceEnum
.
CAMBRICON
)
if
args
.
ascend
:
if
args
.
ascend
:
import
torch
import
torch_npu
import
torch_npu
torch
.
npu
.
set_device
(
0
)
# Ascend NPU needs explicit device initialization
devices_to_test
.
append
(
InfiniDeviceEnum
.
ASCEND
)
devices_to_test
.
append
(
InfiniDeviceEnum
.
ASCEND
)
if
not
devices_to_test
:
if
not
devices_to_test
:
devices_to_test
=
[
InfiniDeviceEnum
.
CPU
]
devices_to_test
=
[
InfiniDeviceEnum
.
CPU
]
...
...
test/infiniop/matmul.py
View file @
9bc9ca91
...
@@ -112,7 +112,7 @@ def test(
...
@@ -112,7 +112,7 @@ def test(
def
lib_matmul
():
def
lib_matmul
():
check_error
(
lib
.
infiniopMatmul
(
check_error
(
lib
.
infiniopMatmul
(
descriptor
,
descriptor
,
workspace
.
data_ptr
()
if
workspace
else
None
,
workspace
.
data_ptr
()
if
workspace
is
not
None
else
None
,
workspace_size
.
value
,
workspace_size
.
value
,
c_tensor
.
data
,
c_tensor
.
data
,
a_tensor
.
data
,
a_tensor
.
data
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment