AI-MXNet

 view release on metacpan or  search on metacpan

lib/AI/MXNet/Rtc.pm  view on Meta::CPAN

    while(my ($name, $arr) = each %{ $self->outputs })
    {
        push @output_names, $name;
        push @output_nds, $arr->handle;
    }
    my $handle = check_call(
        AI::MXNetCAPI::RtcCreate(
            $self->name,
            scalar(@input_names),
            scalar(@output_names),
            \@input_names,
            \@output_names,
            \@input_nds,
            \@output_nds,
            $self->kernel
        )
    );
    $self->handle($handle);
}

sub DEMOLISH
{
    check_call(AI::MXNetCAPI::MXRtcFree(shift->handle));
}

=head2 push

        run the kernel.

        Parameters
        ----------
        inputs : list of ndarray
            list of input. Can be different ndarray then uses for constructor,
            but must have the same shape and in the same order.
        outputs : list of ndarray
            list of out. Can be different ndarray then uses for constructor,
            but must have the same shape and in the same order.
        grid_dims : tuple of 3 uint
            grid dimension for kernel launch
        block_dims : tuple of 3 uint
            block dimension for kernel launch
=cut


method push(
    ArrayRef[AI::MXNet::NDArray] $inputs,
    ArrayRef[AI::MXNet::NDArray] $outputs,
    ArrayRef[DimSize] $grid_dims,
    ArrayRef[DimSize] $block_dims
)
{
    confess("grid_dims must be size of 3")
        unless @{ $grid_dims } == 3;
    confess("block_dims must be size of 3")
        unless @{ $block_dims } == 3;
    check_call(
        AI::MXNetCAPI::RtcPush(
            $self->handle,
            scalar(@$inputs),
            scalar(@$outputs),
            [map { $_->handle } @$inputs],
            [map { $_->handle } @$outputs],
            @{ $grid_dims },
            @{ $block_dims }
        )
    );
}

1;



( run in 0.422 second using v1.01-cache-2.11-cpan-39bf76dae61 )