From ebe5bd5cf070b9683e2532d98a96fb8231f3db44 Mon Sep 17 00:00:00 2001 From: wangyuan Date: Thu, 19 Dec 2024 19:41:35 +0800 Subject: [PATCH] [Feature-internal](test): test adam_w --- bangc_kernels.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 bangc_kernels.h diff --git a/bangc_kernels.h b/bangc_kernels.h new file mode 100644 index 000000000..144706de7 --- /dev/null +++ b/bangc_kernels.h @@ -0,0 +1,86 @@ +/************************************************************************* + * Copyright (C) [2022] by Cambricon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *************************************************************************/ +#ifndef MLUOP_LITE_H_ +#define MLUOP_LITE_H_ + +#include "mlu_op.h" + +#ifndef BANGC_KERNELS_WIN_API +#ifdef _WIN32 +#define BANGC_KERNELS_WIN_API __stdcall +#else +#define BANGC_KERNELS_WIN_API +#endif +#endif + +typedef enum { + BANGC_KERNELS_STATUS_SUCCESS = + 0, /*!< The operation is successfully completed. */ + BANGC_KERNELS_STATUS_ALLOC_FAILED = 1, + /*!< This error occurs when the resource allocation fails, which is usually + caused by failing to call cnMallocHost due to exceeded memory usage. Make + sure that the memory allocated previously is deallocated as much as + possible. */ + BANGC_KERNELS_STATUS_BAD_PARAM = 2, + /*!< Invalid value or parameters are passed to the function, including data + type, layout, dimensions, etc. */ + BANGC_KERNELS_STATUS_INTERNAL_ERROR = 3, + /*!< An error occurs inside of the function, which may indicate an internal + error or bug in the library. This error is usually caused by failing to + call cnrtMemcpyAsync. Check whether the memory passed to the function is + deallocated before the completion of the routine. */ + BANGC_KERNELS_STATUS_ARCH_MISMATCH = 4, + /*!< Invalid MLU device which is not supported by current function. */ + BANGC_KERNELS_STATUS_EXECUTION_FAILED = 5, + /*!< An error occurs when the function fails to be executed on MLU device due + to multiple reasons. You can check whether the hardware environment, driver + version and other prerequisite libraries are correctly installed. */ + BANGC_KERNELS_STATUS_NOT_SUPPORTED = 6, + /*!< An error occurs when the requested functionality is not supported in this + version but would be supported in the future. */ + BANGC_KERNELS_STATUS_NUMERICAL_OVERFLOW = 7, + /*!< A numerical overflow occurs when executing the function, which is usually + due to large scale or inappropriate range of value of input tensor. */ +} bangcKernelsStatus_t; + + +template +bangcKernelsStatus_t BANGC_KERNELS_WIN_API mluApplyAdamW(const cnrtQueue_t queue, + T *param_h, + T *grad, + void *param, + void *momentum, + void *velocity, + float lr, + float beta1, + float beta2, + float bias1, + float bias2, + float epsilon, + float weight_decay, + float scale, + bool use_nesterov, + size_t size); + + +#endif // MLUOP_LITE_H_