<!-- HTML header for doxygen 1.8.14--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.11"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>Caffe2 - C++ API: caffe2/operators/concat_split_op.cc Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link rel="icon" href="/static/favicon.png" type="image/x-icon"> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="search/searchdata.js"></script> <script type="text/javascript" src="search/search.js"></script> <script type="text/javascript"> $(document).ready(function() { init_search(); }); </script> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> <link href="main.css" rel="stylesheet" type="text/css"/> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectlogo" width="56"><a href="/"><img alt="Logo" src="Caffe2-with-name-55-tall.png"/></a></td> <td id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">Caffe2 - C++ API </div> <div id="projectbrief">A deep learning, cross platform ML framework</div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.11 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="/doxygen-c/html/classes.html"><span>C++ API</span></a></li> <li><a href="/doxygen-python/html/annotated.html"><span>Python API</span></a></li> <li><a href="https://github.com/caffe2/caffe2"><span>GitHub</span></a></li> <li> <div id="MSearchBox" class="MSearchBoxInactive"> <span class="left"> <img id="MSearchSelect" src="search/mag_sel.png" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" alt=""/> <input type="text" id="MSearchField" value="Search" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)" onkeyup="searchBox.OnSearchFieldChange(event)"/> </span><span class="right"> <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> </span> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <!-- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> </div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="dir_20697b8f204bdfcab31e6b1a416f3ab8.html">caffe2</a></li><li class="navelem"><a class="el" href="dir_a88b8b93dde245e9b5ee872e77180f4c.html">operators</a></li> </ul> </div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">concat_split_op.cc</div> </div> </div><!--header--> <div class="contents"> <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="preprocessor">#include "caffe2/operators/concat_split_op.h"</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> </div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="keyword">namespace </span><a class="code" href="namespacecaffe2.html">caffe2</a> {</div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="keyword">namespace </span>{</div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> std::pair<std::vector<DeviceOption>, std::vector<DeviceOption>> splitOpDevInfer(</div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>  <span class="keyword">const</span> OperatorDef& def) {</div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>  <span class="keyword">auto</span> op_device =</div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>  def.has_device_option() ? def.device_option() : DeviceOption();</div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>  vector<DeviceOption> in_dev(def.input_size(), op_device);</div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>  vector<DeviceOption> out_dev(def.output_size(), op_device);</div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> </div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>  <span class="comment">// If we obtain split from input tensor, then 2nd input's type is always CPU.</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>  <span class="keywordflow">if</span> (def.input_size() == SplitOp<CPUContext>::kSplitOpInputSize) {</div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>  CAFFE_ENFORCE_GT(in_dev.size(), 1);</div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>  in_dev[1] = DeviceOption();</div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>  }</div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>  <span class="keywordflow">return</span> std::make_pair(in_dev, out_dev);</div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> }</div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> } <span class="comment">// namespace.</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> </div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> REGISTER_CPU_OPERATOR(Split, SplitOp<CPUContext>);</div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> OPERATOR_SCHEMA(Split)</div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>  .NumInputs(1, 2)</div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>  .NumOutputs(1, INT_MAX)</div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>  .Input(0, <span class="stringliteral">"input"</span>, <span class="stringliteral">"The tensor to split"</span>)</div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>  .Input(1, <span class="stringliteral">"split"</span>, <span class="stringliteral">"Optional list of output lengths (see also arg 'split')"</span>)</div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>  .Arg(<span class="stringliteral">"axis"</span>, <span class="stringliteral">"Which axis to split on"</span>)</div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>  .Arg(<span class="stringliteral">"split"</span>, <span class="stringliteral">"length of each output"</span>)</div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>  .Arg(<span class="stringliteral">"order"</span>, <span class="stringliteral">"Either NHWC or NCWH, will split on C axis, defaults to NCHW"</span>)</div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  .DeviceInferenceFunction(splitOpDevInfer)</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  .SetDoc(R<span class="stringliteral">"DOC(</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="stringliteral">Split a tensor into a list of tensors, along the specified</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="stringliteral">'axis'. The lengths of the split can be specified using argument 'split' or</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="stringliteral">optional second input blob to the operator. Otherwise, the tensor is split</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="stringliteral">to equal sized parts.</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="stringliteral">)DOC")</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="stringliteral"> .InheritOnnxSchema(</span><span class="stringliteral">"Split"</span>);</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> </div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="keyword">namespace </span>{</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> OpSchema::Cost CostInferenceForConcat(</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="keyword">const</span> OperatorDef& def,</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  <span class="keyword">const</span> vector<TensorShape>& in) {</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  ArgumentHelper helper(def);</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> axis = helper.HasArgument(<span class="stringliteral">"axis"</span>)</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  ? helper.GetSingleArgument<<span class="keywordtype">int</span>>(<span class="stringliteral">"axis"</span>, -1)</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  : GetDimFromOrderString(</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  helper.GetSingleArgument<<span class="keywordtype">string</span>>(<span class="stringliteral">"order"</span>, <span class="stringliteral">"NCHW"</span>));</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  <span class="keywordtype">bool</span> add_axis = helper.GetSingleArgument<<span class="keywordtype">int</span>>(<span class="stringliteral">"add_axis"</span>, 0) != 0;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> canonical_axis = canonical_axis_index_(axis, in[0].dims_size());</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  CAFFE_ENFORCE_GT(in.size(), 0);</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  vector<int> out_shape(in[0].dims().begin(), in[0].dims().end());</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="keywordflow">if</span> (add_axis) {</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  out_shape.insert(out_shape.begin() + canonical_axis, in.size());</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i < in.size(); ++i) {</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  out_shape[canonical_axis] += in[i].dims(canonical_axis);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  }</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  }</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="keywordtype">int</span> size = 1;</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="keywordflow">for</span> (<span class="keyword">auto</span>& s : out_shape) {</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  size *= s;</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  }</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> </div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <span class="keyword">struct </span>OpSchema::Cost cost;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  cost.flops = 0;</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  cost.bytes_moved = size * <span class="keyword">sizeof</span>(float);</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  cost.params_bytes = 0;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="keywordflow">return</span> cost;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> }</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span> </div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span> std::pair<std::vector<DeviceOption>, std::vector<DeviceOption>></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span> concatOpDevInfer(<span class="keyword">const</span> OperatorDef& def) {</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keyword">auto</span> op_device =</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  def.has_device_option() ? def.device_option() : DeviceOption();</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  vector<DeviceOption> in_dev(def.input_size(), op_device);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  vector<DeviceOption> out_dev(def.output_size(), op_device);</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span> </div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="comment">// 2nd output's type is always CPU irrespective of op's device option.</span></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  CAFFE_ENFORCE_GT(out_dev.size(), 1);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  out_dev[1] = DeviceOption();</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <span class="keywordflow">return</span> std::make_pair(in_dev, out_dev);</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span> }</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span> } <span class="comment">// namespace</span></div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> </div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> REGISTER_CPU_OPERATOR(Concat, ConcatOp<CPUContext>);</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> OPERATOR_SCHEMA(Concat)</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  .NumInputs(1, INT_MAX)</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  .NumOutputs(2)</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  .Arg(<span class="stringliteral">"axis"</span>, <span class="stringliteral">"Which axis to concat on"</span>)</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  .Arg(</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <span class="stringliteral">"order"</span>,</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="stringliteral">"Either NHWC or NCHW, will concat on C axis, defaults to NCHW"</span>)</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  .Arg(</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="stringliteral">"add_axis"</span>,</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <span class="stringliteral">"Pass 1 to add the axis specified in arg 'axis' to all "</span></div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  <span class="stringliteral">"input tensors"</span>)</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  .TensorInferenceFunction([](<span class="keyword">const</span> OperatorDef& def,</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  <span class="keyword">const</span> vector<TensorShape>& in) {</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  ArgumentHelper helper(def);</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> axis = helper.HasArgument(<span class="stringliteral">"axis"</span>)</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  ? helper.GetSingleArgument<<span class="keywordtype">int</span>>(<span class="stringliteral">"axis"</span>, -1)</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  : GetDimFromOrderString(</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  helper.GetSingleArgument<<span class="keywordtype">string</span>>(<span class="stringliteral">"order"</span>, <span class="stringliteral">"NCHW"</span>));</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  <span class="keywordtype">bool</span> add_axis = helper.GetSingleArgument<<span class="keywordtype">int</span>>(<span class="stringliteral">"add_axis"</span>, 0) != 0;</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> canonical_axis = canonical_axis_index_(axis, in[0].dims_size());</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  CAFFE_ENFORCE_GT(in.size(), 0);</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  vector<int> split_shape(1, in.size());</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  vector<int> out_shape(in[0].dims().begin(), in[0].dims().end());</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keywordflow">if</span> (add_axis) {</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i < in.size(); ++i) {</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  CAFFE_ENFORCE_EQ(</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  in[0].dims().size(),</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  in[i].dims().size(),</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="stringliteral">"All inputs of Concat should have same dims when add_axis = 1. "</span></div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <span class="stringliteral">"Got different sizes for inputs 0 and "</span>,</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  i);</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < in[0].dims().size(); ++j) {</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  CAFFE_ENFORCE_EQ(</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  in[0].dims(j),</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  in[i].dims(j),</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  <span class="stringliteral">"All inputs of Concat should have same dims when add_axis = 1. "</span></div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="stringliteral">"Got different dims for inputs 0 and "</span>,</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  i,</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="stringliteral">". At dim: "</span>,</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  j);</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span>  }</div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  }</div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  out_shape.insert(out_shape.begin() + canonical_axis, in.size());</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i < in.size(); ++i) {</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  CAFFE_ENFORCE_EQ(</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  in[0].dims().size(),</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  in[i].dims().size(),</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  <span class="stringliteral">"All inputs of Concat should have same dims except "</span></div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="stringliteral">"canonical_axis dim that is equal to "</span>,</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  canonical_axis,</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  <span class="stringliteral">"Got different sizes for inputs 0 and "</span>,</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  i);</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < in[0].dims().size(); ++j) {</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  <span class="keywordflow">if</span> (j == canonical_axis) {</div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  <span class="keywordflow">continue</span>;</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  }</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  CAFFE_ENFORCE_EQ(</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  in[0].dims(j),</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  in[i].dims(j),</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <span class="stringliteral">"All inputs of Concat should have same dims except "</span></div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <span class="stringliteral">"canonical_axis dim that is equal to "</span>,</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  canonical_axis,</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="stringliteral">"Got different dims for inputs 0 and "</span>,</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  i,</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  <span class="stringliteral">". At dim: "</span>,</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  j);</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  }</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  }</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span> </div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i < in.size(); ++i) {</div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  out_shape[canonical_axis] += in[i].dims(canonical_axis);</div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  }</div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  }</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  <span class="keywordflow">if</span> (def.output_size() == 1) {</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  <span class="keywordflow">return</span> vector<TensorShape>{</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  CreateTensorShape(out_shape, in[0].data_type())};</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  }</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  <span class="keywordflow">return</span> vector<TensorShape>{</div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  CreateTensorShape(out_shape, in[0].data_type()),</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  CreateTensorShape(split_shape, TensorProto::INT32)};</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  })</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  .CostInferenceFunction(CostInferenceForConcat)</div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  .DeviceInferenceFunction(concatOpDevInfer)</div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  .SetDoc(<span class="stringliteral">"Concatenate a list of tensors into a single tensor"</span>)</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  .Output(0, <span class="stringliteral">"concat_result"</span>, <span class="stringliteral">"Concatenated tensor"</span>)</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  .Output(1, <span class="stringliteral">"split_info"</span>, <span class="stringliteral">"The dimensions of the inputs."</span>)</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  .InheritOnnxSchema(<span class="stringliteral">"Concat"</span>);</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span> </div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span> <span class="comment">// Backward compatibility names.</span></div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span> REGISTER_CPU_OPERATOR(DepthSplit, SplitOp<CPUContext>);</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span> REGISTER_CPU_OPERATOR(DepthConcat, ConcatOp<CPUContext>);</div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span> OPERATOR_SCHEMA(DepthSplit)</div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  .NumInputs(1, 2)</div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  .NumOutputs(1, INT_MAX)</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  .SetDoc(<span class="stringliteral">"Backward compatible operator name for Split."</span>);</div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span> OPERATOR_SCHEMA(DepthConcat)</div><div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  .NumInputs(1, INT_MAX)</div><div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  .NumOutputs(2)</div><div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  .SetDoc(<span class="stringliteral">"Backward compatible operator name for Concat."</span>);</div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span> </div><div class="line"><a name="l00187"></a><span class="lineno"><a class="line" href="classcaffe2_1_1_get_split_gradient.html"> 187</a></span> <span class="keyword">class </span><a class="code" href="classcaffe2_1_1_get_split_gradient.html">GetSplitGradient</a> : <span class="keyword">public</span> <a class="code" href="classcaffe2_1_1_gradient_maker_base.html">GradientMakerBase</a> {</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  <span class="keyword">using</span> GradientMakerBase::GradientMakerBase;</div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  vector<OperatorDef> GetGradientDefs()<span class="keyword"> override </span>{</div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  vector<string> output_grads;</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < def_.output_size(); ++i) {</div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  <span class="keywordflow">if</span> (!GradOut(i).IsEmpty()) {</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  output_grads.push_back(GO(i));</div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  }</div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  }</div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  <span class="keywordflow">if</span> (output_grads.empty()) {</div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  <span class="keywordflow">return</span> {};</div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  }</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  <span class="keywordflow">return</span> <a class="code" href="classcaffe2_1_1_gradient_maker_base.html#a44d7fb1a86d355a0d057648443f2d1f7">SingleGradientDef</a>(</div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  <span class="stringliteral">"Concat"</span>,</div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  <span class="stringliteral">""</span>,</div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  output_grads,</div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  vector<string>{GI(0), <span class="stringliteral">"_"</span> + GI(0) + <span class="stringliteral">"_dims"</span>});</div><div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  }</div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span> };</div><div class="line"><a name="l00206"></a><span class="lineno"> 206</span> REGISTER_GRADIENT(Split, <a class="code" href="classcaffe2_1_1_get_split_gradient.html">GetSplitGradient</a>);</div><div class="line"><a name="l00207"></a><span class="lineno"> 207</span> REGISTER_GRADIENT(DepthSplit, <a class="code" href="classcaffe2_1_1_get_split_gradient.html">GetSplitGradient</a>);</div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span> </div><div class="line"><a name="l00209"></a><span class="lineno"><a class="line" href="classcaffe2_1_1_get_concat_gradient.html"> 209</a></span> <span class="keyword">class </span><a class="code" href="classcaffe2_1_1_get_concat_gradient.html">GetConcatGradient</a> : <span class="keyword">public</span> <a class="code" href="classcaffe2_1_1_gradient_maker_base.html">GradientMakerBase</a> {</div><div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  <span class="keyword">using</span> GradientMakerBase::GradientMakerBase;</div><div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  vector<OperatorDef> GetGradientDefs()<span class="keyword"> override </span>{</div><div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  <span class="keywordflow">if</span> (GradOut(0).IsEmpty()) {</div><div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  <span class="keywordflow">return</span> {};</div><div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  }</div><div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  vector<string> grads;</div><div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < def_.input_size(); ++i) {</div><div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  grads.push_back(GI(i));</div><div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  }</div><div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  <span class="keywordflow">return</span> <a class="code" href="classcaffe2_1_1_gradient_maker_base.html#a44d7fb1a86d355a0d057648443f2d1f7">SingleGradientDef</a>(<span class="stringliteral">"Split"</span>, <span class="stringliteral">""</span>, vector<string>{GO(0), O(1)}, grads);</div><div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  }</div><div class="line"><a name="l00221"></a><span class="lineno"> 221</span> };</div><div class="line"><a name="l00222"></a><span class="lineno"> 222</span> REGISTER_GRADIENT(Concat, <a class="code" href="classcaffe2_1_1_get_concat_gradient.html">GetConcatGradient</a>);</div><div class="line"><a name="l00223"></a><span class="lineno"> 223</span> REGISTER_GRADIENT(DepthConcat, <a class="code" href="classcaffe2_1_1_get_concat_gradient.html">GetConcatGradient</a>);</div><div class="line"><a name="l00224"></a><span class="lineno"> 224</span> } <span class="comment">// namespace caffe2</span></div><div class="ttc" id="classcaffe2_1_1_gradient_maker_base_html"><div class="ttname"><a href="classcaffe2_1_1_gradient_maker_base.html">caffe2::GradientMakerBase</a></div><div class="ttdef"><b>Definition:</b> <a href="operator__gradient_8h_source.html#l00047">operator_gradient.h:47</a></div></div> <div class="ttc" id="namespacecaffe2_html"><div class="ttname"><a href="namespacecaffe2.html">caffe2</a></div><div class="ttdoc">A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...</div><div class="ttdef"><b>Definition:</b> <a href="convert__encoded__to__raw__leveldb_8cc_source.html#l00047">convert_encoded_to_raw_leveldb.cc:47</a></div></div> <div class="ttc" id="classcaffe2_1_1_gradient_maker_base_html_a44d7fb1a86d355a0d057648443f2d1f7"><div class="ttname"><a href="classcaffe2_1_1_gradient_maker_base.html#a44d7fb1a86d355a0d057648443f2d1f7">caffe2::GradientMakerBase::SingleGradientDef</a></div><div class="ttdeci">static vector< OperatorDef > SingleGradientDef(const Args &...args)</div><div class="ttdoc">a helper function to allow one to create one single operator def, which is usually the case for many ...</div><div class="ttdef"><b>Definition:</b> <a href="operator__gradient_8h_source.html#l00199">operator_gradient.h:199</a></div></div> <div class="ttc" id="classcaffe2_1_1_get_concat_gradient_html"><div class="ttname"><a href="classcaffe2_1_1_get_concat_gradient.html">caffe2::GetConcatGradient</a></div><div class="ttdef"><b>Definition:</b> <a href="concat__split__op_8cc_source.html#l00209">concat_split_op.cc:209</a></div></div> <div class="ttc" id="classcaffe2_1_1_get_split_gradient_html"><div class="ttname"><a href="classcaffe2_1_1_get_split_gradient.html">caffe2::GetSplitGradient</a></div><div class="ttdef"><b>Definition:</b> <a href="concat__split__op_8cc_source.html#l00187">concat_split_op.cc:187</a></div></div> </div><!-- fragment --></div><!-- contents --> <!-- HTML footer for doxygen 1.8.14--> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated on Thu Apr 19 2018 13:03:55 for Caffe2 - C++ API by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.11 </small></address> <div class="footerContainer"> <div id="footer_wrap" class="wrapper footerWrapper"> <div class="footerBlocks"> <div id="fb_oss" class="footerSection fbOpenSourceFooter"> <svg class="facebookOSSLogoSvg" viewBox="0 0 1133.9 1133.9" x="0px" y="0px" height=50 width=50> <g> <path class="logoRing outerRing" d="M 498.3 3.7 c 153.6 88.9 307.3 177.7 461.1 266.2 c 7.6 4.4 10.3 9.1 10.3 17.8 c -0.3 179.1 -0.2 358.3 0 537.4 c 0 8.1 -2.4 12.8 -9.7 17.1 c -154.5 88.9 -308.8 178.1 -462.9 267.5 c -9 5.2 -15.5 5.3 -24.6 0.1 c -153.9 -89.2 -307.9 -178 -462.1 -266.8 C 3 838.8 0 833.9 0 825.1 c 0.3 -179.1 0.2 -358.3 0 -537.4 c 0 -8.6 2.6 -13.6 10.2 -18 C 164.4 180.9 318.4 92 472.4 3 C 477 -1.5 494.3 -0.7 498.3 3.7 Z M 48.8 555.3 c 0 79.9 0.2 159.9 -0.2 239.8 c -0.1 10 3 15.6 11.7 20.6 c 137.2 78.8 274.2 157.8 411 237.3 c 9.9 5.7 17 5.7 26.8 0.1 c 137.5 -79.8 275.2 -159.2 412.9 -238.5 c 7.4 -4.3 10.5 -8.9 10.5 -17.8 c -0.3 -160.2 -0.3 -320.5 0 -480.7 c 0 -8.8 -2.8 -13.6 -10.3 -18 C 772.1 218 633.1 137.8 494.2 57.4 c -6.5 -3.8 -11.5 -4.5 -18.5 -0.5 C 336.8 137.4 197.9 217.7 58.8 297.7 c -7.7 4.4 -10.2 9.2 -10.2 17.9 C 48.9 395.5 48.8 475.4 48.8 555.3 Z" /> <path class="logoRing middleRing" d="M 184.4 555.9 c 0 -33.3 -1 -66.7 0.3 -100 c 1.9 -48 24.1 -86 64.7 -110.9 c 54.8 -33.6 110.7 -65.5 167 -96.6 c 45.7 -25.2 92.9 -24.7 138.6 1 c 54.4 30.6 108.7 61.5 162.2 93.7 c 44 26.5 67.3 66.8 68 118.4 c 0.9 63.2 0.9 126.5 0 189.7 c -0.7 50.6 -23.4 90.7 -66.6 116.9 c -55 33.4 -110.8 65.4 -167.1 96.5 c -43.4 24 -89 24.2 -132.3 0.5 c -57.5 -31.3 -114.2 -64 -170 -98.3 c -41 -25.1 -62.9 -63.7 -64.5 -112.2 C 183.5 621.9 184.3 588.9 184.4 555.9 Z M 232.9 556.3 c 0 29.5 0.5 59.1 -0.1 88.6 c -0.8 39.2 16.9 67.1 50.2 86.2 c 51.2 29.4 102.2 59.2 153.4 88.4 c 31.4 17.9 63.6 18.3 95 0.6 c 53.7 -30.3 107.1 -61.2 160.3 -92.5 c 29.7 -17.5 45 -44.5 45.3 -78.8 c 0.6 -61.7 0.5 -123.5 0 -185.2 c -0.3 -34.4 -15.3 -61.5 -44.9 -79 C 637.7 352.6 583 320.8 527.9 290 c -27.5 -15.4 -57.2 -16.1 -84.7 -0.7 c -56.9 31.6 -113.4 64 -169.1 97.6 c -26.4 15.9 -40.7 41.3 -41.1 72.9 C 232.6 491.9 232.9 524.1 232.9 556.3 Z" /> <path class="logoRing innerRing" d="M 484.9 424.4 c 69.8 -2.8 133.2 57.8 132.6 132 C 617 630 558.5 688.7 484.9 689.1 c -75.1 0.4 -132.6 -63.6 -132.7 -132.7 C 352.1 485 413.4 421.5 484.9 424.4 Z M 401.3 556.7 c -3.4 37.2 30.5 83.6 83 84.1 c 46.6 0.4 84.8 -37.6 84.9 -84 c 0.1 -46.6 -37.2 -84.4 -84.2 -84.6 C 432.2 472.1 397.9 518.3 401.3 556.7 Z" /> </g> </svg> <h2>Facebook Open Source</h2> </div> <div class="footerSection"> <a class="footerLink" href="https://code.facebook.com/projects/" target="_blank">Open Source Projects</a> <a class="footerLink" href="https://github.com/facebook/" target="_blank">GitHub</a> <a class="footerLink" href="https://twitter.com/fbOpenSource" target="_blank">Twitter</a> </div> <div class="footerSection rightAlign"> <a class="footerLink" href="https://github.com/caffe2/caffe2" target="_blank">Contribute to this project on GitHub</a> </div> </div> </div> </div> <script type="text/javascript" src="/js/jekyll-link-anchors.js"></script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', '{{ site.gacode }}', 'auto'); ga('send', 'pageview'); </script> </body> </html>