From 30337750d8e410cccc7c2f31a13ccd1279aba23f Mon Sep 17 00:00:00 2001 From: Sergey Kolychev Date: Sat, 15 Feb 2020 16:59:55 -0800 Subject: [PATCH 1/4] [Perl] MXNET-1447 Runtime features and large tensor support. --- perl-package/AI-MXNet/Changes | 3 + perl-package/AI-MXNet/MANIFEST | 2 + perl-package/AI-MXNet/META.json | 4 +- perl-package/AI-MXNet/META.yml | 4 +- perl-package/AI-MXNet/Makefile.PL | 4 +- perl-package/AI-MXNet/README | 2 +- perl-package/AI-MXNet/lib/AI/MXNet.pm | 3 +- .../lib/AI/MXNet/Gluon/Data/Vision.pm | 8 +- perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm | 25 +- .../AI-MXNet/lib/AI/MXNet/NDArray/Sparse.pm | 6 +- perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm | 116 ++++ perl-package/AI-MXNet/lib/AI/MXNet/Symbol.pm | 17 +- perl-package/AI-MXNet/t/test_runtime.t | 63 ++ perl-package/AI-MXNetCAPI/Changes | 3 + perl-package/AI-MXNetCAPI/META.json | 2 +- perl-package/AI-MXNetCAPI/META.yml | 2 +- perl-package/AI-MXNetCAPI/README | 2 +- perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm | 2 +- perl-package/AI-MXNetCAPI/mxnet.i | 538 ++++++++++++++---- perl-package/AI-MXNetCAPI/mxnet_typemaps.i | 268 +++++++-- 20 files changed, 882 insertions(+), 192 deletions(-) create mode 100644 perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm create mode 100644 perl-package/AI-MXNet/t/test_runtime.t diff --git a/perl-package/AI-MXNet/Changes b/perl-package/AI-MXNet/Changes index c762cc73fc33..6807d79d088a 100644 --- a/perl-package/AI-MXNet/Changes +++ b/perl-package/AI-MXNet/Changes @@ -1,4 +1,7 @@ Revision history for Perl extension AI::MXNet +1.5 Sun Feb 16 19:56:17 PST 2020 + - Runtime features + - INT64 Tensor support 1.4 Mon Feb 18 11:54:07 PST 2019 - Two more gluon loss classes diff --git a/perl-package/AI-MXNet/MANIFEST b/perl-package/AI-MXNet/MANIFEST index 14290227a65f..3d6937c11abf 100644 --- a/perl-package/AI-MXNet/MANIFEST +++ b/perl-package/AI-MXNet/MANIFEST @@ -82,6 +82,7 @@ lib/AI/MXNet/RecordIO.pm lib/AI/MXNet/RNN.pm lib/AI/MXNet/RNN/Cell.pm lib/AI/MXNet/RNN/IO.pm +lib/AI/MXNet/RunTime.pm lib/AI/MXNet/Symbol.pm lib/AI/MXNet/Symbol/AttrScope.pm lib/AI/MXNet/Symbol/Base.pm @@ -125,6 +126,7 @@ t/test_optimizers.t t/test_random.t t/test_recordio.t t/test_rnn.t +t/test_runtime.t t/test_sparse_ndarray.t t/test_symbol.t t/test_viz.t diff --git a/perl-package/AI-MXNet/META.json b/perl-package/AI-MXNet/META.json index 37c573c279f5..e7681343ecd8 100644 --- a/perl-package/AI-MXNet/META.json +++ b/perl-package/AI-MXNet/META.json @@ -30,7 +30,7 @@ }, "runtime" : { "requires" : { - "AI::MXNetCAPI" : "1.4", + "AI::MXNetCAPI" : "1.5", "AI::NNVMCAPI" : "1.3", "Function::Parameters" : "1.0705", "Hash::Ordered" : "0.012", @@ -45,5 +45,5 @@ } }, "release_status" : "stable", - "version" : "1.4" + "version" : "1.5" } diff --git a/perl-package/AI-MXNet/META.yml b/perl-package/AI-MXNet/META.yml index 692ca0307948..d2daa486ffb3 100644 --- a/perl-package/AI-MXNet/META.yml +++ b/perl-package/AI-MXNet/META.yml @@ -34,7 +34,7 @@ no_index: - t - inc requires: - AI::MXNetCAPI: '1.4' + AI::MXNetCAPI: '1.5' AI::NNVMCAPI: '1.3' Function::Parameters: '1.0705' Hash::Ordered: '0.012' @@ -42,4 +42,4 @@ requires: Mouse: v2.1.0 PDL: '2.007' PDL::CCS: '1.23.4' -version: '1.4' +version: '1.5' diff --git a/perl-package/AI-MXNet/Makefile.PL b/perl-package/AI-MXNet/Makefile.PL index 19aba3fee4a5..4a9016234ad6 100644 --- a/perl-package/AI-MXNet/Makefile.PL +++ b/perl-package/AI-MXNet/Makefile.PL @@ -36,7 +36,7 @@ my %WriteMakefileArgs = ( "LICENSE" => "apache_2_0", "NAME" => "AI::MXNet", "PREREQ_PM" => { - "AI::MXNetCAPI" => "1.4", + "AI::MXNetCAPI" => "1.5", "AI::NNVMCAPI" => "1.3", "Function::Parameters" => "1.0705", "Hash::Ordered" => "0.012", @@ -46,7 +46,7 @@ my %WriteMakefileArgs = ( "GraphViz" => "2.14" }, "TEST_REQUIRES" => {}, - "VERSION" => "1.4", + "VERSION" => "1.5", "test" => { "TESTS" => "t/*.t" } diff --git a/perl-package/AI-MXNet/README b/perl-package/AI-MXNet/README index 4935b6384071..57d9e4a7b7e8 100644 --- a/perl-package/AI-MXNet/README +++ b/perl-package/AI-MXNet/README @@ -1,5 +1,5 @@ This archive contains the distribution AI-MXNet, -version 1.4: +version 1.5: Perl interface to MXNet machine learning library diff --git a/perl-package/AI-MXNet/lib/AI/MXNet.pm b/perl-package/AI-MXNet/lib/AI/MXNet.pm index b8e17f380118..9c8f68277efe 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet.pm @@ -42,6 +42,7 @@ use AI::MXNet::Module::Base; use AI::MXNet::Module qw(mod module); use AI::MXNet::Module::Bucketing; use AI::MXNet::RNN 'rnn'; +use AI::MXNet::RunTime 'runtime'; use AI::MXNet::Visualization 'viz'; use AI::MXNet::RecordIO 'recordio'; use AI::MXNet::Image qw(img image); @@ -53,7 +54,7 @@ use AI::MXNet::Gluon 'gluon'; use AI::MXNet::NDArray::Sparse; use AI::MXNet::Symbol::Sparse; use AI::MXNet::Engine 'engine'; -our $VERSION = '1.4'; +our $VERSION = '1.5'; sub cpu { AI::MXNet::Context->cpu($_[1]//0) } sub cpu_pinned { AI::MXNet::Context->cpu_pinned($_[1]//0) } diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Gluon/Data/Vision.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Gluon/Data/Vision.pm index 1c9d551b3d1e..abc1c51bfbbe 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Gluon/Data/Vision.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Gluon/Data/Vision.pm @@ -84,7 +84,7 @@ extends 'AI::MXNet::Gluon::Data::Vision::DownloadedDataSet'; Whether to load the training or testing set. Defaults to True transform : function - A user defined callback that transforms each instance. For example + A user defined callback that transforms each instance. For example: transform => sub { my ($data, $label) = @_; return ($data->astype('float32')/255, $label) } =cut @@ -172,7 +172,7 @@ use Mouse; Whether to load the training or testing set. Defaults to True transform : function - A user defined callback that transforms each instance. For example + A user defined callback that transforms each instance. For example: transform => sub { my ($data, $label) = @_; return ($data->astype('float32')/255, $label) } =cut @@ -306,7 +306,7 @@ extends 'AI::MXNet::Gluon::Data::RecordFileSet'; If 1, always convert images to colored (RGB). transform : function - A user defined callback that transforms each instance. For example:: + A user defined callback that transforms each instance. For example: =cut has 'flag' => (is => 'rw', isa => 'Bool', default => 1); has 'transform' => (is => 'rw', isa => 'Maybe[CodeRef]'); @@ -421,7 +421,7 @@ method at(Int $idx) my $label = $self->items->[$idx][1]; if(defined $self->transform) { - return [$self->transform($img, $label)]; + return [$self->transform->($img, $label)]; } return [$img, $label]; } diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm b/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm index abad4471a8e4..1eff8f17a869 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm @@ -63,6 +63,7 @@ use AI::MXNet::NS; use AI::MXNet::Base; use AI::MXNet::NDArray::Slice; use AI::MXNet::Context; +use AI::MXNet::RunTime; use Mouse; use AI::MXNet::Function::Parameters; use overload ( @@ -384,8 +385,11 @@ method _slice ( ) { confess("start $start > stop $stop") if $start > $stop; + my $sub = AI::MXNet::RunTime->Features()->is_enabled('INT64_TENSOR_SIZE') + ? \&AI::MXNetCAPI::NDArraySlice64 + : \&AI::MXNetCAPI::NDArraySlice; my $handle = check_call( - AI::MXNetCAPI::NDArraySlice( + $sub->( $self->handle, $start, $stop @@ -407,8 +411,11 @@ method _slice ( method _at(Index $idx) { + my $sub = AI::MXNet::RunTime->Features()->is_enabled('INT64_TENSOR_SIZE') + ? \&AI::MXNetCAPI::NDArrayAt64 + : \&AI::MXNetCAPI::NDArrayAt; my $handle = check_call( - AI::MXNetCAPI::NDArrayAt( + $sub->( $self->handle, $idx >=0 ? $idx : $self->shape->[0] + $idx ) ); @@ -549,7 +556,14 @@ method wait_to_read() method shape() { - return scalar(check_call(AI::MXNetCAPI::NDArrayGetShapeEx($self->handle))); + if(AI::MXNet::RunTime->Features()->is_enabled('INT64_TENSOR_SIZE')) + { + return [map { $_ + 0 } @{ scalar(check_call(AI::MXNetCAPI::NDArrayGetShapeEx64($self->handle))) }]; + } + else + { + return scalar(check_call(AI::MXNetCAPI::NDArrayGetShapeEx($self->handle))); + } } =head2 size @@ -1464,8 +1478,11 @@ sub _new_empty_handle func _new_alloc_handle($shape, $ctx, $delay_alloc, $dtype) { + my $sub = AI::MXNet::RunTime->Features()->is_enabled('INT64_TENSOR_SIZE') + ? \&AI::MXNetCAPI::NDArrayCreateEx64 + : \&AI::MXNetCAPI::NDArrayCreateEx; my $hdl = check_call( - AI::MXNetCAPI::NDArrayCreateEx( + $sub->( $shape, scalar(@$shape), $ctx->device_type_id, diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/NDArray/Sparse.pm b/perl-package/AI-MXNet/lib/AI/MXNet/NDArray/Sparse.pm index e0257fd0238b..53e6b6362e89 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/NDArray/Sparse.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/NDArray/Sparse.pm @@ -20,6 +20,7 @@ use strict; use warnings; use AI::MXNet::Base; use AI::MXNet::Function::Parameters; +use AI::MXNet::RunTime; use Mouse; extends 'AI::MXNet::NDArray'; @@ -51,8 +52,11 @@ method _new_alloc_handle( my $aux_shape_lens = [map { scalar(@$_) } @$aux_shapes]; @$aux_shapes = map { @$_ } @$aux_shapes; my $num_aux = @{ $aux_types }; + my $sub = AI::MXNet::RunTime->Features()->is_enabled('INT64_TENSOR_SIZE') + ? \&AI::MXNetCAPI::NDArrayCreateSparseEx64 + : \&AI::MXNetCAPI::NDArrayCreateSparseEx; my $handle = check_call( - AI::MXNetCAPI::NDArrayCreateSparseEx( + $sub->( STORAGE_TYPE_STR_TO_ID->{$stype}, $shape, scalar(@$shape), diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm b/perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm new file mode 100644 index 000000000000..51e80f29617a --- /dev/null +++ b/perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm @@ -0,0 +1,116 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +package AI::MXNet::RunTime; +use strict; +use warnings; +use AI::MXNet::NS; +use AI::MXNet::Base; +use AI::MXNet::Function::Parameters; +use Mouse; + +=head1 NAME + + AI::MXNet::RunTime - Runtime querying of compile time features in the native library. +=cut + +=head1 DESCRIPTION + + With this module you can check at runtime which libraries and features were compiled in the library. + + Example usage: + + use AI::MXNet qw(mx); + my $features = mx->runtime->Features(); + + print $features->is_enabled("CUDNN"); + 0 + + print $features->is_enabled("CPU_SSE"); + 1 + + print Dumper($features->features); + $VAR1 = { + 'LAPACK' => 1, + 'F16C' => 1, + 'CPU_SSE2' => 1, + 'BLAS_MKL' => 0, + 'CXX14' => 0, + 'DIST_KVSTORE' => 0, + 'NCCL' => 0, + 'OPENMP' => 1, + 'CUDNN' => 0, + 'CPU_AVX' => 1, + 'CUDA_RTC' => 0, + 'BLAS_OPEN' => 1, + 'CPU_SSE4_2' => 1, + 'CPU_SSE4A' => 0, + 'TVM_OP' => 0, + 'MKLDNN' => 0, + 'TENSORRT' => 0, + 'JEMALLOC' => 1, + 'SSE' => 0, + 'PROFILER' => 0, + 'DEBUG' => 0, + 'BLAS_APPLE' => 0, + 'CPU_SSE3' => 1, + 'INT64_TENSOR_SIZE' => 0, + 'CPU_SSE4_1' => 1, + 'CUDA' => 0, + 'OPENCV' => 1, + 'CPU_SSE' => 1, + 'SIGNAL_HANDLER' => 0, + 'BLAS_ATLAS' => 0, + 'CAFFE' => 0, + 'CPU_AVX2' => 0 + }; + + print $features; + [✖ CUDA, ✖ CUDNN, ✖ NCCL, ✖ CUDA_RTC, ✖ TENSORRT, ✔ CPU_SSE, ✔ CPU_SSE2, ✔ CPU_SSE3, + ✔ CPU_SSE4_1, ✔ CPU_SSE4_2, ✖ CPU_SSE4A, ✔ CPU_AVX, ✖ CPU_AVX2, ✔ OPENMP, ✖ SSE, + ✔ F16C, ✔ JEMALLOC, ✔ BLAS_OPEN, ✖ BLAS_ATLAS, ✖ BLAS_MKL, ✖ BLAS_APPLE, ✔ LAPACK, + ✖ MKLDNN, ✔ OPENCV, ✖ CAFFE, ✖ PROFILER, ✖ DIST_KVSTORE, ✖ CXX14, ✖ INT64_TENSOR_SIZE, + ✔ SIGNAL_HANDLER, ✔ DEBUG, ✖ TVM_OP] + +=cut +use overload '""' => sub { + my $self = shift; + my $s = join(', ', map { + sprintf("%s %s", $self->features->{ $_ } ? '✔' : '✖', $_) + } sort keys %{ $self->features }); + return "[$s]"; +}; + +has 'features' => (is => 'rw', init_arg => undef, default => sub { + return scalar(check_call(AI::MXNetCAPI::LibInfoFeatures())); +}); + +method is_enabled(Str $feature) +{ + confess("Feature $feature does not exist") + unless exists $self->features->{ $feature }; + return $self->features->{ $feature }; +} + +my $features; +method Features() +{ + $features //= __PACKAGE__->new; + return $features; +} + +1; diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Symbol.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Symbol.pm index 32e1105210d5..6a472c1e9d8e 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Symbol.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Symbol.pm @@ -28,6 +28,7 @@ use AI::MXNet::NS; use AI::MXNet::Base; use AI::MXNet::Symbol::Base; use AI::MXNet::Symbol::Random; +use AI::MXNet::RunTime; use AI::MXNet::Types; use Mouse; use AI::MXNet::Function::Parameters; @@ -663,7 +664,16 @@ method _infer_shape_impl(Maybe[Str|Shape] @args) push @{ $indptr }, scalar(@{ $sdata }); } } - my $infer_func = $partial ? \&AI::MXNetCAPI::SymbolInferShapePartialEx : \&AI::MXNetCAPI::SymbolInferShapeEx; + my $is64 = AI::MXNet::RunTime->Features()->is_enabled('INT64_TENSOR_SIZE'); + my $infer_func = $partial + ? ( + $is64 ? \&AI::MXNetCAPI::SymbolInferShapePartialEx64 + : \&AI::MXNetCAPI::SymbolInferShapePartialEx + ) + : ( + $is64 ? \&AI::MXNetCAPI::SymbolInferShapeEx64 + : \&AI::MXNetCAPI::SymbolInferShapeEx + ); my ($arg_shapes, $out_shapes, $aux_shapes, $complete) = check_call( $infer_func->( $self->handle, @@ -934,11 +944,14 @@ method simple_bind( $aux_state_handles, $exe_handle ); + my $sub = AI::MXNet::RunTime->Features()->is_enabled('INT64_TENSOR_SIZE') + ? \&AI::MXNetCAPI::ExecutorSimpleBindEx64 + : \&AI::MXNetCAPI::ExecutorSimpleBindEx; eval { ($updated_shared_data, $in_arg_handles, $arg_grad_handles, $aux_state_handles, $exe_handle) = check_call( - AI::MXNetCAPI::ExecutorSimpleBindEx( + $sub->( $self->handle, $ctx->device_type_id, $ctx->device_id, diff --git a/perl-package/AI-MXNet/t/test_runtime.t b/perl-package/AI-MXNet/t/test_runtime.t new file mode 100644 index 000000000000..300ceb44e1de --- /dev/null +++ b/perl-package/AI-MXNet/t/test_runtime.t @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +use AI::MXNet qw(mx); +use AI::MXNet::TestUtils qw(dies_ok); +use Test::More 'no_plan'; +use Scalar::Util qw(refaddr); + +sub test_features +{ + my $features = mx->runtime->Features(); + ok(exists $features->features->{CUDA}); + ok(keys %{ $features->features } >= 30); +} + +sub test_is_singleton +{ + my $x = mx->runtime->Features(); + my $y = mx->runtime->Features(); + ok(refaddr($x) == refaddr($y)); +} + +sub test_is_enabled +{ + my $features = mx->runtime->Features(); + for my $f (keys %{ $features->features }) + { + if($features->features->{$f}) + { + ok($features->is_enabled($f)); + } + else + { + ok(not $features->is_enabled($f)); + } + } +} + +sub test_is_enabled_not_existing +{ + my $features = mx->runtime->Features(); + dies_ok(sub { $features->is_enabled("hello world") }); +} + +test_features(); +test_is_singleton(); +test_is_enabled(); +test_is_enabled_not_existing(); +done_testing(); \ No newline at end of file diff --git a/perl-package/AI-MXNetCAPI/Changes b/perl-package/AI-MXNetCAPI/Changes index 411be3604360..9028f0fc0ec1 100644 --- a/perl-package/AI-MXNetCAPI/Changes +++ b/perl-package/AI-MXNetCAPI/Changes @@ -1,4 +1,7 @@ Revision history for Perl extension AI::MXNetCAPI +1.5 Sun Feb 16 19:56:17 PST 2020 + - Runtime features + - INT64 Tensor support 1.4 Mon Feb 18 11:54:07 PST 2019 - Support for 64bit integers diff --git a/perl-package/AI-MXNetCAPI/META.json b/perl-package/AI-MXNetCAPI/META.json index 82bee1ace8f8..4c9520336d7c 100644 --- a/perl-package/AI-MXNetCAPI/META.json +++ b/perl-package/AI-MXNetCAPI/META.json @@ -37,5 +37,5 @@ } }, "release_status" : "stable", - "version" : "1.4" + "version" : "1.5" } diff --git a/perl-package/AI-MXNetCAPI/META.yml b/perl-package/AI-MXNetCAPI/META.yml index bd4af4047378..61e7a17385ce 100644 --- a/perl-package/AI-MXNetCAPI/META.yml +++ b/perl-package/AI-MXNetCAPI/META.yml @@ -36,4 +36,4 @@ no_index: - inc requires: Test::More: '0' -version: '1.4' +version: '1.5' diff --git a/perl-package/AI-MXNetCAPI/README b/perl-package/AI-MXNetCAPI/README index 5266a72a00ab..a19771c914f7 100644 --- a/perl-package/AI-MXNetCAPI/README +++ b/perl-package/AI-MXNetCAPI/README @@ -1,4 +1,4 @@ -AI-MXNetCAPI version 1.4 +AI-MXNetCAPI version 1.5 ===================== Swig interface to MXNet c api. diff --git a/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm b/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm index e3b71f8efc92..bf44b1b13278 100644 --- a/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm +++ b/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm @@ -18,7 +18,7 @@ package AI::MXNetCAPI; use base qw(DynaLoader); bootstrap AI::MXNetCAPI; -our $VERSION = '1.4'; +our $VERSION = '1.5'; 1; __END__ diff --git a/perl-package/AI-MXNetCAPI/mxnet.i b/perl-package/AI-MXNetCAPI/mxnet.i index f35f620bfca9..3bc53d6442c1 100644 --- a/perl-package/AI-MXNetCAPI/mxnet.i +++ b/perl-package/AI-MXNetCAPI/mxnet.i @@ -194,7 +194,7 @@ XS(py_zip) { %} /*! \brief manually define unsigned int */ -typedef unsigned int mx_uint; +typedef uint32_t mx_uint; /*! \brief manually define float */ typedef float mx_float; // all the handles are simply void * @@ -274,6 +274,14 @@ struct NDArrayOpInfo { */ const char *MXGetLastError(); +/*! + * \brief Get list of features supported on the runtime + * \param libFeature pointer to array of LibFeature + * \param size of the array + * \return 0 when success, -1 when failure happens. + */ +int MXLibInfoFeatures(const LibFeature **libFeature, size_t *size); + //------------------------------------- // Part 0: Global State setups //------------------------------------- @@ -384,8 +392,8 @@ int MXNDArrayCreateNone(NDArrayHandle *out); * \param out the returning handle * \return 0 when success, -1 when failure happens */ -int MXNDArrayCreate(const mx_uint *in, - mx_uint ndim, +int MXNDArrayCreate(const uint32_t *in, + uint32_t in, int dev_type, int dev_id, int delay_alloc, @@ -403,13 +411,34 @@ int MXNDArrayCreate(const mx_uint *in, * \param out the returning handle * \return 0 when success, -1 when failure happens */ -int MXNDArrayCreateEx(const mx_uint *in, - mx_uint ndim, +int MXNDArrayCreateEx(const uint32_t *in, + uint32_t in, int dev_type, int dev_id, int delay_alloc, int dtype, NDArrayHandle *out); +/*! + * \brief create a NDArray with specified shape and data type + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * \param shape the pointer to int64_t shape + * \param ndim the dimension of the shape + * \param dev_type device type, specify device we want to take + * \param dev_id the device id of the specific device + * \param delay_alloc whether to delay allocation until + * the narray is first mutated + * \param dtype data type of created array + * \param out the returning handle + * \return 0 when success, -1 when failure happens + */ +int MXNDArrayCreateEx64(const int64_t *in, + int ndim, + int dev_type, + int dev_id, + int delay_alloc, + int dtype, + NDArrayHandle *out); /*! * \brief create an empty sparse NDArray with specified shape and data type * \param storage_type the storage type of the ndarray @@ -428,19 +457,48 @@ int MXNDArrayCreateEx(const mx_uint *in, * \return 0 when success, -1 when failure happens */ int MXNDArrayCreateSparseEx(int storage_type, - const mx_uint *in, - mx_uint ndim, + const uint32_t *in, + uint32_t in, int dev_type, int dev_id, int delay_alloc, int dtype, - mx_uint num_aux, + uint32_t in, int *in, - mx_uint *in, - const mx_uint *in, + uint32_t *in, + const uint32_t *in, NDArrayHandle *out); - - +/*! + * \brief create an empty sparse NDArray with specified shape and data type + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * \param storage_type the storage type of the ndarray + * \param shape the pointer to the shape + * \param ndim the dimension of the shape + * \param dev_type device type, specify device we want to take + * \param dev_id the device id of the specific device + * \param delay_alloc whether to delay allocation until + * the narray is first mutated + * \param dtype data type of created array + * \param num_aux the number of aux data to support this ndarray + * \param aux_type data type of the aux data for the created array + * \param aux_ndims the dimension of the shapes of aux data + * \param aux_shape the shapes of aux data + * \param out the returning handle + * \return 0 when success, -1 when failure happens + */ +int MXNDArrayCreateSparseEx64(int storage_type, + const int64_t *in, + int ndim, + int dev_type, + int dev_id, + int delay_alloc, + int dtype, + uint32_t in, + int *in, + int *in, + const int64_t *in, + NDArrayHandle *out); /*! * \brief create a NDArray handle that is loaded from raw bytes. * \param buf the head of the raw bytes @@ -470,7 +528,7 @@ int MXNDArraySaveRawBytes(NDArrayHandle handle, * \return 0 when success, -1 when failure happens */ int MXNDArraySave(const char* fname, - mx_uint num_args, + uint32_t in, NDArrayHandle* in, const char** in); /*! @@ -483,9 +541,9 @@ int MXNDArraySave(const char* fname, * \return 0 when success, -1 when failure happens */ int MXNDArrayLoad(const char* fname, - mx_uint *out_size, + uint32_t *out_size, NDArrayHandle** out_array, - mx_uint *out_size, + uint32_t *out_size, const char*** out_array); /*! @@ -504,13 +562,13 @@ int MXNDArrayLoad(const char* fname, */ int MXNDArrayLoadFromBuffer(const void *in, size_t size, - mx_uint *out_size, + uint32_t *out_size, NDArrayHandle** out_array, - mx_uint *out_size, + uint32_t *out_size, const char*** out_array); /*! - * \brief Perform a synchronize copy from a contiguous CPU memory region. + * \brief Perform a synchronized copy from a contiguous CPU memory region. * * This function will call WaitToWrite before the copy is performed. * This is useful to copy data from existing memory region that are @@ -524,7 +582,7 @@ int MXNDArraySyncCopyFromCPU(NDArrayHandle handle, const void *in, size_t size); /*! - * \brief Perform a synchronize copy to a contiguous CPU memory region. + * \brief Perform a synchronized copy to a contiguous CPU memory region. * * This function will call WaitToRead before the copy is performed. * This is useful to copy data from existing memory region that are @@ -589,9 +647,24 @@ int MXNDArrayFree(NDArrayHandle handle); * \return 0 when success, -1 when failure happens */ int MXNDArraySlice(NDArrayHandle handle, - mx_uint slice_begin, - mx_uint slice_end, + uint32_t in, + uint32_t in, NDArrayHandle *out); +/*! + * \brief Slice the NDArray along axis 0. + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * \param handle the handle to the NDArray + * \param slice_begin The beginning index of slice + * \param slice_end The ending index of slice + * \param out The NDArrayHandle of sliced NDArray + * \return 0 when success, -1 when failure happens + */ +int MXNDArraySlice64(NDArrayHandle handle, + int64_t in, + int64_t in, + NDArrayHandle *out); + /*! * \brief Index the NDArray along axis 0. * \param handle the handle to the NDArray @@ -600,8 +673,20 @@ int MXNDArraySlice(NDArrayHandle handle, * \return 0 when success, -1 when failure happens */ int MXNDArrayAt(NDArrayHandle handle, - mx_uint idx, + uint32_t in, NDArrayHandle *out); +/*! + * \brief Index the NDArray along axis 0. + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * \param handle the handle to the NDArray + * \param idx the index + * \param out The NDArrayHandle of output NDArray + * \return 0 when success, -1 when failure happens + */ +int MXNDArrayAt64(NDArrayHandle handle, + int64_t in, + NDArrayHandle *out); /*! * \brief get the storage type of the array */ @@ -643,6 +728,18 @@ int MXNDArrayReshape64(NDArrayHandle handle, int MXNDArrayGetShapeEx(NDArrayHandle handle, int *out_dim, const int **out_pdata); +/*! + * \brief get the shape of the array + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * \param handle the handle to the narray + * \param out_dim the output dimension + * \param out_pdata pointer holder to get data pointer of the shape + * \return 0 when success, -1 when failure happens + */ +int MXNDArrayGetShapeEx64(NDArrayHandle handle, + int *out_dim, + const int64_t **out_pdata); /*! * \brief get the content of the data in NDArray * \param handle the handle to the ndarray @@ -667,16 +764,40 @@ int MXNDArrayGetDType(NDArrayHandle handle, * \return 0 when success, -1 when failure happens */ int MXNDArrayGetAuxType(NDArrayHandle handle, - mx_uint i, + uint32_t in, int *out); +/*! + * \brief get the type of the ith aux data in NDArray + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * \param handle the handle to the narray + * \param i the index of the aux data + * \param out_type pointer holder to get type of aux data + * \return 0 when success, -1 when failure happens + */ +// int MXNDArrayGetAuxType64(NDArrayHandle handle, +// int64_t i, +// int *out); + /*! * \brief Get a deep copy of the ith aux data blob * in the form of an NDArray of default storage type. * This function blocks. Do not use it in performance critical code. */ int MXNDArrayGetAuxNDArray(NDArrayHandle handle, - mx_uint i, + uint32_t in, NDArrayHandle *out); +/*! + * \brief Get a deep copy of the ith aux data blob + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * in the form of an NDArray of default storage type. + * This function blocks. Do not use it in performance critical code. + */ +// int MXNDArrayGetAuxNDArray64(NDArrayHandle handle, +// int64_t i, +// NDArrayHandle *out); + /*! * \brief Get a deep copy of the data blob * in the form of an NDArray of default storage type. @@ -735,7 +856,7 @@ int MXNDArrayGetGradState(NDArrayHandle handle, int *out); * \param out_array the output function array * \return 0 when success, -1 when failure happens */ -int MXListFunctions(mx_uint *out_size, +int MXListFunctions(uint32_t *out_size, FunctionHandle **out_array); /*! * \brief get the function handle by name @@ -760,7 +881,7 @@ int MXGetFunction(const char *name, int MXFuncGetInfo(FunctionHandle fun, const char **name, const char **description, - mx_uint *num_args, + uint32_t *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions @@ -776,9 +897,9 @@ int MXFuncGetInfo(FunctionHandle fun, * \sa MXFuncInvoke */ int MXFuncDescribe(FunctionHandle fun, - mx_uint *out, - mx_uint *out, - mx_uint *out, + uint32_t *out, + uint32_t *out, + uint32_t *out, int *out); /*! * \brief invoke a function, the array size of passed in arguments @@ -792,7 +913,7 @@ int MXFuncDescribe(FunctionHandle fun, */ int MXFuncInvoke(FunctionHandle fun, NDArrayHandle *in, - mx_float *in, + float *in, NDArrayHandle *in); /*! * \brief invoke a function, the array size of passed in arguments @@ -809,7 +930,7 @@ int MXFuncInvoke(FunctionHandle fun, */ int MXFuncInvokeEx(FunctionHandle fun, NDArrayHandle *in, - mx_float *in, + float *in, NDArrayHandle *in, int num_params, char **keys, @@ -893,9 +1014,9 @@ int MXAutogradIsTraining(bool* out); * \param var_handles variable NDArrays * \return 0 when success, -1 when failure happens */ -int MXAutogradMarkVariables(mx_uint num_var, +int MXAutogradMarkVariables(uint32_t in, NDArrayHandle *in, - mx_uint *in, + uint32_t *in, NDArrayHandle *in); /*! * \brief compute the gradient of outputs w.r.t variables @@ -903,7 +1024,7 @@ int MXAutogradMarkVariables(mx_uint num_var, * \param output_handles output NDArrays * \return 0 when success, -1 when failure happens */ -int MXAutogradComputeGradient(mx_uint num_output, +int MXAutogradComputeGradient(uint32_t in, NDArrayHandle* in); /*! * \brief compute the gradient of outputs w.r.t variabels @@ -913,7 +1034,7 @@ int MXAutogradComputeGradient(mx_uint num_output, * \param retain_graph whether to keep the graph after backward * \return 0 when success, -1 when failure happens */ -int MXAutogradBackward(mx_uint num_output, +int MXAutogradBackward(uint32_t in, NDArrayHandle* in, NDArrayHandle* in, int retain_graph); @@ -927,10 +1048,10 @@ int MXAutogradBackward(mx_uint num_output, * \param is_train whether to do backward for training or inference * \return 0 when success, -1 when failure happens */ -int MXAutogradBackwardEx(mx_uint num_output, +int MXAutogradBackwardEx(uint32_t in, NDArrayHandle *in, NDArrayHandle *in, - mx_uint num_variables, + uint32_t in, NDArrayHandle *in, int retain_graph, int create_graph, @@ -995,7 +1116,7 @@ int MXInvokeCachedOpEx(CachedOpHandle handle, * \param out_array the output operator name array. * \return 0 when success, -1 when failure happens */ -int MXListAllOpNames(mx_uint *out_size, +int MXListAllOpNames(uint32_t *out_size, const char ***out_array); /*! * \brief list all the available AtomicSymbolEntry @@ -1003,7 +1124,7 @@ int MXListAllOpNames(mx_uint *out_size, * \param out_array the output AtomicSymbolCreator array * \return 0 when success, -1 when failure happens */ -int MXSymbolListAtomicSymbolCreators(mx_uint *out_size, +int MXSymbolListAtomicSymbolCreators(uint32_t *out_size, AtomicSymbolCreator **out_array); /*! @@ -1033,7 +1154,7 @@ int MXSymbolGetAtomicSymbolName(AtomicSymbolCreator in, int MXSymbolGetAtomicSymbolInfo(AtomicSymbolCreator in, const char **name, const char **description, - mx_uint *num_args, + uint32_t *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions, @@ -1049,7 +1170,7 @@ int MXSymbolGetAtomicSymbolInfo(AtomicSymbolCreator in, * \return 0 when success, -1 when failure happens */ int MXSymbolCreateAtomicSymbol(AtomicSymbolCreator in, - mx_uint num_param, + uint32_t in, const char **keys, const char **vals, SymbolHandle *out); @@ -1067,7 +1188,7 @@ int MXSymbolCreateVariable(const char *name, SymbolHandle *out); * \param out pointer to the created symbol handle * \return 0 when success, -1 when failure happens */ -int MXSymbolCreateGroup(mx_uint num_symbols, +int MXSymbolCreateGroup(uint32_t in, SymbolHandle *in, SymbolHandle *out); /*! @@ -1167,7 +1288,7 @@ int MXSymbolSetAttr(SymbolHandle symbol, * \return 0 when success, -1 when failure happens */ int MXSymbolListAttr(SymbolHandle symbol, - mx_uint *out_size, + uint32_t *out_size, const char*** out_array2); /*! * \brief Get all attributes from symbol, excluding descendents. @@ -1177,7 +1298,7 @@ int MXSymbolListAttr(SymbolHandle symbol, * \return 0 when success, -1 when failure happens */ int MXSymbolListAttrShallow(SymbolHandle symbol, - mx_uint *out_size, + uint32_t *out_size, const char*** out_array2); /*! * \brief List arguments in the symbol. @@ -1187,7 +1308,7 @@ int MXSymbolListAttrShallow(SymbolHandle symbol, * \return 0 when success, -1 when failure happens */ int MXSymbolListArguments(SymbolHandle symbol, - mx_uint *out_size, + uint32_t *out_size, const char ***out_array); /*! * \brief List returns in the symbol. @@ -1197,7 +1318,7 @@ int MXSymbolListArguments(SymbolHandle symbol, * \return 0 when success, -1 when failure happens */ int MXSymbolListOutputs(SymbolHandle symbol, - mx_uint *out_size, + uint32_t *out_size, const char ***out_array); /*! * \brief Get a symbol that contains all the internals. @@ -1223,8 +1344,10 @@ int MXSymbolGetChildren(SymbolHandle symbol, * \return 0 when success, -1 when failure happens */ int MXSymbolGetOutput(SymbolHandle symbol, - mx_uint index, + mx_uint in, SymbolHandle *out); +int MXSymbolGetNumOutputs(SymbolHandle symbol, + uint32_t *out); /*! * \brief List auxiliary states in the symbol. * \param symbol the symbol @@ -1233,7 +1356,7 @@ int MXSymbolGetOutput(SymbolHandle symbol, * \return 0 when success, -1 when failure happens */ int MXSymbolListAuxiliaryStates(SymbolHandle symbol, - mx_uint *out_size, + uint32_t *out_size, const char ***out_array); /*! * \brief Compose the symbol on other symbols. @@ -1251,7 +1374,7 @@ int MXSymbolListAuxiliaryStates(SymbolHandle symbol, */ int MXSymbolCompose(SymbolHandle sym, const char *name, - mx_uint num_args, + uint32_t in, const char** in, SymbolHandle* in); /*! @@ -1264,7 +1387,7 @@ int MXSymbolCompose(SymbolHandle sym, * \return 0 when success, -1 when failure happens */ int MXSymbolGrad(SymbolHandle sym, - mx_uint num_wrt, + uint32_t in, const char** in, SymbolHandle* out); /*! @@ -1290,20 +1413,59 @@ int MXSymbolGrad(SymbolHandle sym, * \return 0 when success, -1 when failure happens */ int MXSymbolInferShapeEx(SymbolHandle sym, - mx_uint num_args, + uint32_t in, const char** in, - const mx_uint *in, + const uint32_t *in, const int *in, - mx_uint *in_shape_size, + uint32_t *in_shape_size, const int **in_shape_ndim, const int ***in_shape_data, - mx_uint *out_shape_size, + uint32_t *out_shape_size, const int **out_shape_ndim, const int ***out_shape_data, - mx_uint *aux_shape_size, + uint32_t *aux_shape_size, const int **aux_shape_ndim, const int ***aux_shape_data, int *out); +/*! + * \brief infer shape of unknown input shapes given the known one. + * The shapes are packed into a CSR matrix represented by arg_ind_ptr and arg_shape_data + * The call will be treated as a kwargs call if key != NULL or num_args==0, otherwise it is positional. + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * \param sym symbol handle + * \param num_args number of input arguments. + * \param keys the key of keyword args (optional) + * \param arg_ind_ptr the head pointer of the rows in CSR + * \param arg_shape_data the content of the CSR + * \param in_shape_size sizeof the returning array of in_shapes + * \param in_shape_ndim returning array of shape dimensions of each input shape. + * \param in_shape_data returning array of pointers to head of the input shape. + * \param out_shape_size sizeof the returning array of out_shapes + * \param out_shape_ndim returning array of shape dimensions of each output shape. + * \param out_shape_data returning array of pointers to head of the output shape. + * \param aux_shape_size sizeof the returning array of aux_shapes + * \param aux_shape_ndim returning array of shape dimensions of each auxiliary shape. + * \param aux_shape_data returning array of pointers to head of the auxiliary shape. + * \param complete whether infer shape completes or more information is needed. + * \return 0 when success, -1 when failure happens + */ +int MXSymbolInferShapeEx64(SymbolHandle sym, + uint32_t in, + const char** in, + const int64_t *in, + const int64_t *in, + size_t *in_shape_size, + const int **in_shape_ndim, + const int64_t ***in_shape_data, + size_t *out_shape_size, + const int **out_shape_ndim, + const int64_t ***out_shape_data, + size_t *aux_shape_size, + const int **aux_shape_ndim, + const int64_t ***aux_shape_data, + int *out); + /*! * \brief partially infer shape of unknown input shapes given the known one. * @@ -1329,20 +1491,61 @@ int MXSymbolInferShapeEx(SymbolHandle sym, * \return 0 when success, -1 when failure happens */ int MXSymbolInferShapePartialEx(SymbolHandle sym, - mx_uint num_args, + uint32_t in, const char** in, - const mx_uint *in, + const uint32_t *in, const int *in, - mx_uint *in_shape_size, + uint32_t *in_shape_size, const int **in_shape_ndim, const int ***in_shape_data, - mx_uint *out_shape_size, + uint32_t *out_shape_size, const int **out_shape_ndim, const int ***out_shape_data, - mx_uint *aux_shape_size, + uint32_t *aux_shape_size, const int **aux_shape_ndim, const int ***aux_shape_data, int *out); +/*! + * \brief partially infer shape of unknown input shapes given the known one. + * + * Return partially inferred results if not all shapes could be inferred. + * The shapes are packed into a CSR matrix represented by arg_ind_ptr and arg_shape_data + * The call will be treated as a kwargs call if key != NULL or num_args==0, otherwise it is positional. + * This api is available when MXNet is built with flag + * USE_INT64_TENSOR_SIZE=1 (not default) i.e. Large Tensor Support + * + * \param sym symbol handle + * \param num_args number of input arguments. + * \param keys the key of keyword args (optional) + * \param arg_ind_ptr the head pointer of the rows in CSR + * \param arg_shape_data the content of the CSR + * \param in_shape_size sizeof the returning array of in_shapes + * \param in_shape_ndim returning array of shape dimensions of each input shape. + * \param in_shape_data returning array of pointers to head of the input shape. + * \param out_shape_size sizeof the returning array of out_shapes + * \param out_shape_ndim returning array of shape dimensions of each output shape. + * \param out_shape_data returning array of pointers to head of the output shape. + * \param aux_shape_size sizeof the returning array of aux_shapes + * \param aux_shape_ndim returning array of shape dimensions of each auxiliary shape. + * \param aux_shape_data returning array of pointers to head of the auxiliary shape. + * \param complete whether infer shape completes or more information is needed. + * \return 0 when success, -1 when failure happens + */ +int MXSymbolInferShapePartialEx64(SymbolHandle sym, + uint32_t in, + const char** in, + const int64_t *in, + const int64_t *in, + size_t *in_shape_size, + const int **in_shape_ndim, + const int64_t ***in_shape_data, + size_t *out_shape_size, + const int **out_shape_ndim, + const int64_t ***out_shape_data, + size_t *aux_shape_size, + const int **aux_shape_ndim, + const int64_t ***aux_shape_data, + int *out); /*! * \brief infer type of unknown input types given the known one. @@ -1363,16 +1566,76 @@ int MXSymbolInferShapePartialEx(SymbolHandle sym, * \return 0 when success, -1 when failure happens */ int MXSymbolInferType(SymbolHandle sym, - mx_uint num_args, + uint32_t in, const char** in, const int *in, - mx_uint *in_type_size, + uint32_t *in_type_size, const int **in_type_data, - mx_uint *out_type_size, + uint32_t *out_type_size, const int **out_type_data, - mx_uint *aux_type_size, + uint32_t *aux_type_size, const int **aux_type_data, int *out); +/*! + * \brief partially infer type of unknown input types given the known one. + * + * Return partially inferred results if not all types could be inferred. + * The types are packed into a CSR matrix represented by arg_ind_ptr and arg_type_data + * The call will be treated as a kwargs call if key != NULL or num_args==0, otherwise it is positional. + * + * \param sym symbol handle + * \param num_args numbe of input arguments. + * \param keys the key of keyword args (optional) + * \param arg_type_data the content of the CSR + * \param in_type_size sizeof the returning array of in_types + * \param in_type_data returning array of pointers to head of the input type. + * \param out_type_size sizeof the returning array of out_types + * \param out_type_data returning array of pointers to head of the output type. + * \param aux_type_size sizeof the returning array of aux_types + * \param aux_type_data returning array of pointers to head of the auxiliary type. + * \param complete whether infer type completes or more information is needed. + * \return 0 when success, -1 when failure happens + */ +int MXSymbolInferTypePartial(SymbolHandle sym, + uint32_t in, + const char** in, + const int *in, + uint32_t *in_type_size, + const int **in_type_data, + uint32_t *out_type_size, + const int **out_type_data, + uint32_t *aux_type_size, + const int **aux_type_data, + int *out); +/*! + * \brief Generate atomic symbol (able to be composed) from a source symbol + * \param sym_handle source symbol + * \param ret_sym_handle returned atomic symbol + */ +int MXGenAtomicSymbolFromSymbol(SymbolHandle sym_handle, SymbolHandle *out); + +/*! + * \brief Partitions symbol for given backend, potentially creating subgraphs + * \param sym_handle symbol to be partitioned + * \param dev_type context device type + * \param backend_name backend name + * \param ret_sym_handle partitioned symbol returned + * \param len number of args + * \param in_args_handle args array + * \param num_options number of key value pairs + * \param keys keys for options + * \param vals values corresponding to keys + */ +int MXOptimizeForBackend(SymbolHandle sym_handle, + const char* in, + const int dev_type, + SymbolHandle* in, + const mx_uint in, + NDArrayHandle* in, + const mx_uint in, + const char** keys, + const char** vals); + //-------------------------------------------- // Part 4: Executor interface //-------------------------------------------- @@ -1407,7 +1670,7 @@ int MXExecutorForward(ExecutorHandle handle, int is_train); * \return 0 when success, -1 when failure happens */ int MXExecutorBackward(ExecutorHandle handle, - mx_uint len, + uint32_t in, NDArrayHandle *in); /*! @@ -1421,7 +1684,7 @@ int MXExecutorBackward(ExecutorHandle handle, * \return 0 when success, -1 when failure happens */ int MXExecutorBackwardEx(ExecutorHandle handle, - mx_uint len, + uint32_t in, NDArrayHandle *in, int is_train); @@ -1434,7 +1697,7 @@ int MXExecutorBackwardEx(ExecutorHandle handle, * \return 0 when success, -1 when failure happens */ int MXExecutorOutputs(ExecutorHandle handle, - mx_uint *out_size, + uint32_t *out_size, NDArrayHandle **out_array); /*! @@ -1455,11 +1718,11 @@ int MXExecutorOutputs(ExecutorHandle handle, int MXExecutorBind(SymbolHandle symbol_handle, int dev_type, int dev_id, - mx_uint len, + uint32_t in, NDArrayHandle *in, NDArrayHandle *in, - mx_uint *in, - mx_uint aux_states_len, + uint32_t *in, + uint32_t aux_states_len, NDArrayHandle *in, ExecutorHandle *out); /*! @@ -1486,15 +1749,15 @@ int MXExecutorBind(SymbolHandle symbol_handle, int MXExecutorBindX(SymbolHandle symbol_handle, int dev_type, int dev_id, - mx_uint num_map_keys, + uint32_t in, const char** in, const int* in, const int* in, - mx_uint len, + uint32_t in, NDArrayHandle *in, NDArrayHandle *in, - mx_uint *in, - mx_uint aux_states_len, + uint32_t *in, + uint32_t in, NDArrayHandle *in, ExecutorHandle *out); /*! @@ -1522,15 +1785,15 @@ int MXExecutorBindX(SymbolHandle symbol_handle, int MXExecutorBindEX(SymbolHandle symbol_handle, int dev_type, int dev_id, - mx_uint num_map_keys, + uint32_t in, const char** in, const int* in, const int* in, - mx_uint len, + uint32_t in, NDArrayHandle *in, NDArrayHandle *in, - mx_uint *in, - mx_uint aux_states_len, + uint32_t *in, + uint32_t in, NDArrayHandle *in, ExecutorHandle shared_exec, ExecutorHandle *out); @@ -1538,39 +1801,74 @@ int MXExecutorBindEX(SymbolHandle symbol_handle, int MXExecutorSimpleBindEx(SymbolHandle symbol_handle, int dev_type, int dev_id, - const mx_uint num_g2c_keys, + const uint32_t in, // num_g2c_keys, const char** in, // g2c_keys, const int* in, // g2c_dev_types, const int* in, // g2c_dev_ids, - const mx_uint provided_grad_req_list_len, + const uint32_t in, // provided_grad_req_list_len, const char** in, // provided_grad_req_names, const char** in, // provided_grad_req_types, - const mx_uint num_provided_arg_shapes, + const uint32_t in, // num_provided_arg_shapes, const char** in, // provided_arg_shape_names, const int* in, // provided_arg_shape_data, - const mx_uint* in, // provided_arg_shape_idx, - const mx_uint num_provided_arg_dtypes, + const uint32_t* in, // provided_arg_shape_idx, + const uint32_t in, // num_provided_arg_dtypes, const char** in, // provided_arg_dtype_names, const int* in, // provided_arg_dtypes, - const mx_uint num_provided_arg_stypes, + const uint32_t in, // num_provided_arg_stypes, const char** in, // provided_arg_stype_names, const int* in, // provided_arg_stypes, - const mx_uint num_shared_arg_names, + const uint32_t in, // num_shared_arg_names, const char** in, // shared_arg_name_list, int* shared_buffer_len, const char** shared_buffer_name_list, NDArrayHandle* shared_buffer_handle_list, const char*** updated_shared_buffer_name_list, NDArrayHandle** updated_shared_buffer_handle_list, - mx_uint* num_in_args, + uint32_t* num_in_args, NDArrayHandle** in_args, NDArrayHandle** arg_grads, - mx_uint* num_aux_states, + uint32_t* num_aux_states, NDArrayHandle** aux_states, ExecutorHandle shared_exec_handle, ExecutorHandle* out ); +int MXExecutorSimpleBindEx64(SymbolHandle symbol_handle, + int dev_type, + int dev_id, + const uint32_t in, // num_g2c_keys, + const char** in, // g2c_keys, + const int* in, // g2c_dev_types, + const int* in, // g2c_dev_ids, + const uint32_t in, // provided_grad_req_list_len, + const char** in, // provided_grad_req_names, + const char** in, // provided_grad_req_types, + const uint32_t in, // num_provided_arg_shapes, + const char** in, // provided_arg_shape_names, + const int64_t* in, // provided_arg_shape_data, + const uint32_t* in, // provided_arg_shape_idx, + const uint32_t in, // num_provided_arg_dtypes, + const char** in, // provided_arg_dtype_names, + const int* in, // provided_arg_dtypes, + const uint32_t in, // num_provided_arg_stypes, + const char** in, // provided_arg_stype_names, + const int* in, // provided_arg_stypes, + const uint32_t in, // num_shared_arg_names, + const char** in, // shared_arg_name_list, + int* shared_buffer_len, + const char** shared_buffer_name_list, + NDArrayHandle* shared_buffer_handle_list, + const char*** updated_shared_buffer_name_list, + NDArrayHandle** updated_shared_buffer_handle_list, + uint32_t* num_in_args, + NDArrayHandle** in_args, + NDArrayHandle** arg_grads, + uint32_t* num_aux_states, + NDArrayHandle** aux_states, + ExecutorHandle shared_exec_handle, + ExecutorHandle* out); + /*! * \brief Return a new executor with the same symbol and shared memory, * but different input/output shapes. @@ -1596,21 +1894,26 @@ int MXExecutorReshapeEx(int partial_shaping, int allow_up_sizing, int dev_type, int dev_id, - mx_uint num_map_keys, + uint32_t in, const char** in, const int* in, const int* in, - const mx_uint num_provided_arg_shapes, + const uint32_t in, const char** in, const int* in, - const mx_uint* in, - mx_uint* couple_out_size, + const uint32_t* in, + uint32_t* couple_out_size, NDArrayHandle** out_first_array, NDArrayHandle** out_second_array, - mx_uint* out_size, + uint32_t* out_size, NDArrayHandle** out_array, ExecutorHandle shared_exec, ExecutorHandle *out); + /*! + * \brief get optimized graph from graph executor + */ +int MXExecutorGetOptimizedSymbol(ExecutorHandle handle, + SymbolHandle *out); /*! * \brief set a call back to notify the completion of operation @@ -1628,7 +1931,7 @@ int MXExecutorSetMonitorCallback(ExecutorHandle handle, * \param out_array the output iteratos entries * \return 0 when success, -1 when failure happens */ -int MXListDataIters(mx_uint *out_size, +int MXListDataIters(uint32_t *out_size, DataIterCreator **out_array); /*! * \brief Init an iterator, init with parameters @@ -1641,7 +1944,7 @@ int MXListDataIters(mx_uint *out_size, * \return 0 when success, -1 when failure happens */ int MXDataIterCreateIter(DataIterCreator handle, - mx_uint num_param, + uint32_t in, const char **keys, const char **vals, DataIterHandle *out); @@ -1659,7 +1962,7 @@ int MXDataIterCreateIter(DataIterCreator handle, int MXDataIterGetIterInfo(DataIterCreator creator, const char **name, const char **description, - mx_uint *num_args, + uint32_t *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions); @@ -1728,7 +2031,7 @@ int MXDataIterGetLabel(DataIterHandle handle, * \param keys environment keys * \param vals environment values */ -int MXInitPSEnv(mx_uint num_vars, +int MXInitPSEnv(uint32_t in, const char **keys, const char **vals); @@ -1755,7 +2058,7 @@ int MXKVStoreFree(KVStoreHandle handle); * \return 0 when success, -1 when failure happens */ int MXKVStoreSetGradientCompression(KVStoreHandle handle, - mx_uint num_params, + uint32_t in, const char** keys, const char** vals); @@ -1769,7 +2072,7 @@ int MXKVStoreSetGradientCompression(KVStoreHandle handle, * \return 0 when success, -1 when failure happens */ int MXKVStoreInitEx(KVStoreHandle handle, - mx_uint num, + uint32_t in, const char** in, NDArrayHandle* in); /*! @@ -1782,7 +2085,7 @@ int MXKVStoreInitEx(KVStoreHandle handle, * \return 0 when success, -1 when failure happens */ int MXKVStorePushEx(KVStoreHandle handle, - mx_uint num, + uint32_t in, const char** in, NDArrayHandle* in, int priority); @@ -1796,7 +2099,7 @@ int MXKVStorePushEx(KVStoreHandle handle, * \return 0 when success, -1 when failure happens */ int MXKVStorePullEx(KVStoreHandle handle, - mx_uint num, + uint32_t in, const char** in, NDArrayHandle* in, int priority); @@ -1813,7 +2116,7 @@ int MXKVStorePullEx(KVStoreHandle handle, * \return 0 when success, -1 when failure happens */ int MXKVStorePullRowSparse(KVStoreHandle handle, - mx_uint num, + uint32_t in, const int* in, NDArrayHandle* in, NDArrayHandle* in, @@ -1831,7 +2134,7 @@ int MXKVStorePullRowSparse(KVStoreHandle handle, * \return 0 when success, -1 when failure happens */ int MXKVStorePullRowSparseEx(KVStoreHandle handle, - mx_uint num, + uint32_t in, const char** in, NDArrayHandle* in, NDArrayHandle* in, @@ -1848,7 +2151,7 @@ int MXKVStorePullRowSparseEx(KVStoreHandle handle, * \return 0 when success, -1 when failure happens */ int MXKVStorePullWithSparseEx(KVStoreHandle handle, - mx_uint num, + uint32_t in, const char** in, NDArrayHandle* in, int priority, @@ -2093,7 +2396,7 @@ int MXRecordIOReaderSeek(RecordIOHandle handle, size_t pos); /** * \brief Create a MXRtc object */ -int MXRtcCreate(char* name, mx_uint num_input, mx_uint num_output, +int MXRtcCreate(char* name, uint32_t in, uint32_t in, char** in, char** in, NDArrayHandle* in, NDArrayHandle* in, char* kernel, RtcHandle *out); @@ -2101,14 +2404,15 @@ int MXRtcCreate(char* name, mx_uint num_input, mx_uint num_output, /** * \brief Run cuda kernel */ -int MXRtcPush(RtcHandle handle, mx_uint num_input, mx_uint num_output, +int MXRtcPush(RtcHandle handle, uint32_t in, uint32_t in, NDArrayHandle* in, NDArrayHandle* in, - mx_uint gridDimX, - mx_uint gridDimY, - mx_uint gridDimZ, - mx_uint blockDimX, - mx_uint blockDimY, - mx_uint blockDimZ); + uint32_t in, // gridDimX, + uint32_t in, // gridDimY, + uint32_t in, // gridDimZ, + uint32_t in, // blockDimX, + uint32_t in, // blockDimY, + uint32_t in // blockDimZ +); /** * \brief Delete a MXRtc object @@ -2164,7 +2468,11 @@ int MXRtcCudaKernelFree(CudaKernelHandle handle); * \param shared_mem size of dynamically allocated shared memory */ int MXRtcCudaKernelCall(CudaKernelHandle handle, int dev_id, void** cuda_kernel_args, - mx_uint grid_dim_x, mx_uint grid_dim_y, - mx_uint grid_dim_z, mx_uint block_dim_x, - mx_uint block_dim_y, mx_uint block_dim_z, - mx_uint shared_mem); + uint32_t in, // grid_dim_x, + uint32_t in, // grid_dim_y, + uint32_t in, // grid_dim_z, + uint32_t in, // block_dim_x, + uint32_t in, // block_dim_y, + uint32_t in, // block_dim_z, + uint32_t in // shared_mem +); diff --git a/perl-package/AI-MXNetCAPI/mxnet_typemaps.i b/perl-package/AI-MXNetCAPI/mxnet_typemaps.i index 3ec9f95ea9c3..aad098750810 100644 --- a/perl-package/AI-MXNetCAPI/mxnet_typemaps.i +++ b/perl-package/AI-MXNetCAPI/mxnet_typemaps.i @@ -115,7 +115,7 @@ } } -%typemap(in,numinputs=0) (int *out) (int temp), (bool *out) (bool temp), (uint64_t *out) (uint64_t temp) +%typemap(in,numinputs=0) (int *out) (int temp), (bool *out) (bool temp), (uint64_t *out) (uint64_t temp), (int64_t *out) (int64_t temp) { temp = 0; $1 = &temp; @@ -131,7 +131,7 @@ } } -%typemap(argout) (uint64_t *out) +%typemap(argout) (uint64_t *out), (int64_t *out) { if(!result) { @@ -169,7 +169,8 @@ } %typemap(in,numinputs=0) (nn_uint *out_size, const char ***out_array) (nn_uint temp_size, char** temp), - (mx_uint *out_size, const char ***out_array) (mx_uint temp_size, char** temp) + (mx_uint *out_size, const char ***out_array) (mx_uint temp_size, char** temp), + (uint32_t *out_size, const char ***out_array) (uint32_t temp_size, char** temp) { $1 = &temp_size; *$1 = 0; @@ -177,7 +178,8 @@ } %typemap(argout) (nn_uint *out_size, const char ***out_array), - (mx_uint *out_size, const char ***out_array) + (mx_uint *out_size, const char ***out_array), + (uint32_t *out_size, const char ***out_array) { if(!result) { @@ -197,14 +199,38 @@ } } -%typemap(in,numinputs=0) (mx_uint *out_size, const char ***out_array2) (mx_uint temp_size, char** temp) +%typemap(in,numinputs=0) (const LibFeature **libFeature, size_t *size) (LibFeature *temp1, size_t temp2) +{ + $1 = &temp1; + $2 = &temp2; + *$2 = 0; +} + +%typemap(argout) (const LibFeature **libFeature, size_t *size) +{ + if(!result) + { + HV* hash = newHV(); + for(int i = 0; i < *$2; i++) + { + hv_store(hash, ((*$1)[i]).name, strlen(((*$1)[i]).name), newSViv(((*$1)[i]).enabled), 0); + } + $result = newRV_noinc((SV*)hash); + sv_2mortal($result); + argvi++; + } +} + +%typemap(in,numinputs=0) (mx_uint *out_size, const char ***out_array2) (mx_uint temp_size, char** temp), + (uint32_t *out_size, const char ***out_array2) (uint32_t temp_size, char** temp) { $1 = &temp_size; *$1 = 0; $2 = &temp; } -%typemap(argout) (mx_uint *out_size, const char ***out_array2) +%typemap(argout) (mx_uint *out_size, const char ***out_array2), + (uint32_t *out_size, const char ***out_array2) { if(!result) { @@ -224,6 +250,21 @@ } } +%typemap(in) (uint32_t in), (const uint32_t in), (mx_uint in), (const mx_uint in) +{ + $1 = (uint32_t)SvIV($input); +} + +%typemap(in) (uint64_t in), (const uint64_t in) +{ + $1 = (uint64_t)SvUV($input); +} + +%typemap(in) (int64_t in), (const int64_t in) +{ + $1 = (int64_t)SvUV($input); +} + %typemap(in) (FunctionHandle in) { int res; @@ -252,7 +293,7 @@ $1 = SvPV_nolen($input); } -%typemap(in) (const mx_uint *in), (mx_uint *in) +%typemap(in) (const mx_uint *in), (mx_uint *in), (const uint32_t *in), (uint32_t *in) { AV *tempav; int i; @@ -278,7 +319,61 @@ } } -%typemap(freearg) (const mx_uint *in), (mx_uint *in) { +%typemap(in) (const uint64_t *in), (uint64_t *in) +{ + AV *tempav; + int i; + SV **tv; + int av_len; + if (!SvROK($input)) + croak("Argument $argnum is not a reference."); + if (SvTYPE(SvRV($input)) != SVt_PVAV) + croak("Argument $argnum is not an array."); + tempav = (AV*)SvRV($input); + av_len = av_len(tempav) + 1; + if(av_len) + { + $1 = (uint64_t *)safemalloc(av_len*sizeof(uint64_t)); + for (i = 0; i < av_len; i++) { + tv = av_fetch(tempav, i, 0); + $1[i] = (uint64_t)SvUV(*tv); + } + } + else + { + $1 = NULL; + } +} + +%typemap(in) (const int64_t *in), (int64_t *in) +{ + AV *tempav; + int i; + SV **tv; + int av_len; + if (!SvROK($input)) + croak("Argument $argnum is not a reference."); + if (SvTYPE(SvRV($input)) != SVt_PVAV) + croak("Argument $argnum is not an array."); + tempav = (AV*)SvRV($input); + av_len = av_len(tempav) + 1; + if(av_len) + { + $1 = (int64_t *)safemalloc(av_len*sizeof(int64_t)); + for (i = 0; i < av_len; i++) { + tv = av_fetch(tempav, i, 0); + $1[i] = (int64_t)SvUV(*tv); + } + } + else + { + $1 = NULL; + } +} + +%typemap(freearg) (const mx_uint *in), (mx_uint *in), (const uint32_t *in), + (uint32_t *in), (const uint64_t *in), (uint64_t *in), (const int64_t *in), (int64_t *in) +{ Safefree($1); } @@ -337,7 +432,6 @@ { $1 = NULL; } - } %typemap(freearg) (dim_t *in) { @@ -410,7 +504,7 @@ Safefree($1); } -%typemap(in) (mx_float *in) +%typemap(in) (mx_float *in), (float *in) { AV *tempav; int i, len; @@ -435,7 +529,7 @@ } } -%typemap(freearg) (mx_float *in) { +%typemap(freearg) (mx_float *in), (float *in) { Safefree($1); } @@ -464,7 +558,7 @@ } } -%typemap(in) (mx_float **out_pdata) (mx_float *temp_pdata) +%typemap(in) (mx_float **out_pdata) (mx_float *temp_pdata), (float **out_pdata) (float *temp_pdata) { $1 = &temp_pdata; } @@ -524,12 +618,33 @@ } } -%typemap(in,numinputs=0) (int *out_dim, const int **out_pdata) (int temp_dim, int *temp_pdata) +%typemap(in,numinputs=0) (int *out_dim, const int **out_pdata) (int temp_dim, int *temp_pdata), + (int *out_dim, const int64_t **out_pdata) (int temp_dim, int64_t *temp_pdata) { $1 = &temp_dim; $2 = &temp_pdata; } +%typemap(argout) (int *out_dim, const int64_t **out_pdata) +{ + if(!result) + { + AV *myav; + SV **svs; + int i = 0; + svs = (SV **)safemalloc(*$1*sizeof(SV *)); + for (i = 0; i < *$1 ; i++) { + svs[i] = newSVnv((double)((*$2)[i])); + sv_2mortal(svs[i]); + } + myav = av_make(*$1,svs); + Safefree(svs); + $result = newRV_noinc((SV*)myav); + sv_2mortal($result); + argvi++; + } +} + %typemap(argout) (int *out_dim, const int **out_pdata) { if(!result) @@ -563,10 +678,10 @@ { AV *myav; SV **svs; - int i = 0; + uint64_t i = 0; svs = (SV **)safemalloc(*$2*sizeof(SV *)); for (i = 0; i < *$2 ; i++) { - svs[i] = newSViv((*$1)[i]); + svs[i] = newSVnv((double)((*$1)[i])); sv_2mortal(svs[i]); } myav = av_make(*$2,svs); @@ -580,7 +695,12 @@ %typemap(in,numinputs=0) (mx_uint *out_size, FunctionHandle** out_array) (mx_uint temp_size, FunctionHandle* temp), (mx_uint *out_size, AtomicSymbolCreator** out_array) (mx_uint temp_size, AtomicSymbolCreator* temp), (mx_uint *out_size, DataIterCreator **out_array) (mx_uint temp_size, DataIterCreator* temp), - (mx_uint *out_size, NDArrayHandle** out_array) (mx_uint temp_size, NDArrayHandle* temp) + (mx_uint *out_size, NDArrayHandle** out_array) (mx_uint temp_size, NDArrayHandle* temp), + (uint32_t *out_size, FunctionHandle** out_array) (uint32_t temp_size, FunctionHandle* temp), + (uint32_t *out_size, AtomicSymbolCreator** out_array) (uint32_t temp_size, AtomicSymbolCreator* temp), + (uint32_t *out_size, DataIterCreator **out_array) (uint32_t temp_size, DataIterCreator* temp), + (uint32_t *out_size, NDArrayHandle** out_array) (uint32_t temp_size, NDArrayHandle* temp) + { $1 = &temp_size; *$1 = 0; @@ -588,7 +708,8 @@ } // many argouts needed because SWIG can't $**2_mangle -%typemap(argout) (mx_uint *out_size, AtomicSymbolCreator** out_array) +%typemap(argout) (mx_uint *out_size, AtomicSymbolCreator** out_array), + (uint32_t *out_size, AtomicSymbolCreator** out_array) { if(!result) { @@ -607,7 +728,8 @@ } } -%typemap(argout) (mx_uint *out_size, FunctionHandle** out_array) +%typemap(argout) (mx_uint *out_size, FunctionHandle** out_array), + (uint32_t *out_size, FunctionHandle** out_array) { if(!result) { @@ -626,7 +748,8 @@ } } -%typemap(argout) (mx_uint *out_size, DataIterCreator **out_array) +%typemap(argout) (mx_uint *out_size, DataIterCreator **out_array), + (uint32_t *out_size, DataIterCreator **out_array) { if(!result) { @@ -645,7 +768,8 @@ } } -%typemap(argout) (mx_uint *out_size, NDArrayHandle** out_array) +%typemap(argout) (mx_uint *out_size, NDArrayHandle** out_array), + (uint32_t *out_size, NDArrayHandle** out_array) { if(!result) { @@ -665,7 +789,9 @@ } %typemap(in,numinputs=0) (mx_uint* couple_out_size, NDArrayHandle** out_first_array, NDArrayHandle** out_second_array) - (mx_uint t, NDArrayHandle* t1, NDArrayHandle* t2) + (mx_uint t, NDArrayHandle* t1, NDArrayHandle* t2), + (uint32_t* couple_out_size, NDArrayHandle** out_first_array, NDArrayHandle** out_second_array) + (uint32_t t, NDArrayHandle* t1, NDArrayHandle* t2) { $1 = &t; *$1 = 0; @@ -673,7 +799,8 @@ $3 = &t2; } -%typemap(argout) (mx_uint* couple_out_size, NDArrayHandle** out_first_array, NDArrayHandle** out_second_array) +%typemap(argout) (mx_uint* couple_out_size, NDArrayHandle** out_first_array, NDArrayHandle** out_second_array), + (uint32_t* couple_out_size, NDArrayHandle** out_first_array, NDArrayHandle** out_second_array) { if(!result) { @@ -819,14 +946,14 @@ %typemap(in,numinputs=0) (const char **name, const char **description, - mx_uint *num_args, + uint32_t *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions ) (char *name_temp, char *desc_temp, - mx_uint num_args_temp, + uint32_t num_args_temp, char **names_temp, char **types_temp, char **descs_temp @@ -843,7 +970,7 @@ %typemap(argout) (const char **name, const char **description, - mx_uint *num_args, + uint32_t *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions @@ -878,7 +1005,7 @@ %typemap(in,numinputs=0) (const char **name, const char **description, - mx_uint *num_args, + uint32_t *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions, @@ -886,7 +1013,7 @@ ) (char *name_temp, char *desc_temp, - mx_uint num_args_temp, + uint32_t num_args_temp, char **names_temp, char **types_temp, char **descs_temp, @@ -905,7 +1032,7 @@ %typemap(argout) (const char **name, const char **description, - mx_uint *num_args, + uint32_t *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions, @@ -940,13 +1067,13 @@ } } -%typemap(in,numinputs=0) (mx_uint *out) (mx_uint temp), (size_t *out) (size_t temp) +%typemap(in,numinputs=0) (uint32_t *out) (uint32_t temp), (size_t *out) (size_t temp) { $1 = &temp; *$1 = 0; } -%typemap(argout) (mx_uint *out), (size_t *out) +%typemap(argout) (uint32_t *out), (size_t *out) { if(!result) { @@ -956,12 +1083,18 @@ } } -%typemap(in,numinputs=0) (mx_uint *in_shape_size, const int **in_shape_ndim, const int ***in_shape_data) - (mx_uint temp1, int *temp2, int **temp3), - (mx_uint *out_shape_size, const int **out_shape_ndim, const int ***out_shape_data) - (mx_uint temp1, int *temp2, int **temp3), - (mx_uint *aux_shape_size, const int **aux_shape_ndim, const int ***aux_shape_data) - (mx_uint temp1, int *temp2, int **temp3) +%typemap(in,numinputs=0) (uint32_t *in_shape_size, const int **in_shape_ndim, const int ***in_shape_data) + (uint32_t temp1, int *temp2, int **temp3), + (uint32_t *out_shape_size, const int **out_shape_ndim, const int ***out_shape_data) + (uint32_t temp1, int *temp2, int **temp3), + (uint32_t *aux_shape_size, const int **aux_shape_ndim, const int ***aux_shape_data) + (uint32_t temp1, int *temp2, int **temp3), + (size_t *in_shape_size, const int **in_shape_ndim, const int64_t ***in_shape_data) + (size_t temp1, int *temp2, int64_t **temp3), + (size_t *out_shape_size, const int **out_shape_ndim, const int64_t ***out_shape_data) + (size_t temp1, int *temp2, int64_t **temp3), + (size_t *aux_shape_size, const int **aux_shape_ndim, const int64_t ***aux_shape_data) + (size_t temp1, int *temp2, int64_t **temp3) { $1 = &temp1; $2 = &temp2; @@ -969,9 +1102,9 @@ *$1 = 0; } -%typemap(argout) (mx_uint *in_shape_size, const int **in_shape_ndim, const int ***in_shape_data), - (mx_uint *out_shape_size, const int **out_shape_ndim, const int ***out_shape_data), - (mx_uint *aux_shape_size, const int **aux_shape_ndim, const int ***aux_shape_data) +%typemap(argout) (uint32_t *in_shape_size, const int **in_shape_ndim, const int ***in_shape_data), + (uint32_t *out_shape_size, const int **out_shape_ndim, const int ***out_shape_data), + (uint32_t *aux_shape_size, const int **aux_shape_ndim, const int ***aux_shape_data) { if(!result && *arg15) { @@ -995,21 +1128,48 @@ } } -%typemap(in,numinputs=0) (mx_uint *in_type_size, const int **in_type_data) - (mx_uint temp1, int *temp2), - (mx_uint *out_type_size, const int **out_type_data) - (mx_uint temp1, int *temp2), - (mx_uint *aux_type_size, const int **aux_type_data) - (mx_uint temp1, int *temp2) +%typemap(argout) (size_t *in_shape_size, const int **in_shape_ndim, const int64_t ***in_shape_data), + (size_t *out_shape_size, const int **out_shape_ndim, const int64_t ***out_shape_data), + (size_t *aux_shape_size, const int **aux_shape_ndim, const int64_t ***aux_shape_data) +{ + if(!result && *arg15) + { + AV *container; + AV *tmp; + size_t i; + int j; + container = newAV(); + for (i = 0; i < *$1 ; i++) + { + tmp = newAV(); + int len = (*$2)[i]; + for (j = 0; j < len ; j++) + { + av_push(tmp, newSVnv((double)((*$3)[i][j]))); + } + av_push(container, newRV((SV*)tmp)); + } + $result = newRV_noinc((SV*)container); + sv_2mortal($result); + argvi++; + } +} + +%typemap(in,numinputs=0) (uint32_t *in_type_size, const int **in_type_data) + (uint32_t temp1, int *temp2), + (uint32_t *out_type_size, const int **out_type_data) + (uint32_t temp1, int *temp2), + (uint32_t *aux_type_size, const int **aux_type_data) + (uint32_t temp1, int *temp2) { $1 = &temp1; $2 = &temp2; *$1 = 0; } -%typemap(argout) (mx_uint *in_type_size, const int **in_type_data), - (mx_uint *out_type_size, const int **out_type_data), - (mx_uint *aux_type_size, const int **aux_type_data) +%typemap(argout) (uint32_t *in_type_size, const int **in_type_data), + (uint32_t *out_type_size, const int **out_type_data), + (uint32_t *aux_type_size, const int **aux_type_data) { if(!result && *arg11) @@ -1027,10 +1187,10 @@ } } -%typemap(in,numinputs=0) (mx_uint* num_in_args, +%typemap(in,numinputs=0) (uint32_t* num_in_args, NDArrayHandle** in_args, NDArrayHandle** arg_grads) - (mx_uint temp1, + (uint32_t temp1, NDArrayHandle* temp2, NDArrayHandle* temp3) { @@ -1040,7 +1200,7 @@ *$1 = 0; } -%typemap(argout) (mx_uint* num_in_args, +%typemap(argout) (uint32_t* num_in_args, NDArrayHandle** in_args, NDArrayHandle** arg_grads) { @@ -1062,9 +1222,9 @@ } } -%typemap(in,numinputs=0) (mx_uint* num_aux_states, +%typemap(in,numinputs=0) (uint32_t* num_aux_states, NDArrayHandle** aux_states) - (mx_uint temp1, + (uint32_t temp1, NDArrayHandle* temp2) { $1 = &temp1; @@ -1072,7 +1232,7 @@ *$1 = 0; } -%typemap(argout) (mx_uint* num_aux_states, +%typemap(argout) (uint32_t* num_aux_states, NDArrayHandle** aux_states) { if(!result) From ce5b1a9c23952362bc7a8f870c58713c36be90d1 Mon Sep 17 00:00:00 2001 From: Sergey Kolychev Date: Sun, 16 Feb 2020 22:40:00 -0800 Subject: [PATCH 2/4] MXNET-1447 fixed test, corrected module version. --- perl-package/AI-MXNet/lib/AI/MXNet/Base.pm | 2 +- perl-package/AI-MXNet/t/test_runtime.t | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm index 13513c577175..56badc37719f 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm @@ -21,7 +21,7 @@ use warnings; use PDL; use PDL::Types (); use PDL::CCS::Nd; -use AI::MXNetCAPI 1.32; +use AI::MXNetCAPI 1.4; use AI::NNVMCAPI 1.3; use AI::MXNet::Types; use Time::HiRes; diff --git a/perl-package/AI-MXNet/t/test_runtime.t b/perl-package/AI-MXNet/t/test_runtime.t index 300ceb44e1de..293ae73096e0 100644 --- a/perl-package/AI-MXNet/t/test_runtime.t +++ b/perl-package/AI-MXNet/t/test_runtime.t @@ -60,4 +60,3 @@ test_features(); test_is_singleton(); test_is_enabled(); test_is_enabled_not_existing(); -done_testing(); \ No newline at end of file From 42e7206c5c504413aa3bb636b16c5992a58124ea Mon Sep 17 00:00:00 2001 From: Sergey Kolychev Date: Mon, 17 Feb 2020 11:35:55 -0800 Subject: [PATCH 3/4] miscellaneous cleanups. --- perl-package/AI-MXNet/META.json | 10 ++++++++-- perl-package/AI-MXNet/META.yml | 8 +++++++- perl-package/AI-MXNet/lib/AI/MXNet/Base.pm | 4 ++-- perl-package/AI-MXNet/lib/AI/MXNet/Executor/Group.pm | 2 +- perl-package/AI-MXNet/lib/AI/MXNet/Gluon.pm | 2 +- perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm | 4 +++- perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm | 2 +- perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm | 2 ++ perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm | 1 + perl-package/AI-NNVMCAPI/Changes | 2 ++ perl-package/AI-NNVMCAPI/META.json | 2 +- perl-package/AI-NNVMCAPI/META.yml | 2 +- perl-package/AI-NNVMCAPI/README | 2 +- perl-package/AI-NNVMCAPI/lib/AI/NNVMCAPI.pm | 3 ++- 14 files changed, 33 insertions(+), 13 deletions(-) diff --git a/perl-package/AI-MXNet/META.json b/perl-package/AI-MXNet/META.json index e7681343ecd8..02357d478095 100644 --- a/perl-package/AI-MXNet/META.json +++ b/perl-package/AI-MXNet/META.json @@ -31,13 +31,19 @@ "runtime" : { "requires" : { "AI::MXNetCAPI" : "1.5", - "AI::NNVMCAPI" : "1.3", + "AI::NNVMCAPI" : "1.4", "Function::Parameters" : "1.0705", "Hash::Ordered" : "0.012", "GraphViz" : "2.14", "Mouse" : "v2.1.0", "PDL" : "2.007", - "PDL::CCS" : "1.23.4" + "PDL::CCS" : "1.23.4", + "Archive::Tar": "0", + "Digest::SHA": "0", + "HTTP::Tiny": "0", + "IO::Zlib": "0", + "JSON::PP": "0", + "parent": "0" } }, "test" : { diff --git a/perl-package/AI-MXNet/META.yml b/perl-package/AI-MXNet/META.yml index d2daa486ffb3..b06b331ec4ae 100644 --- a/perl-package/AI-MXNet/META.yml +++ b/perl-package/AI-MXNet/META.yml @@ -35,11 +35,17 @@ no_index: - inc requires: AI::MXNetCAPI: '1.5' - AI::NNVMCAPI: '1.3' + AI::NNVMCAPI: '1.4' Function::Parameters: '1.0705' Hash::Ordered: '0.012' GraphViz: '2.14' Mouse: v2.1.0 PDL: '2.007' PDL::CCS: '1.23.4' + Archive::Tar: '0' + Digest::SHA: '0' + HTTP::Tiny: '0' + IO::Zlib: '0' + JSON::PP: '0' + parent: '0' version: '1.5' diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm index 56badc37719f..9ac917b57b41 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm @@ -21,8 +21,8 @@ use warnings; use PDL; use PDL::Types (); use PDL::CCS::Nd; -use AI::MXNetCAPI 1.4; -use AI::NNVMCAPI 1.3; +use AI::MXNetCAPI 1.5; +use AI::NNVMCAPI 1.4; use AI::MXNet::Types; use Time::HiRes; use Scalar::Util qw(blessed); diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Executor/Group.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Executor/Group.pm index 161a2d7f1175..79f395fb7c5a 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Executor/Group.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Executor/Group.pm @@ -340,7 +340,7 @@ sub BUILD $self->bind_exec($self->data_shapes, $self->label_shapes, $self->shared_group); } -=decide_slices +=head2 decide_slices Decide the slices for each context according to the workload. diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Gluon.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Gluon.pm index 789011a2a7e1..a2dd64e926a5 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Gluon.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Gluon.pm @@ -108,7 +108,7 @@ sub model_zoo { require AI::MXNet::Gluon::ModelZoo; 'AI::MXNet::Gluon::ModelZoo' my $children_outputs = [ map { $self->forward($F, $inputs, $_) @{ $tree->children } ]; - #Recursively builds the neural network based on each input sentence’s + #Recursively builds the neural network based on each input sentence #syntactic structure during the model definition and training process ... } diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm index 1729cd4a76e0..cf98458d61ab 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm @@ -23,6 +23,8 @@ use AI::MXNet::Function::Parameters; use Scalar::Util qw/blessed/; use JSON::PP; +=encoding utf-8 + =head1 NAME AI::MXNet::Metric - Evaluation Metric API. @@ -295,7 +297,7 @@ method update(ArrayRef[AI::MXNet::NDArray] $labels, ArrayRef[AI::MXNet::NDArray] If top_k = 1, then TopKAccuracy is identical to Accuracy. - Parameters: + Parameters: top_k(Int, default 1) – Whether targets are in top k predictions. name (Str, default 'top_k_accuracy') – Name of this metric instance for display. diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm b/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm index 1eff8f17a869..b9268bf0fabc 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/NDArray.pm @@ -29,7 +29,7 @@ package AI::MXNet::NDArray; An NDArray represents a multidimensional, fixed-size homogenous array. If you're familiar with the PDL, you might notice some similarities. However, NDArray is row-major, unlike the PDL that is column-major. - Like the PDL, MXNet’s NDArray enables imperative computation. + Like the PDL, MXNet's NDArray enables imperative computation. Some NDArray advandages compared to PDL: MXNet's NDArray supports fast execution on a wide range of hardware configurations, including CPU, GPU, and multi-GPU machines. diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm b/perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm index 51e80f29617a..5ef0815c8c77 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/RunTime.pm @@ -23,6 +23,8 @@ use AI::MXNet::Base; use AI::MXNet::Function::Parameters; use Mouse; +=encoding utf-8 + =head1 NAME AI::MXNet::RunTime - Runtime querying of compile time features in the native library. diff --git a/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm b/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm index bf44b1b13278..c75ee336acf1 100644 --- a/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm +++ b/perl-package/AI-MXNetCAPI/lib/AI/MXNetCAPI.pm @@ -16,6 +16,7 @@ # under the License. package AI::MXNetCAPI; +use strict; use base qw(DynaLoader); bootstrap AI::MXNetCAPI; our $VERSION = '1.5'; diff --git a/perl-package/AI-NNVMCAPI/Changes b/perl-package/AI-NNVMCAPI/Changes index ba787009cf42..cf9628ab8d1c 100644 --- a/perl-package/AI-NNVMCAPI/Changes +++ b/perl-package/AI-NNVMCAPI/Changes @@ -1,4 +1,6 @@ Revision history for Perl extension AI::NNVMCAPI. +1.4 Sun Feb 16 19:56:17 PST 2020 + - use strict 1.3 Tue Jun 26 20:57:40 PDT 2018 - Major update, Gluon interface updated to parity with Python's API diff --git a/perl-package/AI-NNVMCAPI/META.json b/perl-package/AI-NNVMCAPI/META.json index 3851c9df600c..5f8364e91847 100644 --- a/perl-package/AI-NNVMCAPI/META.json +++ b/perl-package/AI-NNVMCAPI/META.json @@ -37,5 +37,5 @@ } }, "release_status" : "stable", - "version" : "1.3" + "version" : "1.4" } diff --git a/perl-package/AI-NNVMCAPI/META.yml b/perl-package/AI-NNVMCAPI/META.yml index 40c49e431e0b..e7b29f377a23 100644 --- a/perl-package/AI-NNVMCAPI/META.yml +++ b/perl-package/AI-NNVMCAPI/META.yml @@ -36,4 +36,4 @@ no_index: - inc requires: Test::More: '0' -version: '1.3' +version: '1.4' diff --git a/perl-package/AI-NNVMCAPI/README b/perl-package/AI-NNVMCAPI/README index f6c3d8fbacc8..e190fefbde4a 100644 --- a/perl-package/AI-NNVMCAPI/README +++ b/perl-package/AI-NNVMCAPI/README @@ -1,4 +1,4 @@ -AI-NNVMCAPI version 1.3 +AI-NNVMCAPI version 1.4 ===================== Swig interface to MXNet c api. diff --git a/perl-package/AI-NNVMCAPI/lib/AI/NNVMCAPI.pm b/perl-package/AI-NNVMCAPI/lib/AI/NNVMCAPI.pm index 92a8f7445975..40f0d35501ea 100644 --- a/perl-package/AI-NNVMCAPI/lib/AI/NNVMCAPI.pm +++ b/perl-package/AI-NNVMCAPI/lib/AI/NNVMCAPI.pm @@ -16,9 +16,10 @@ # under the License. package AI::NNVMCAPI; +use strict; use base qw(DynaLoader); bootstrap AI::NNVMCAPI; -our $VERSION = '1.3'; +our $VERSION = '1.4'; 1; __END__ From 09301f72abcef6a79c51bf79a43a0380dd9e88e6 Mon Sep 17 00:00:00 2001 From: Sergey Kolychev Date: Tue, 18 Feb 2020 16:52:31 -0800 Subject: [PATCH 4/4] added missing file. --- perl-package/AI-MXNet/MANIFEST | 1 + 1 file changed, 1 insertion(+) diff --git a/perl-package/AI-MXNet/MANIFEST b/perl-package/AI-MXNet/MANIFEST index 3d6937c11abf..763d7186d0c9 100644 --- a/perl-package/AI-MXNet/MANIFEST +++ b/perl-package/AI-MXNet/MANIFEST @@ -75,6 +75,7 @@ lib/AI/MXNet/NDArray/Base.pm lib/AI/MXNet/NDArray/Doc.pm lib/AI/MXNet/NDArray/Slice.pm lib/AI/MXNet/NDArray/Sparse.pm +lib/AI/MXNet/NS.pm lib/AI/MXNet/Optimizer.pm lib/AI/MXNet/Profiler.pm lib/AI/MXNet/Random.pm