Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "hccl_channel_config.h"
12 : #include "hccl/hccl_channel.h"
13 : #include "log.h"
14 : #include "exception_handler.h"
15 :
16 0 : HcclResult HcclChannelConfigCreate(HcclChannelConfig* config)
17 : {
18 0 : CHK_PTR_NULL(config);
19 0 : NEW_NOTHROW(*config, hccl::HcclChannelConfigData(), return HCCL_E_PTR);
20 0 : return HCCL_SUCCESS;
21 : }
22 :
23 0 : HcclResult HcclChannelConfigDestroy(HcclChannelConfig config)
24 : {
25 0 : if (config == nullptr) {
26 0 : return HCCL_SUCCESS;
27 : }
28 0 : auto* cfg = static_cast<hccl::HcclChannelConfigData*>(config);
29 0 : if (cfg->destroyed_.exchange(true)) {
30 0 : HCCL_WARNING("[%s] config[%p] is already destroyed, skip to avoid double-free.", __func__, config);
31 0 : return HCCL_SUCCESS;
32 : }
33 0 : delete cfg;
34 0 : return HCCL_SUCCESS;
35 : }
36 :
37 0 : HcclResult HcclChannelConfigSetInt(HcclChannelConfig config, HcclChannelConfigType type, uint32_t value)
38 : {
39 0 : CHK_PTR_NULL(config);
40 0 : auto* cfg = static_cast<hccl::HcclChannelConfigData*>(config);
41 0 : switch (type) {
42 0 : case HCCL_CHANNEL_CONFIG_TYPE_IS_SHARED_QUEUE:
43 0 : cfg->isSharedQueue = (value != 0);
44 0 : HCCL_INFO("[%s] set IS_SHARED_QUEUE=%d.", __func__, static_cast<int>(cfg->isSharedQueue));
45 0 : break;
46 0 : default:
47 0 : HCCL_ERROR("[%s] invalid int config type[%d].", __func__, static_cast<int>(type));
48 0 : return HCCL_E_PARA;
49 : }
50 0 : return HCCL_SUCCESS;
51 : }
52 :
53 0 : HcclResult HcclChannelConfigSetStr(HcclChannelConfig config, HcclChannelConfigType type, const char* value)
54 : {
55 0 : CHK_PTR_NULL(config);
56 0 : CHK_PTR_NULL(value);
57 0 : auto* cfg = static_cast<hccl::HcclChannelConfigData*>(config);
58 0 : switch (type) {
59 0 : case HCCL_CHANNEL_CONFIG_TYPE_SHARED_QUEUE_TAG:
60 0 : CHK_PRT_RET(
61 : strlen(value) == 0 || strlen(value) > HCCL_CHANNEL_CONFIG_SHARED_QUEUE_TAG_MAX_LEN,
62 : HCCL_ERROR(
63 : "[%s] SHARED_QUEUE_TAG length[%zu] must be in (0, %u].", __func__, strlen(value),
64 : HCCL_CHANNEL_CONFIG_SHARED_QUEUE_TAG_MAX_LEN),
65 : HCCL_E_PARA);
66 0 : cfg->sharedQueueTag = std::string(value);
67 0 : HCCL_INFO("[%s] set SHARED_QUEUE_TAG=%s.", __func__, cfg->sharedQueueTag.c_str());
68 0 : break;
69 0 : default:
70 0 : HCCL_ERROR("[%s] invalid str config type[%d].", __func__, static_cast<int>(type));
71 0 : return HCCL_E_PARA;
72 : }
73 0 : return HCCL_SUCCESS;
74 : }
|