torch_model_save Subroutine

public subroutine torch_model_save(model, filename)

Uses

  • proc~~torch_model_save~~UsesGraph proc~torch_model_save torch_model_save iso_c_binding iso_c_binding proc~torch_model_save->iso_c_binding

Writes out a model to file in TorchScript format

Arguments

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

Model to write out

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

Filename for saved TorchScript model


Source Code

  subroutine torch_model_save(model, filename)
    use, intrinsic :: iso_c_binding, only : c_null_char
    type(torch_model), intent(in) :: model  !! Model to write out
    character(*), intent(in) :: filename    !! Filename for saved TorchScript model

    interface
      subroutine torch_jit_save_c(model_c, filename_c) bind(c, name = 'torch_jit_save')
        use, intrinsic :: iso_c_binding, only : c_char, c_ptr
        implicit none
        type(c_ptr), value, intent(in) :: model_c
        character(c_char), intent(in) :: filename_c(*)
      end subroutine torch_jit_save_c
    end interface

    ! Need to append c_null_char at end of filename
    call torch_jit_save_c(model%p, trim(adjustl(filename))//c_null_char)
  end subroutine torch_model_save