Skip to content

Commit

Permalink
feat: add torch_delete interface
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMelt committed Jul 10, 2024
1 parent 291080a commit d7c0f4d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/1_SimpleNet/simplenet_infer_fortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ program inference
write (*,*) out_data(:)

! Cleanup
call torch_model_delete(model)
call torch_tensor_array_delete(in_tensors)
call torch_tensor_array_delete(out_tensors)
call torch_delete(model)
call torch_delete(in_tensors)
call torch_delete(out_tensors)

end program inference
6 changes: 3 additions & 3 deletions examples/2_ResNet18/resnet_infer_fortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ subroutine main()
write (*,*) trim(categories(idx(2))), " (id=", idx(2), "), : probability =", probability

! Cleanup
call torch_model_delete(model)
call torch_tensor_array_delete(in_tensors)
call torch_tensor_array_delete(out_tensors)
call torch_delete(model)
call torch_delete(in_tensors)
call torch_delete(out_tensors)
deallocate(in_data)
deallocate(out_data)
deallocate(probabilities)
Expand Down
6 changes: 3 additions & 3 deletions examples/3_MultiGPU/simplenet_infer_fortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ program inference
200 format("output on rank ", i1,": [", 4(f5.1,","), f5.1,"]")

! Cleanup
call torch_model_delete(model)
call torch_tensor_array_delete(in_tensors)
call torch_tensor_array_delete(out_tensors)
call torch_delete(model)
call torch_delete(in_tensors)
call torch_delete(out_tensors)
call mpi_finalize(ierr)

end program inference
6 changes: 3 additions & 3 deletions examples/4_MultiIO/multiionet_infer_fortran.f90
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ program inference
write (*,*) out_data2

! Cleanup
call torch_model_delete(model)
call torch_tensor_array_delete(in_tensors)
call torch_tensor_array_delete(out_tensors)
call torch_delete(model)
call torch_delete(in_tensors)
call torch_delete(out_tensors)

end program inference
6 changes: 3 additions & 3 deletions pages/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ call torch_model_forward(model, model_input_arr, model_output_arr)
write(*,*) output
! Clean up
call torch_model_delete(model)
call torch_tensor_array_delete(model_input_arr)
call torch_tensor_array_delete(model_output_arr)
call torch_delete(model)
call torch_delete(model_input_arr)
call torch_delete(model_output_arr)
```

#### 3. Build the code
Expand Down
7 changes: 7 additions & 0 deletions src/ftorch.f90
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ module ftorch
module procedure torch_tensor_from_array_real64_4d
end interface

!> Interface for deleting generic torch objects
interface torch_delete
module procedure torch_model_delete
module procedure torch_tensor_delete
module procedure torch_tensor_array_delete
end interface

interface
function torch_from_blob_c(data, ndims, tensor_shape, strides, dtype, &
device_type, device_index, &
Expand Down
7 changes: 7 additions & 0 deletions src/ftorch.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ module ftorch
#:endfor
end interface

!> Interface for deleting generic torch objects
interface torch_delete
module procedure torch_model_delete
module procedure torch_tensor_delete
module procedure torch_tensor_array_delete
end interface

interface
function torch_from_blob_c(data, ndims, tensor_shape, strides, dtype, &
device_type, device_index, &
Expand Down

0 comments on commit d7c0f4d

Please sign in to comment.