Skip to content

Commit 71fef9a

Browse files
committed
regenerate protobufs.
1 parent 6534271 commit 71fef9a

43 files changed

Lines changed: 7884 additions & 753 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/TensorFlowNET.Core/Binding.Util.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public static void print(object obj)
8080
public static void print(string format, params object[] objects)
8181
{
8282
if (!format.Contains("{}"))
83-
Console.WriteLine(format, string.Join(" ", objects.Select(x => x.ToString())));
83+
{
84+
Console.WriteLine(format + " " + string.Join(" ", objects.Select(x => x.ToString())));
85+
return;
86+
}
8487

8588
foreach(var obj in objects)
8689
{

‎src/TensorFlowNET.Core/Eager/c_api.eager.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ public partial class c_api
2020
[DllImport(TensorFlowLibName)]
2121
public static extern void TFE_DeleteContextOptions(IntPtr options);
2222

23+
/// <summary>
24+
///
25+
/// </summary>
26+
/// <param name="op">TFE_Op*</param>
27+
/// <param name="attr_name">const char*</param>
28+
/// <param name="is_list">unsigned char*</param>
29+
/// <param name="status">TF_Status*</param>
30+
/// <returns></returns>
31+
[DllImport(TensorFlowLibName)]
32+
public static extern TF_AttrType TFE_OpGetAttrType(IntPtr op, string attr_name, ref byte is_list, IntPtr status);
33+
2334
/// <summary>
2435
/// Returns the length (number of tensors) of the input argument `input_name`
2536
/// found in the provided `op`.
@@ -119,6 +130,9 @@ public partial class c_api
119130
[DllImport(TensorFlowLibName)]
120131
public static extern void TFE_OpSetAttrShape(IntPtr op, string attr_name, long[] dims, int num_dims, IntPtr out_status);
121132

133+
[DllImport(TensorFlowLibName)]
134+
public static extern void TFE_OpSetAttrBool(IntPtr op, string attr_name, bool value);
135+
122136
/// <summary>
123137
///
124138
/// </summary>

‎src/TensorFlowNET.Core/Eager/pywrap_tfe_src.cs‎

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,36 @@ public static EagerTensor TFE_Py_FastPathExecute(Context ctx,
1414
string device_name,
1515
string opName,
1616
string name,
17-
params object[] inputs)
17+
Action callbacks,
18+
params object[] args)
1819
{
20+
int args_size = args.Length;
1921
IntPtr op = IntPtr.Zero;
20-
var attr_list_sizes = new Dictionary<string, int>();
22+
var attr_list_sizes = new Dictionary<string, long>();
2123
using (var status = new Status())
2224
{
2325
op = c_api.TFE_NewOp(ctx, opName, status);
2426

2527
var op_def = Graph.TFE_GetOpDef(opName);
2628

27-
// SetOpAttrWithDefaults
28-
c_api.TFE_OpSetDevice(op, "", status);
29+
// Set non-inferred attrs, including setting defaults if the attr is passed in
30+
// as None.
31+
for (int i = op_def.InputArg.Count; i < args_size; i += 2)
32+
{
33+
var attr_name = args[i].ToString();
34+
var attr_value = args[i + 1];
35+
36+
foreach(var attr in op_def.Attr)
37+
{
38+
if(attr_name == attr.Name)
39+
{
40+
SetOpAttrWithDefaults(ctx, op, attr, attr_name, attr_value, attr_list_sizes, status);
41+
break;
42+
}
43+
}
44+
}
45+
46+
c_api.TFE_OpSetDevice(op, device_name, status);
2947

3048
for (int i = 0; i < op_def.InputArg.Count; i++)
3149
{
@@ -42,7 +60,7 @@ public static EagerTensor TFE_Py_FastPathExecute(Context ctx,
4260
else
4361
{
4462
// The item is a single item.
45-
switch (inputs[i])
63+
switch (args[i])
4664
{
4765
case Tensor inputTensor:
4866
AddInputToOp(inputTensor, true, input_arg, op, status);
@@ -57,18 +75,19 @@ public static EagerTensor TFE_Py_FastPathExecute(Context ctx,
5775
for (int i = 0; i < op_def.OutputArg.Count; i++)
5876
{
5977
var output_arg = op_def.OutputArg[i];
60-
var delta = 1;
78+
var delta = 1L;
6179
if (!string.IsNullOrEmpty(output_arg.NumberAttr))
6280
delta = attr_list_sizes[output_arg.NumberAttr];
6381
else if (!string.IsNullOrEmpty(output_arg.TypeListAttr))
6482
delta = attr_list_sizes[output_arg.TypeListAttr];
6583
if(delta < 0)
6684
throw new RuntimeError("Attributes suggest that the size of an output list is less than 0");
67-
num_retvals += delta;
85+
num_retvals += (int)delta;
6886
}
6987

7088
var retVals = new IntPtr[num_retvals];
7189
c_api.TFE_Execute(op, retVals, ref num_retvals, status);
90+
status.Check(true);
7291

7392
var t = c_api.TFE_TensorHandleResolve(retVals[0], status);
7493
status.Check(true);
@@ -106,6 +125,72 @@ private static bool AddInputToOp(Tensor input,
106125
return true;
107126
}
108127

128+
/// <summary>
129+
/// This function will set the op attrs required. If an attr has the value of
130+
/// None, then it will read the AttrDef to get the default value and set that
131+
/// instead. Any failure in this function will simply fall back to the slow
132+
/// path.
133+
/// </summary>
134+
/// <param name="ctx"></param>
135+
/// <param name="op"></param>
136+
/// <param name="attr"></param>
137+
/// <param name="attr_name"></param>
138+
/// <param name="attr_value"></param>
139+
/// <param name="attr_list_sizes"></param>
140+
/// <param name="status"></param>
141+
private static void SetOpAttrWithDefaults(Context ctx, IntPtr op, AttrDef attr,
142+
string attr_name, object attr_value,
143+
Dictionary<string, long> attr_list_sizes,
144+
Status status)
145+
{
146+
byte is_list = 0;
147+
var type = c_api.TFE_OpGetAttrType(op, attr_name, ref is_list, status);
148+
if (status.Code != TF_Code.TF_OK) return;
149+
150+
if(attr_value == null)
151+
{
152+
if (is_list != 0)
153+
;
154+
//SetOpAttrListDefault
155+
else
156+
;
157+
//SetOpAttrScalarDefault
158+
}
159+
else
160+
{
161+
if (is_list != 0)
162+
;// SetOpAttrList
163+
else
164+
SetOpAttrScalar(ctx, op, attr_name, attr_value, type, attr_list_sizes, status);
165+
}
166+
}
167+
168+
private static bool SetOpAttrScalar(Context ctx, IntPtr op,
169+
string key, object value, TF_AttrType type,
170+
Dictionary<string, long> attr_list_sizes,
171+
Status status)
172+
{
173+
switch(type)
174+
{
175+
case TF_AttrType.TF_ATTR_STRING:
176+
c_api.TFE_OpSetAttrString(op, key, value.ToString(), (uint)value.ToString().Length);
177+
break;
178+
case TF_AttrType.TF_ATTR_TYPE:
179+
c_api.TFE_OpSetAttrType(op, key, (TF_DataType)value);
180+
break;
181+
case TF_AttrType.TF_ATTR_BOOL:
182+
c_api.TFE_OpSetAttrBool(op, key, Convert.ToBoolean(value));
183+
break;
184+
case TF_AttrType.TF_ATTR_INT:
185+
c_api.TFE_OpSetAttrInt(op, key, Convert.ToInt64(value));
186+
break;
187+
default:
188+
throw new NotImplementedException("");
189+
}
190+
191+
return true;
192+
}
193+
109194
public static void RecordGradient(string op_name, Tensor[] inputs, Dictionary<string, object> attrs, Tensor[] results, string name = null)
110195
{
111196
var input_ids = inputs.Select(x => x.Id).ToArray();

‎src/TensorFlowNET.Core/Operations/gen_array_ops.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
using NumSharp;
1818
using System;
1919
using System.Collections.Generic;
20+
using static Tensorflow.Binding;
2021
using Tensorflow.Eager;
2122

2223
namespace Tensorflow

‎src/TensorFlowNET.Core/Operations/gen_math_ops.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static Tensor add<Tx, Ty>(Tx x, Ty y, string name = null)
144144
{
145145
if (tf.context.executing_eagerly())
146146
{
147-
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Add", name, x, y);
147+
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Add", name, null, x, y);
148148
return _result;
149149
}
150150

@@ -466,7 +466,7 @@ public static Tensor cast(Tensor x, TF_DataType DstT, bool Truncate= false, stri
466466
{
467467
if (tf.context.executing_eagerly())
468468
{
469-
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Cast", name, x, "DstT", DstT, "Truncate", Truncate);
469+
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Cast", name, null, x, "DstT", DstT, "Truncate", Truncate);
470470
return _result;
471471
}
472472

@@ -493,7 +493,7 @@ public static Tensor sub<Tx, Ty>(Tx x, Ty y, string name = null)
493493
{
494494
if (tf.context.executing_eagerly())
495495
{
496-
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Sub", name, x, y);
496+
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Sub", name, null, x, y);
497497
return _result;
498498
}
499499

@@ -544,7 +544,7 @@ public static Tensor mul<Tx, Ty>(Tx x, Ty y, string name = null)
544544
{
545545
if (tf.context.executing_eagerly())
546546
{
547-
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Mul", name, x, y);
547+
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "Mul", name, null, x, y);
548548
return _result;
549549
}
550550

@@ -564,7 +564,7 @@ public static Tensor real_div(Tensor x, Tensor y, string name = null)
564564
{
565565
if (tf.context.executing_eagerly())
566566
{
567-
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "RealDiv", name, x, y);
567+
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "RealDiv", name, null, x, y);
568568
return _result;
569569
}
570570

@@ -591,7 +591,7 @@ public static Tensor floor_div(Tensor x, Tensor y, string name = null)
591591
{
592592
if (tf.context.executing_eagerly())
593593
{
594-
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "FloorDiv", name, x, y);
594+
var _result = pywrap_tfe_src.TFE_Py_FastPathExecute(tf.context, "", "FloorDiv", name, null, x, y);
595595
return _result;
596596
}
597597

‎src/TensorFlowNET.Core/Protobuf/AllocationDescription.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static AllocationDescriptionReflection() {
3535
"BnByb3RvMw=="));
3636
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
3737
new pbr::FileDescriptor[] { },
38-
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
39-
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.AllocationDescription), global::Tensorflow.AllocationDescription.Parser, new[]{ "RequestedBytes", "AllocatedBytes", "AllocatorName", "AllocationId", "HasSingleReference", "Ptr" }, null, null, null)
38+
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
39+
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.AllocationDescription), global::Tensorflow.AllocationDescription.Parser, new[]{ "RequestedBytes", "AllocatedBytes", "AllocatorName", "AllocationId", "HasSingleReference", "Ptr" }, null, null, null, null)
4040
}));
4141
}
4242
#endregion

‎src/TensorFlowNET.Core/Protobuf/ApiDef.cs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ static ApiDefReflection() {
4949
"YgZwcm90bzM="));
5050
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
5151
new pbr::FileDescriptor[] { global::Tensorflow.AttrValueReflection.Descriptor, },
52-
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
53-
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef), global::Tensorflow.ApiDef.Parser, new[]{ "GraphOpName", "DeprecationMessage", "DeprecationVersion", "Visibility", "Endpoint", "InArg", "OutArg", "ArgOrder", "Attr", "Summary", "Description", "DescriptionPrefix", "DescriptionSuffix" }, null, new[]{ typeof(global::Tensorflow.ApiDef.Types.Visibility) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef.Types.Endpoint), global::Tensorflow.ApiDef.Types.Endpoint.Parser, new[]{ "Name", "Deprecated", "DeprecationVersion" }, null, null, null),
54-
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef.Types.Arg), global::Tensorflow.ApiDef.Types.Arg.Parser, new[]{ "Name", "RenameTo", "Description" }, null, null, null),
55-
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef.Types.Attr), global::Tensorflow.ApiDef.Types.Attr.Parser, new[]{ "Name", "RenameTo", "DefaultValue", "Description" }, null, null, null)}),
56-
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDefs), global::Tensorflow.ApiDefs.Parser, new[]{ "Op" }, null, null, null)
52+
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
53+
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef), global::Tensorflow.ApiDef.Parser, new[]{ "GraphOpName", "DeprecationMessage", "DeprecationVersion", "Visibility", "Endpoint", "InArg", "OutArg", "ArgOrder", "Attr", "Summary", "Description", "DescriptionPrefix", "DescriptionSuffix" }, null, new[]{ typeof(global::Tensorflow.ApiDef.Types.Visibility) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef.Types.Endpoint), global::Tensorflow.ApiDef.Types.Endpoint.Parser, new[]{ "Name", "Deprecated", "DeprecationVersion" }, null, null, null, null),
54+
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef.Types.Arg), global::Tensorflow.ApiDef.Types.Arg.Parser, new[]{ "Name", "RenameTo", "Description" }, null, null, null, null),
55+
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDef.Types.Attr), global::Tensorflow.ApiDef.Types.Attr.Parser, new[]{ "Name", "RenameTo", "DefaultValue", "Description" }, null, null, null, null)}),
56+
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.ApiDefs), global::Tensorflow.ApiDefs.Parser, new[]{ "Op" }, null, null, null, null)
5757
}));
5858
}
5959
#endregion
@@ -172,7 +172,7 @@ public int DeprecationVersion {
172172

173173
/// <summary>Field number for the "visibility" field.</summary>
174174
public const int VisibilityFieldNumber = 2;
175-
private global::Tensorflow.ApiDef.Types.Visibility visibility_ = 0;
175+
private global::Tensorflow.ApiDef.Types.Visibility visibility_ = global::Tensorflow.ApiDef.Types.Visibility.DefaultVisibility;
176176
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
177177
public global::Tensorflow.ApiDef.Types.Visibility Visibility {
178178
get { return visibility_; }
@@ -325,7 +325,7 @@ public override int GetHashCode() {
325325
if (GraphOpName.Length != 0) hash ^= GraphOpName.GetHashCode();
326326
if (DeprecationMessage.Length != 0) hash ^= DeprecationMessage.GetHashCode();
327327
if (DeprecationVersion != 0) hash ^= DeprecationVersion.GetHashCode();
328-
if (Visibility != 0) hash ^= Visibility.GetHashCode();
328+
if (Visibility != global::Tensorflow.ApiDef.Types.Visibility.DefaultVisibility) hash ^= Visibility.GetHashCode();
329329
hash ^= endpoint_.GetHashCode();
330330
hash ^= inArg_.GetHashCode();
331331
hash ^= outArg_.GetHashCode();
@@ -352,7 +352,7 @@ public void WriteTo(pb::CodedOutputStream output) {
352352
output.WriteRawTag(10);
353353
output.WriteString(GraphOpName);
354354
}
355-
if (Visibility != 0) {
355+
if (Visibility != global::Tensorflow.ApiDef.Types.Visibility.DefaultVisibility) {
356356
output.WriteRawTag(16);
357357
output.WriteEnum((int) Visibility);
358358
}
@@ -402,7 +402,7 @@ public int CalculateSize() {
402402
if (DeprecationVersion != 0) {
403403
size += 1 + pb::CodedOutputStream.ComputeInt32Size(DeprecationVersion);
404404
}
405-
if (Visibility != 0) {
405+
if (Visibility != global::Tensorflow.ApiDef.Types.Visibility.DefaultVisibility) {
406406
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Visibility);
407407
}
408408
size += endpoint_.CalculateSize(_repeated_endpoint_codec);
@@ -442,7 +442,7 @@ public void MergeFrom(ApiDef other) {
442442
if (other.DeprecationVersion != 0) {
443443
DeprecationVersion = other.DeprecationVersion;
444444
}
445-
if (other.Visibility != 0) {
445+
if (other.Visibility != global::Tensorflow.ApiDef.Types.Visibility.DefaultVisibility) {
446446
Visibility = other.Visibility;
447447
}
448448
endpoint_.Add(other.endpoint_);
@@ -478,7 +478,7 @@ public void MergeFrom(pb::CodedInputStream input) {
478478
break;
479479
}
480480
case 16: {
481-
visibility_ = (global::Tensorflow.ApiDef.Types.Visibility) input.ReadEnum();
481+
Visibility = (global::Tensorflow.ApiDef.Types.Visibility) input.ReadEnum();
482482
break;
483483
}
484484
case 26: {
@@ -1152,7 +1152,7 @@ public void MergeFrom(Attr other) {
11521152
}
11531153
if (other.defaultValue_ != null) {
11541154
if (defaultValue_ == null) {
1155-
defaultValue_ = new global::Tensorflow.AttrValue();
1155+
DefaultValue = new global::Tensorflow.AttrValue();
11561156
}
11571157
DefaultValue.MergeFrom(other.DefaultValue);
11581158
}
@@ -1180,9 +1180,9 @@ public void MergeFrom(pb::CodedInputStream input) {
11801180
}
11811181
case 26: {
11821182
if (defaultValue_ == null) {
1183-
defaultValue_ = new global::Tensorflow.AttrValue();
1183+
DefaultValue = new global::Tensorflow.AttrValue();
11841184
}
1185-
input.ReadMessage(defaultValue_);
1185+
input.ReadMessage(DefaultValue);
11861186
break;
11871187
}
11881188
case 34: {

0 commit comments

Comments
 (0)