AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/Rtc.pm view on Meta::CPAN
list of input names and ndarray
outputs : tuple of (str, mxnet.ndarray)
list of output names and ndarray
kernel : str
the actual kernel code.
Note that this is only the body of the kernel, i.e.
after { and before }. Rtc will decorate the kernel.
For example, if name = "mykernel" and
inputs = [('x', mx.nd.zeros((10,)))]
outputs = [('y', mx.nd.zeros((10,)))]
kernel = "y[threadIdx.x] = x[threadIdx.x];",
the kernel that is compile will be:
extern "C" __global__ mykernel(float *x, float *y) {
const int x_ndim = 1;
const int x_dims = { 10 };
const int y_ndim = 1;
const int y_dims = { 10 };
y[threadIdx.x] = x[threadIdx.x];
}
=cut
has 'handle' => (is => 'rw', isa => 'RtcHandle', init_arg => undef);
has [qw/name kernel/] => (is => 'ro', isa => 'Str', required => 1);
has [qw/inputs outputs/] => (is => 'ro', isa => 'HashRef[AI::MXNet::NDArray]', required => 1);
sub BUILD
{
my $self = shift;
t/test_io.t view on Meta::CPAN
{
GetCifar10();
my $dataiter = mx->io->ImageRecordIter({
path_imgrec => "data/cifar/train.rec",
mean_img => "data/cifar/cifar10_mean.bin",
rand_crop => 0,
and_mirror => 0,
shuffle => 0,
data_shape => [3,28,28],
batch_size => 100,
preprocess_threads => 4,
prefetch_buffer => 1
});
my @labelcount;
my $batchcount = 0;
while(my $batch = <$dataiter>)
{
my $nplabel = $batch->label->[0];
for my $i (0..$nplabel->shape->[0]-1)
{
$labelcount[int($nplabel->at($i)->asscalar)] += 1;
( run in 0.329 second using v1.01-cache-2.11-cpan-49f99fa48dc )