ftorch Module

Main module for FTorch containing types and procedures. Generated from ftorch.fypp using the fypp Fortran preprocessor.

  • License
    FTorch is released under an MIT license. See the LICENSE file for details.


Enumerations

enum, bind(c)

Enumerators

enumerator:: torch_kUInt8 = 0
enumerator:: torch_kInt8 = 1
enumerator:: torch_kInt16 = 2
enumerator:: torch_kInt32 = 3
enumerator:: torch_kInt64 = 4
enumerator:: torch_kFloat16 = 5
enumerator:: torch_kFloat32 = 6
enumerator:: torch_kFloat64 = 7

Description

Enumerator for Torch data types
From c_torch.h (torch_data_t)
Note that 0 torch_kUInt8 and 5 torch_kFloat16 are not sypported in Fortran

enum, bind(c)

Enumerators

enumerator:: torch_kCPU = 0
enumerator:: torch_kCUDA = 1

Description

Enumerator for Torch devices
From c_torch.h (torch_device_t)


Interfaces

interface

  • public function torch_from_blob_c(data, ndims, tensor_shape, strides, dtype, device_type, device_index, requires_grad) result(tensor_p) bind(c, name = 'torch_from_blob')

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: data
    integer(kind=c_int), intent(in), value :: ndims
    integer(kind=c_int64_t), intent(in) :: tensor_shape(*)
    integer(kind=c_int64_t), intent(in) :: strides(*)
    integer(kind=c_int), intent(in), value :: dtype
    integer(kind=c_int), intent(in), value :: device_type
    integer(kind=c_int), intent(in), value :: device_index
    logical(kind=c_bool), intent(in), value :: requires_grad

    Return Value type(c_ptr)

public interface torch_tensor_from_array

Interface for directing torch_tensor_from_array to possible input types and ranks

  • public subroutine torch_tensor_from_array_int8_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 1 containing data of type int8

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int8), intent(in), target :: data_in(:)

    Input data that tensor will point at

    integer, intent(in) :: layout(1)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int8_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 2 containing data of type int8

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int8), intent(in), target :: data_in(:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(2)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int8_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 3 containing data of type int8

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int8), intent(in), target :: data_in(:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(3)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int8_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 4 containing data of type int8

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int8), intent(in), target :: data_in(:,:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(4)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int16_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 1 containing data of type int16

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int16), intent(in), target :: data_in(:)

    Input data that tensor will point at

    integer, intent(in) :: layout(1)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int16_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 2 containing data of type int16

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int16), intent(in), target :: data_in(:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(2)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int16_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 3 containing data of type int16

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int16), intent(in), target :: data_in(:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(3)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int16_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 4 containing data of type int16

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int16), intent(in), target :: data_in(:,:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(4)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int32_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 1 containing data of type int32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int32), intent(in), target :: data_in(:)

    Input data that tensor will point at

    integer, intent(in) :: layout(1)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int32_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 2 containing data of type int32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int32), intent(in), target :: data_in(:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(2)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int32_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 3 containing data of type int32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int32), intent(in), target :: data_in(:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(3)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int32_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 4 containing data of type int32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int32), intent(in), target :: data_in(:,:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(4)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int64_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 1 containing data of type int64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int64), intent(in), target :: data_in(:)

    Input data that tensor will point at

    integer, intent(in) :: layout(1)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int64_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 2 containing data of type int64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int64), intent(in), target :: data_in(:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(2)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int64_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 3 containing data of type int64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int64), intent(in), target :: data_in(:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(3)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_int64_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 4 containing data of type int64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    integer(kind=int64), intent(in), target :: data_in(:,:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(4)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real32_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 1 containing data of type real32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real32), intent(in), target :: data_in(:)

    Input data that tensor will point at

    integer, intent(in) :: layout(1)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real32_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 2 containing data of type real32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real32), intent(in), target :: data_in(:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(2)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real32_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 3 containing data of type real32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real32), intent(in), target :: data_in(:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(3)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real32_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 4 containing data of type real32

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real32), intent(in), target :: data_in(:,:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(4)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real64_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 1 containing data of type real64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real64), intent(in), target :: data_in(:)

    Input data that tensor will point at

    integer, intent(in) :: layout(1)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real64_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 2 containing data of type real64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real64), intent(in), target :: data_in(:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(2)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real64_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 3 containing data of type real64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real64), intent(in), target :: data_in(:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(3)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor

  • public subroutine torch_tensor_from_array_real64_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

    Return a Torch tensor pointing to data_in array of rank 4 containing data of type real64

    Arguments

    Type IntentOptional Attributes Name
    type(torch_tensor), intent(out) :: tensor

    Returned tensor

    real(kind=real64), intent(in), target :: data_in(:,:,:,:)

    Input data that tensor will point at

    integer, intent(in) :: layout(4)

    Control order of indices

    integer(kind=c_int), intent(in) :: c_device_type

    Device type the tensor will live on (torch_kCPU or torch_kCUDA)

    integer(kind=c_int), intent(in), optional :: device_index

    device index to use for torch_kCUDA case

    logical, intent(in), optional :: requires_grad

    Whether gradients need to be computed for the created tensor


Derived Types

type, public ::  torch_model

Type for holding a torch neural net (nn.Module).

Components

Type Visibility Attributes Name Initial
type(c_ptr), public :: p = c_null_ptr

pointer to the neural net in memory

type, public ::  torch_tensor

Type for holding a Torch tensor.

Components

Type Visibility Attributes Name Initial
type(c_ptr), public :: p = c_null_ptr

pointer to the tensor in memory


Functions

public function torch_tensor_get_device_index(tensor) result(device_index)

Determines the device index of a tensor.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(in) :: tensor

Input tensor

Return Value integer(kind=c_int)

Device index of tensor


Subroutines

public subroutine torch_model_delete(model)

Deallocates a TorchScript model

Arguments

Type IntentOptional Attributes Name
type(torch_model), intent(in) :: model

Torch Model to deallocate

public subroutine torch_model_forward(model, input_tensors, output_tensors, requires_grad)

Performs a forward pass of the model with the input tensors

Arguments

Type IntentOptional Attributes Name
type(torch_model), intent(in) :: model

Model

type(torch_tensor), intent(in), dimension(:) :: input_tensors

Array of Input tensors

type(torch_tensor), intent(in), dimension(:) :: output_tensors

Returned output tensors

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_model_load(model, filename, device_type, device_index, requires_grad, is_training)

Loads a TorchScript nn.module (pre-trained PyTorch model saved with TorchScript)

Arguments

Type IntentOptional Attributes Name
type(torch_model), intent(out) :: model

Returned deserialized model

character(len=*), intent(in) :: filename

Filename of saved TorchScript model

integer(kind=c_int), intent(in), optional :: device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

logical, intent(in), optional :: is_training

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_delete(tensor)

Deallocates a tensor.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(in) :: tensor

Input tensor

public subroutine torch_tensor_from_array_int16_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 1 containing data of type int16

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int16), intent(in), target :: data_in(:)

Input data that tensor will point at

integer, intent(in) :: layout(1)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int16_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 2 containing data of type int16

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int16), intent(in), target :: data_in(:,:)

Input data that tensor will point at

integer, intent(in) :: layout(2)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int16_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 3 containing data of type int16

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int16), intent(in), target :: data_in(:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(3)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int16_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 4 containing data of type int16

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int16), intent(in), target :: data_in(:,:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(4)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int32_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 1 containing data of type int32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int32), intent(in), target :: data_in(:)

Input data that tensor will point at

integer, intent(in) :: layout(1)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int32_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 2 containing data of type int32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int32), intent(in), target :: data_in(:,:)

Input data that tensor will point at

integer, intent(in) :: layout(2)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int32_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 3 containing data of type int32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int32), intent(in), target :: data_in(:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(3)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int32_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 4 containing data of type int32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int32), intent(in), target :: data_in(:,:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(4)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int64_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 1 containing data of type int64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int64), intent(in), target :: data_in(:)

Input data that tensor will point at

integer, intent(in) :: layout(1)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int64_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 2 containing data of type int64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int64), intent(in), target :: data_in(:,:)

Input data that tensor will point at

integer, intent(in) :: layout(2)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int64_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 3 containing data of type int64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int64), intent(in), target :: data_in(:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(3)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int64_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 4 containing data of type int64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int64), intent(in), target :: data_in(:,:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(4)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int8_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 1 containing data of type int8

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int8), intent(in), target :: data_in(:)

Input data that tensor will point at

integer, intent(in) :: layout(1)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int8_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 2 containing data of type int8

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int8), intent(in), target :: data_in(:,:)

Input data that tensor will point at

integer, intent(in) :: layout(2)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int8_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 3 containing data of type int8

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int8), intent(in), target :: data_in(:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(3)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_int8_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 4 containing data of type int8

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int8), intent(in), target :: data_in(:,:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(4)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real32_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 1 containing data of type real32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real32), intent(in), target :: data_in(:)

Input data that tensor will point at

integer, intent(in) :: layout(1)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real32_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 2 containing data of type real32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real32), intent(in), target :: data_in(:,:)

Input data that tensor will point at

integer, intent(in) :: layout(2)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real32_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 3 containing data of type real32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real32), intent(in), target :: data_in(:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(3)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real32_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 4 containing data of type real32

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real32), intent(in), target :: data_in(:,:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(4)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real64_1d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 1 containing data of type real64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real64), intent(in), target :: data_in(:)

Input data that tensor will point at

integer, intent(in) :: layout(1)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real64_2d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 2 containing data of type real64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real64), intent(in), target :: data_in(:,:)

Input data that tensor will point at

integer, intent(in) :: layout(2)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real64_3d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 3 containing data of type real64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real64), intent(in), target :: data_in(:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(3)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_array_real64_4d(tensor, data_in, layout, c_device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 4 containing data of type real64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

real(kind=real64), intent(in), target :: data_in(:,:,:,:)

Input data that tensor will point at

integer, intent(in) :: layout(4)

Control order of indices

integer(kind=c_int), intent(in) :: c_device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_from_blob(tensor, data, ndims, tensor_shape, layout, dtype, device_type, device_index, requires_grad)

Exposes the given data as a tensor without taking ownership of the original data. This routine will take an (i, j, k) array and return an (k, j, i) tensor.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

type(c_ptr), intent(in) :: data

Pointer to data

integer(kind=c_int), intent(in) :: ndims

Number of dimensions of the tensor

integer(kind=c_int64_t), intent(in) :: tensor_shape(*)

Shape of the tensor

integer(kind=c_int), intent(in) :: layout(*)

Layout for strides for accessing data

integer(kind=c_int), intent(in) :: dtype

Data type of the tensor

integer(kind=c_int), intent(in) :: device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical(kind=c_bool), intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_ones(tensor, ndims, tensor_shape, dtype, device_type, device_index, requires_grad)

Returns a tensor filled with the scalar value 1.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=c_int), intent(in) :: ndims

Number of dimensions of the tensor

integer(kind=c_int64_t), intent(in) :: tensor_shape(*)

Shape of the tensor

integer(kind=c_int), intent(in) :: dtype

Data type of the tensor

integer(kind=c_int), intent(in) :: device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical(kind=c_bool), intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor

public subroutine torch_tensor_print(tensor)

Prints the contents of a tensor.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(in) :: tensor

Input tensor

public subroutine torch_tensor_zeros(tensor, ndims, tensor_shape, dtype, device_type, device_index, requires_grad)

Returns a tensor filled with the scalar value 0.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=c_int), intent(in) :: ndims

Number of dimensions of the tensor

integer(kind=c_int64_t), intent(in) :: tensor_shape(*)

Shape of the tensor

integer(kind=c_int), intent(in) :: dtype

Data type of the tensor

integer(kind=c_int), intent(in) :: device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer(kind=c_int), intent(in), optional :: device_index

device index to use for torch_kCUDA case

logical(kind=c_bool), intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor