@@ -15,84 +15,54 @@ namespace Tensorflow.Eager
1515 /// </summary>
1616 public partial class EagerRunner
1717 {
18- int kFastPathExecuteInputStartIndex = 0 ;
1918 UnorderedMap < Context , SafeOpHandle > thread_local_eager_operation_map = new UnorderedMap < Context , SafeOpHandle > ( ) ;
2019
21- public Tensor [ ] TFE_FastPathExecute2 ( Context ctx ,
22- string device_name ,
23- string opName ,
24- string name ,
25- Action callbacks ,
26- object [ ] inputArgs ,
27- object [ ] attrs )
20+ public Tensor [ ] TFE_FastPathExecute ( FastPathOpExecInfo op_exec_info )
2821 {
29- var args = new List < object > ( ) ;
30- args . AddRange ( inputArgs ) ;
31- if ( attrs != null )
32- args . AddRange ( attrs ) ;
33- return TFE_FastPathExecute ( ctx , device_name , opName , name , callbacks , args . ToArray ( ) ) ;
34- }
35-
36- public Tensor [ ] TFE_FastPathExecute ( Context ctx ,
37- string device_name ,
38- string opName ,
39- string name ,
40- Action callbacks ,
41- params object [ ] args )
42- {
43- if ( ctx == null )
44- throw new ValueError ( "This function does not handle the case of the path where " +
45- "all inputs are not already EagerTensors." ) ;
22+ if ( op_exec_info . ctx == null )
23+ op_exec_info . ctx = tf . Context ;
24+ if ( string . IsNullOrEmpty ( op_exec_info . device_name ) )
25+ op_exec_info . device_name = tf . Context . DeviceName ;
4626
47- int args_size = args . Length ;
4827 var attr_list_sizes = new Dictionary < string , long > ( ) ;
4928
50- FastPathOpExecInfo op_exec_info = new FastPathOpExecInfo ( )
51- {
52- ctx = ctx ,
53- args = args ,
54- device_name = device_name ,
55- op_name = opName ,
56- name = name ,
57- } ;
58-
5929 op_exec_info . run_gradient_callback = HasAccumulatorOrTape ( ) ;
60- op_exec_info . run_post_exec_callbacks = callbacks != null ;
30+ op_exec_info . run_post_exec_callbacks = op_exec_info . callbacks != null ;
6131 op_exec_info . run_callbacks = op_exec_info . run_gradient_callback || op_exec_info . run_post_exec_callbacks ;
6232
6333 var status = tf . Status ;
64- using var op = GetOp ( ctx , opName , status ) ;
34+ using var op = GetOp ( op_exec_info . ctx , op_exec_info . op_name , status ) ;
6535
66- var op_def = tf . get_default_graph ( ) . GetOpDef ( opName ) ;
36+ var op_def = tf . get_default_graph ( ) . GetOpDef ( op_exec_info . op_name ) ;
6737
6838 var flattened_attrs = new List < object > ( op_def . Attr . Count * 2 ) ;
6939 var flattened_inputs = new List < Tensor > ( op_def . InputArg . Count ) ;
7040
7141 // Set non-inferred attrs, including setting defaults if the attr is passed in
7242 // as None.
73- for ( int i = kFastPathExecuteInputStartIndex + op_def . InputArg . Count ; i < args_size ; i += 2 )
43+ if ( op_exec_info . attrs != null )
7444 {
75- var attr_name = args [ i ] . ToString ( ) ;
76- var attr_value = args [ i + 1 ] ;
77-
78- var attr = op_def . Attr . FirstOrDefault ( x => x . Name == attr_name ) ;
79- if ( attr != null )
45+ foreach ( var attr1 in op_exec_info . attrs )
8046 {
81- flattened_attrs . Add ( attr_name ) ;
82- flattened_attrs . Add ( attr_value ) ;
47+ var attr = op_def . Attr . FirstOrDefault ( x => x . Name == attr1 . Key ) ;
48+ if ( attr != null )
49+ {
50+ flattened_attrs . Add ( attr . Name ) ;
51+ flattened_attrs . Add ( attr1 . Value ) ;
8352
84- SetOpAttrWithDefaults ( ctx , op , attr , attr_name , attr_value , attr_list_sizes , status ) ;
85- status . Check ( true ) ;
53+ SetOpAttrWithDefaults ( op_exec_info . ctx , op , attr , attr . Name , attr1 . Value , attr_list_sizes , status ) ;
54+ status . Check ( true ) ;
55+ }
8656 }
8757 }
8858
89- c_api . TFE_OpSetDevice ( op , device_name , status . Handle ) ;
59+ c_api . TFE_OpSetDevice ( op , op_exec_info . device_name , status . Handle ) ;
9060 status . Check ( true ) ;
9161
9262 // Add inferred attrs and inputs.
9363 for ( int i = 0 ; i < op_def . InputArg . Count ; i ++ )
9464 {
95- var input = args [ kFastPathExecuteInputStartIndex + i ] ;
65+ var input = op_exec_info . args [ i ] ;
9666 var input_arg = op_def . InputArg [ i ] ;
9767 if ( ! string . IsNullOrEmpty ( input_arg . NumberAttr ) )
9868 {
@@ -107,7 +77,7 @@ public Tensor[] TFE_FastPathExecute(Context ctx,
10777
10878 if ( len > 0 )
10979 {
110- var fast_input_array = ( object [ ] ) args [ i ] ;
80+ var fast_input_array = ( object [ ] ) op_exec_info . args [ i ] ;
11181 // First item adds the type attr.
11282 if ( ! AddInputToOp ( fast_input_array [ i ] , true , input_arg , flattened_attrs , flattened_inputs , op , status ) )
11383 return null ;
@@ -151,7 +121,7 @@ public Tensor[] TFE_FastPathExecute(Context ctx,
151121 else
152122 {
153123 // The item is a single item.
154- AddInputToOp ( args [ i ] , true , input_arg , flattened_attrs , flattened_inputs , op , status ) ;
124+ AddInputToOp ( op_exec_info . args [ i ] , true , input_arg , flattened_attrs , flattened_inputs , op , status ) ;
155125 }
156126 }
157127
@@ -179,7 +149,7 @@ public Tensor[] TFE_FastPathExecute(Context ctx,
179149 if ( op_exec_info . run_callbacks )
180150 {
181151 RunCallbacks ( op_exec_info ,
182- kFastPathExecuteInputStartIndex + op_def . InputArg . Count ( ) ,
152+ op_def . InputArg . Count ( ) ,
183153 flattened_inputs . ToArray ( ) , flattened_attrs . ToArray ( ) , flat_result ) ;
184154 }
185155
0 commit comments