You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* FAQ about warnings
* Provide some additional information about tensor finalizer
* Provide link to Fortran-lang learn section on OO-Fortran
* Reference common warnings section for finalizer warning
* Refer to f08/0011 for technical details
* Text specific to structure finalizer
See the [Fortran-lang page on object-oriented Fortran](https://fortran-lang.org/learn/oop_features_in_fortran/object_based_programming_techniques/#finalization-and-conclusions)
Copy file name to clipboardExpand all lines: pages/usage/troubleshooting.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ If you are experiencing problems building or using FTorch please see below for g
10
10
-[Common Errors](#common-errors)
11
11
-[No specific subroutine](#no-specific-subroutine)
12
12
-[Segmentation faults](#segmentation-faults)
13
+
-[Common warnings](#common-warnings)
13
14
14
15
15
16
### Usage
@@ -97,3 +98,50 @@ the overloaded assignment operator should be triggered. As such, if you aren't
97
98
using the bare `use ftorch` import then you should ensure you specify
98
99
`use ftorch, only: assignment(=)` (as well as any other module members you
99
100
require). See the [tensor documentation](|page|/usage/tensor.html) for more details.
101
+
102
+
103
+
### Common warnings
104
+
105
+
#### Structure constructor finalizer with Fortran 2008
106
+
107
+
If you are building FTorch with gfortran and are specifying the Fortran 2008
108
+
standard (e.g., with the compiler flag `-std=f2008` or by default) then you may
109
+
get compiler warnings of the form:
110
+
```
111
+
Warning: The structure constructor at (1) has been finalized. This feature was removed by f08/0011. Use -std=f2018 or -std=gnu to eliminate the finalization.
112
+
```
113
+
These warn that the structure finalizer of the
114
+
[[ftorch(module):torch_tensor(type)]] derived type is triggered when a tensor
115
+
goes out of scope, despite the fact that this feature was removed from the 2008
116
+
standard. That is, the [[ftorch(module):torch_tensor_delete(subroutine)]]
117
+
subroutine is called so that the associated memory is automatically freed.
118
+
Firstly, this is the behaviour that we want so we should not be too concerned.
119
+
Secondly, structure finalizers are not used anywhere in FTorch, so we believe
120
+
this warning to be errorneous. Use of the structure constructor for the
121
+
`torch_tensor` type would be something like
122
+
```fortran
123
+
program
124
+
use, intrinsic :: iso_c_binding, only: c_null_ptr
125
+
use ftorch
126
+
implicit none
127
+
type(torch_tensor) :: tensor
128
+
129
+
tensor = torch_tensor(c_null_ptr)
130
+
end program
131
+
```
132
+
While this code would compile successfully, the warning mentioned above would be
133
+
raised.
134
+
135
+
@warning
136
+
The code snippet above is **not** the intended way to create a tensor. The
137
+
intended way is to use the provided API procedures such as
138
+
[[ftorch(module):torch_tensor_from_array(interface)]] or
139
+
[[ftorch(module):torch_tensor_ones(subroutine)]]. The code snippet above is
140
+
only intended to illustrate the use of the structure constructor and the
141
+
associated warning.
142
+
@endwarning
143
+
144
+
See the [tensor documentation](|page|/usage/tensor.html#deallocation) for more
145
+
details on the memory management of tensors and the use of the finalizer. For
0 commit comments