Skip to content

Commit f1e6df7

Browse files
Liheng Jianouonline
authored andcommitted
[opt]add cudnn&VisionEmbedding micro.
1 parent 7b2363d commit f1e6df7

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/ppl/nn/engines/llm_cuda/kernels/opmx/vision_embedding_kernel.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@
1717

1818
#include "vision_embedding_kernel.h"
1919

20-
#include "ppl/common/cuda/nccl_utils.h"
2120
#include "ppl/common/destructor.h"
2221

2322
#include "ppl/kernel/llm/cuda/pmx/vision_embedding.h"
2423

24+
#ifdef PPLNN_CUDA_ENABLE_CUDNN
2525
#include <cudnn.h>
26+
#endif
2627

2728
namespace ppl { namespace nn { namespace llm { namespace cuda { namespace opmx {
2829

2930
ppl::common::RetCode VisionEmbeddingKernel::DoExecute(KernelExecContext* ctx) {
3031
PPLNN_LLM_CUDA_DEBUG_TRACE("Entry LlmCudaKernel: [%s]\n", GetName().c_str());
3132

33+
#ifdef PPLNN_CUDA_ENABLE_CUDNN
3234
PPLNN_LLM_CUDA_REQUIRED_INPUT(pixel_values, 0);
3335
PPLNN_LLM_CUDA_REQUIRED_INPUT(cls_emb_weight, 1);
3436
PPLNN_LLM_CUDA_OPTIONAL_INPUT(patch_emb_weight, 2);
@@ -100,6 +102,10 @@ ppl::common::RetCode VisionEmbeddingKernel::DoExecute(KernelExecContext* ctx) {
100102
ppl::kernel::llm::cuda::pmx::vision_embedding_postprocessing(config);
101103

102104
return ppl::common::RC_SUCCESS;
105+
#else
106+
LOG(ERROR) << "VisionEmbedding need cudnn, please recompile with PPLNN_CUDA_ENABLE_CUDNN=ON";
107+
return ppl::common::RC_UNSUPPORTED;
108+
#endif
103109
}
104110

105111
}}}}} // namespace ppl::nn::llm::cuda::opmx

src/ppl/nn/engines/llm_cuda/llm_cuda_device.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ LlmCudaDevice::~LlmCudaDevice() {
4949
cudaFree(cublas_workspace_);
5050
}
5151

52+
#ifdef PPLNN_CUDA_ENABLE_CUDNN
5253
if (cudnn_handle_) {
5354
cudnnDestroy(cudnn_handle_);
5455
}
56+
#endif
5557

5658
if (i4f16_gemm_handle_) {
5759
ppl::kernel::llm::cuda::pmx::i4f16::destory_gemm_handle(i4f16_gemm_handle_);
@@ -98,13 +100,15 @@ RetCode LlmCudaDevice::Init(int device_id, bool init_cublas_cudnn, NcclParam* te
98100
cublas_workspace_size_ = 32 * 1024 * 1024;
99101
}
100102

103+
#ifdef PPLNN_CUDA_ENABLE_CUDNN
101104
if (!cudnn_handle_ && init_cublas_cudnn) {
102105
auto cu_status = cudnnCreate(&cudnn_handle_);
103106
if (cu_status != CUDNN_STATUS_SUCCESS) {
104107
LOG(ERROR) << "cudnnCreate failed: " << cudnnGetErrorString(cu_status);
105108
return RC_INTERNAL_ERROR;
106109
}
107110
}
111+
#endif
108112

109113
if (!stream_) {
110114
if (flag == NEW) {

src/ppl/nn/engines/llm_cuda/llm_cuda_device.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626

2727
#include <cuda_runtime.h>
2828
#include <cublasLt.h>
29+
30+
#ifdef PPLNN_CUDA_ENABLE_CUDNN
2931
#include <cudnn.h>
32+
#else
33+
typedef void* cudnnHandle_t;
34+
#endif
3035

3136
#include <functional>
3237

0 commit comments

Comments
 (0)