|
25 | 25 | #include "mxl/flow.h" |
26 | 26 | #include "mxl/platform.h" |
27 | 27 |
|
28 | | -namespace |
| 28 | +namespace ofi = mxl::lib::fabrics::ofi; |
| 29 | + |
| 30 | +namespace mxl::lib::fabrics::ofi |
29 | 31 | { |
30 | | - /// Parse the optional target setup options JSON and return the requested completion |
31 | | - /// queue depth, or std::nullopt (use the implementation default) when not specified. |
32 | | - /// |
33 | | - /// Recognized form: {"cqDepth": <positive integer>} |
34 | | - std::optional<std::size_t> parseCqDepthOption(char const* options) |
| 32 | + namespace |
35 | 33 | { |
36 | | - using mxl::lib::fabrics::ofi::Exception; |
37 | | - |
38 | | - if ((options == nullptr) || (options[0] == '\0')) |
| 34 | + /// Parse the optional target setup options JSON and return the requested completion |
| 35 | + /// queue depth, or std::nullopt (use the implementation default) when not specified. |
| 36 | + /// |
| 37 | + /// Recognized form: {"cqDepth": <positive integer>} |
| 38 | + std::optional<std::size_t> parseCqDepthOption(char const* options) |
39 | 39 | { |
40 | | - return std::nullopt; |
41 | | - } |
| 40 | + if ((options == nullptr) || (options[0] == '\0')) |
| 41 | + { |
| 42 | + return std::nullopt; |
| 43 | + } |
42 | 44 |
|
43 | | - auto value = picojson::value{}; |
44 | | - auto const err = picojson::parse(value, options); |
45 | | - if (!err.empty() || !value.is<picojson::object>()) |
46 | | - { |
47 | | - throw Exception::invalidArgument("Invalid JSON target options: {}", err.empty() ? std::string{"expected an object"} : err); |
48 | | - } |
| 45 | + auto value = picojson::value{}; |
| 46 | + auto const err = picojson::parse(value, options); |
| 47 | + if (!err.empty() || !value.is<picojson::object>()) |
| 48 | + { |
| 49 | + throw Exception::invalidArgument("Invalid JSON target options: {}", err.empty() ? std::string{"expected an object"} : err); |
| 50 | + } |
49 | 51 |
|
50 | | - auto const& root = value.get<picojson::object>(); |
51 | | - auto const it = root.find("cqDepth"); |
52 | | - if (it == root.end()) |
53 | | - { |
54 | | - return std::nullopt; |
55 | | - } |
56 | | - if (!it->second.is<double>()) |
57 | | - { |
58 | | - throw Exception::invalidArgument("cqDepth must be a number."); |
59 | | - } |
60 | | - auto const depth = it->second.get<double>(); |
61 | | - if (depth < 1.0) |
62 | | - { |
63 | | - throw Exception::invalidArgument("cqDepth must be greater or equal to 1."); |
| 52 | + auto const& root = value.get<picojson::object>(); |
| 53 | + auto const it = root.find("cqDepth"); |
| 54 | + if (it == root.end()) |
| 55 | + { |
| 56 | + return std::nullopt; |
| 57 | + } |
| 58 | + if (!it->second.is<double>()) |
| 59 | + { |
| 60 | + throw Exception::invalidArgument("cqDepth must be a number."); |
| 61 | + } |
| 62 | + auto const depth = it->second.get<double>(); |
| 63 | + if (depth < 1.0) |
| 64 | + { |
| 65 | + throw Exception::invalidArgument("cqDepth must be greater or equal to 1."); |
| 66 | + } |
| 67 | + return static_cast<std::size_t>(depth); |
64 | 68 | } |
65 | | - return static_cast<std::size_t>(depth); |
66 | | - } |
67 | | -} |
68 | | - |
69 | | -namespace ofi = mxl::lib::fabrics::ofi; |
70 | 69 |
|
71 | | -namespace mxl::lib::fabrics::ofi |
72 | | -{ |
73 | | - namespace |
74 | | - { |
75 | 70 | template<typename F> |
76 | 71 | mxlStatus try_run(F&& func, std::string_view errMsg) |
77 | 72 | { |
@@ -194,7 +189,7 @@ mxlStatus mxlFabricsTargetSetup(mxlFabricsTarget in_target, mxlFabricsTargetConf |
194 | 189 | return ofi::try_run( |
195 | 190 | [&]() |
196 | 191 | { |
197 | | - auto const setupOptions = ofi::TargetSetupOptions{.cqDepth = parseCqDepthOption(options)}; |
| 192 | + auto const setupOptions = ofi::TargetSetupOptions{.cqDepth = ofi::parseCqDepthOption(options)}; |
198 | 193 |
|
199 | 194 | // Set up the target, release the returned unique_ptr, convert to external API type, assign the the pointer location |
200 | 195 | // passed by the user. |
|
0 commit comments