|
| 1 | +//===------ dppl_utils_helper.cpp - dpctl-C_API ----*---- C++ -----*-----===// |
| 2 | +// |
| 3 | +// Data Parallel Control Library (dpCtl) |
| 4 | +// |
| 5 | +// Copyright 2020 Intel Corporation |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | +// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +/// |
| 21 | +/// \file |
| 22 | +/// This file implements the helper functions defined in dppl_utils_helper.h. |
| 23 | +/// |
| 24 | +//===----------------------------------------------------------------------===// |
| 25 | + |
| 26 | +#include "dppl_utils_helper.h" |
| 27 | +#include <string> |
| 28 | +#include <sstream> |
| 29 | + |
| 30 | +using namespace cl::sycl; |
| 31 | + |
| 32 | +/*! |
| 33 | +* Transforms enum info::device_type to string. |
| 34 | +*/ |
| 35 | +std::string DPPL_DeviceTypeToStr(info::device_type devTy) |
| 36 | +{ |
| 37 | + std::stringstream ss; |
| 38 | + switch (devTy) |
| 39 | + { |
| 40 | + case info::device_type::cpu: |
| 41 | + ss << "cpu" << '\n'; |
| 42 | + break; |
| 43 | + case info::device_type::gpu: |
| 44 | + ss << "gpu" << '\n'; |
| 45 | + break; |
| 46 | + case info::device_type::accelerator: |
| 47 | + ss << "accelerator" << '\n'; |
| 48 | + break; |
| 49 | + case info::device_type::custom: |
| 50 | + ss << "custom" << '\n'; |
| 51 | + break; |
| 52 | + case info::device_type::host: |
| 53 | + ss << "host" << '\n'; |
| 54 | + break; |
| 55 | + default: |
| 56 | + ss << "unknown" << '\n'; |
| 57 | + } |
| 58 | + return ss.str(); |
| 59 | +} |
| 60 | + |
| 61 | +/*! |
| 62 | +* Transforms string to enum info::device_type. |
| 63 | +*/ |
| 64 | +info::device_type DPPL_StrToDeviceType(std::string devTyStr) |
| 65 | +{ |
| 66 | + info::device_type devTy; |
| 67 | + if (devTyStr == "cpu") { |
| 68 | + devTy = info::device_type::cpu; |
| 69 | + } else if(devTyStr == "gpu") { |
| 70 | + devTy = info::device_type::gpu; |
| 71 | + } else if(devTyStr == "accelerator") { |
| 72 | + devTy = info::device_type::accelerator; |
| 73 | + } else if(devTyStr == "custom") { |
| 74 | + devTy = info::device_type::custom; |
| 75 | + } else if(devTyStr == "host") { |
| 76 | + devTy = info::device_type::host; |
| 77 | + } else { |
| 78 | + // \todo handle the error |
| 79 | + throw std::runtime_error("Unknown device type."); |
| 80 | + } |
| 81 | + return devTy; |
| 82 | +} |
0 commit comments