1 /**
2 * Copyright 2022 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "include/backend/data_queue/data_queue.h"
18 #include "utils/ms_context.h"
19 #include "runtime/hardware/device_context_manager.h"
20
21 namespace mindspore {
22 namespace device {
DataQueue(const std::string & channel_name,const size_t capacity)23 DataQueue::DataQueue(const std::string &channel_name, const size_t capacity)
24 : channel_name_(channel_name), head_(0), tail_(0), size_(0), capacity_(capacity), device_context_(nullptr) {
25 auto ms_context = MsContext::GetInstance();
26 MS_EXCEPTION_IF_NULL(ms_context);
27 const std::string &device_target = ms_context->get_param<std::string>(MS_CTX_DEVICE_TARGET);
28 uint32_t device_id = ms_context->get_param<uint32_t>(MS_CTX_DEVICE_ID);
29 device_context_ = DeviceContextManager::GetInstance().GetOrCreateDeviceContext({device_target, device_id});
30 device_context_->Initialize();
31 }
32 } // namespace device
33 } // namespace mindspore
34