MXNet/RunTime.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 50 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17  
18 package AI::MXNet::RunTime;
19 use strict;
20 use warnings;
21 use AI::MXNet::NS;
22 use AI::MXNet::Base;
23 use AI::MXNet::Function::Parameters;
24 use Mouse;
25  
26 =encoding utf-8
27  
28 =head1 NAME
29  
30 AI::MXNet::RunTime - Runtime querying of compile time features in the native library.
31 =cut
32  
33 =head1 DESCRIPTION
34  
35 With this module you can check at runtime which libraries and features were compiled in the library.
36  
37 Example usage:
38  
39 use AI::MXNet qw(mx);
40 my $features = mx->runtime->Features();
41  
42 print $features->is_enabled("CUDNN");
43 0
44  
45 print $features->is_enabled("CPU_SSE");
46 1
47  
48 print Dumper($features->features);
49 $VAR1 = {
50 'LAPACK' => 1,
51 'F16C' => 1,
52 'CPU_SSE2' => 1,
53 'BLAS_MKL' => 0,
54 'CXX14' => 0,
55 'DIST_KVSTORE' => 0,
56 'NCCL' => 0,
57 'OPENMP' => 1,
58 'CUDNN' => 0,
59 'CPU_AVX' => 1,
60 'CUDA_RTC' => 0,
61 'BLAS_OPEN' => 1,
62 'CPU_SSE4_2' => 1,
63 'CPU_SSE4A' => 0,
64 'TVM_OP' => 0,
65 'MKLDNN' => 0,
66 'TENSORRT' => 0,
67 'JEMALLOC' => 1,
68 'SSE' => 0,
69 'PROFILER' => 0,
70 'DEBUG' => 0,
71 'BLAS_APPLE' => 0,
72 'CPU_SSE3' => 1,
73 'INT64_TENSOR_SIZE' => 0,
74 'CPU_SSE4_1' => 1,
75 'CUDA' => 0,
76 'OPENCV' => 1,
77 'CPU_SSE' => 1,
78 'SIGNAL_HANDLER' => 0,
79 'BLAS_ATLAS' => 0,
80 'CAFFE' => 0,
81 'CPU_AVX2' => 0
82 };
83  
84 print $features;
85 [✖ CUDA, ✖ CUDNN, ✖ NCCL, ✖ CUDA_RTC, ✖ TENSORRT, ✔ CPU_SSE, ✔ CPU_SSE2, ✔ CPU_SSE3,
86 ✔ CPU_SSE4_1, ✔ CPU_SSE4_2, ✖ CPU_SSE4A, ✔ CPU_AVX, ✖ CPU_AVX2, ✔ OPENMP, ✖ SSE,
87 ✔ F16C, ✔ JEMALLOC, ✔ BLAS_OPEN, ✖ BLAS_ATLAS, ✖ BLAS_MKL, ✖ BLAS_APPLE, ✔ LAPACK,
88 ✖ MKLDNN, ✔ OPENCV, ✖ CAFFE, ✖ PROFILER, ✖ DIST_KVSTORE, ✖ CXX14, ✖ INT64_TENSOR_SIZE,
89 ✔ SIGNAL_HANDLER, ✔ DEBUG, ✖ TVM_OP]
90  
91 =cut
92 use overload '""' => sub {
93 my $self = shift;
94 my $s = join(', ', map {
95 sprintf("%s %s", $self->features->{ $_ } ? '✔' : '✖', $_)
96 } sort keys %{ $self->features });
97 return "[$s]";
98 };
99  
100 has 'features' => (is => 'rw', init_arg => undef, default => sub {
101 return scalar(check_call(AI::MXNetCAPI::LibInfoFeatures()));
102 });
103  
104 method is_enabled(Str $feature)
105 {
106 confess("Feature $feature does not exist")
107 unless exists $self->features->{ $feature };
108 return $self->features->{ $feature };
109 }
110  
111 my $features;
112 method Features()
113 {
114 $features //= __PACKAGE__->new;
115 return $features;
116 }
117  
118 1;