Commit 878db6cc authored by PanZezhong's avatar PanZezhong
Browse files

issue/87/cpu 重构cpu handle

parent 93e0b45f
#include "cpu_handle.h" #include "cpu_handle.h"
infiniStatus_t createCpuHandle(infiniopCpuHandle_t *handle_ptr) { namespace infiniop::cpu {
*handle_ptr = new InfiniopHandle{INFINI_DEVICE_CPU, 0}; Handle::Handle() : InfiniopHandle{INFINI_DEVICE_CPU, 0} {}
return INFINI_STATUS_SUCCESS;
}
infiniStatus_t destroyCpuHandle(infiniopCpuHandle_t handle) { infiniStatus_t Handle::create(InfiniopHandle **handle_ptr) {
delete handle; *handle_ptr = new Handle{};
return INFINI_STATUS_SUCCESS; return INFINI_STATUS_SUCCESS;
} }
} // namespace infiniop::cpu
...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
#include "../../handle.h" #include "../../handle.h"
typedef infiniopHandle_t infiniopCpuHandle_t; namespace infiniop::cpu {
class Handle : public InfiniopHandle {
infiniStatus_t createCpuHandle(infiniopCpuHandle_t *handle_ptr); Handle();
infiniStatus_t destroyCpuHandle(infiniopCpuHandle_t handle); public:
static infiniStatus_t create(InfiniopHandle **handle_ptr);
};
} // namespace infiniop::cpu
#endif #endif
...@@ -24,7 +24,7 @@ __C infiniStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr, ...@@ -24,7 +24,7 @@ __C infiniStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr,
switch (device) { switch (device) {
#ifdef ENABLE_CPU_API #ifdef ENABLE_CPU_API
case INFINI_DEVICE_CPU: case INFINI_DEVICE_CPU:
return createCpuHandle((infiniopCpuHandle_t *)handle_ptr); return infiniop::cpu::Handle::create(handle_ptr);
#endif #endif
#ifdef ENABLE_CUDA_API #ifdef ENABLE_CUDA_API
case INFINI_DEVICE_NVIDIA: { case INFINI_DEVICE_NVIDIA: {
...@@ -51,10 +51,15 @@ __C infiniStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr, ...@@ -51,10 +51,15 @@ __C infiniStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr,
} }
__C infiniStatus_t infiniopDestroyHandle(infiniopHandle_t handle) { __C infiniStatus_t infiniopDestroyHandle(infiniopHandle_t handle) {
#define DELETE(CASE, NAMESPACE) \
case CASE: \
delete reinterpret_cast<infiniop::NAMESPACE::Handle *>(handle); \
return INFINI_STATUS_SUCCESS;
switch (handle->device) { switch (handle->device) {
#ifdef ENABLE_CPU_API #ifdef ENABLE_CPU_API
case INFINI_DEVICE_CPU: DELETE(INFINI_DEVICE_CPU, cpu)
return destroyCpuHandle((infiniopCpuHandle_t)handle);
#endif #endif
#ifdef ENABLE_CUDA_API #ifdef ENABLE_CUDA_API
case INFINI_DEVICE_NVIDIA: { case INFINI_DEVICE_NVIDIA: {
...@@ -76,6 +81,8 @@ __C infiniStatus_t infiniopDestroyHandle(infiniopHandle_t handle) { ...@@ -76,6 +81,8 @@ __C infiniStatus_t infiniopDestroyHandle(infiniopHandle_t handle) {
return destroyKunlunHandle((infiniopKunlunHandle_t)handle); return destroyKunlunHandle((infiniopKunlunHandle_t)handle);
} }
#endif #endif
} default:
return INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED; return INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
}
#undef DELETE
} }
...@@ -12,7 +12,7 @@ infiniStatus_t Descriptor::create( ...@@ -12,7 +12,7 @@ infiniStatus_t Descriptor::create(
infiniopTensorDescriptor_t c_desc, infiniopTensorDescriptor_t c_desc,
infiniopTensorDescriptor_t a_desc, infiniopTensorDescriptor_t a_desc,
infiniopTensorDescriptor_t b_desc) { infiniopTensorDescriptor_t b_desc) {
auto handle = reinterpret_cast<infiniopCpuHandle_t>(handle_); auto handle = reinterpret_cast<infiniop::cpu::Handle *>(handle_);
auto dtype = c_desc->dtype(); auto dtype = c_desc->dtype();
if (dtype != INFINI_DTYPE_F16 && dtype != INFINI_DTYPE_F32) { if (dtype != INFINI_DTYPE_F16 && dtype != INFINI_DTYPE_F32) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment