<html dir="ltr"><head>
<link href="https://www.blogger.com/static/v1/widgets/55013136-widget_css_bundle.css" rel="stylesheet" type="text/css">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta content="blogger" name="generator">
<link href="http://cudamusing.blogspot.com/favicon.ico" rel="icon" type="image/x-icon">
<link href="http://cudamusing.blogspot.com/" rel="canonical">
<link rel="alternate" type="application/atom+xml" title="CUDA Musing - Atom" href="http://cudamusing.blogspot.com/feeds/posts/default">
<link rel="alternate" type="application/rss+xml" title="CUDA Musing - RSS" href="http://cudamusing.blogspot.com/feeds/posts/default?alt=rss">
<link rel="service.post" type="application/atom+xml" title="CUDA Musing - Atom" href="https://draft.blogger.com/feeds/5417613544042855153/posts/default">
<link rel="me" href="https://draft.blogger.com/profile/06026735414532627847">
<!--Can't find substitution for tag [blog.ieCssRetrofitLinks]-->
<meta content="http://cudamusing.blogspot.com/" property="og:url">
<meta content="CUDA Musing" property="og:title">
<meta content="Random collection of CUDA examples, tricks and suggestions." property="og:description">
<title>CUDA Musing</title>
<style id="page-skin-1" type="text/css"><!--
/*
-----------------------------------------------
Blogger Template Style
Name:     Minima Stretch
Date:     26 Feb 2004
----------------------------------------------- */
/* Use this with templates/template-twocol.html */
body {
background:#ffffff;
margin:0;
color:#333333;
font:x-small Georgia Serif;
font-size/* */:/**/small;
font-size: /**/small;
text-align: center;
}
a:link {
color:#5588aa;
text-decoration:none;
}
a:visited {
color:#999999;
text-decoration:none;
}
a:hover {
color:#cc6600;
text-decoration:underline;
}
a img {
border-width:0;
}
/* Header
-----------------------------------------------
*/
#header-wrapper {
margin:0 2% 10px;
border:1px solid #cccccc;
}
#header {
margin: 5px;
border: 1px solid #cccccc;
text-align: center;
color:#666666;
}
#header-inner {
background-position: center;
margin-left: auto;
margin-right: auto;
}
#header h1 {
margin:5px 5px 0;
padding:15px 20px .25em;
line-height:1.2em;
text-transform:uppercase;
letter-spacing:.2em;
font: normal normal 200% Georgia, Serif;
}
#header a {
color:#666666;
text-decoration:none;
}
#header a:hover {
color:#666666;
}
#header .description {
margin:0 5px 5px;
padding:0 20px 15px;
text-transform:uppercase;
letter-spacing:.2em;
line-height: 1.4em;
font: normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif;
color: #999999;
}
#header img {
margin-left: auto;
margin-right: auto;
}
/* Outer-Wrapper
----------------------------------------------- */
#outer-wrapper {
margin:0;
padding:10px;
text-align:left;
font: normal normal 100% Georgia, Serif;
}
#main-wrapper {
margin-left: 2%;
width: 67%;
float: left;
display: inline;       /* fix for doubling margin in IE */
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden;      /* fix for long non-text content breaking IE sidebar float */
}
#sidebar-wrapper {
margin-right: 2%;
width: 25%;
float: right;
display: inline;       /* fix for doubling margin in IE */
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden;      /* fix for long non-text content breaking IE sidebar float */
}
/* Headings
----------------------------------------------- */
h2 {
margin:1.5em 0 .75em;
font:normal normal 78% 'Trebuchet MS',Trebuchet,Arial,Verdana,Sans-serif;
line-height: 1.4em;
text-transform:uppercase;
letter-spacing:.2em;
color:#999999;
}
/* Posts
-----------------------------------------------
*/
h2.date-header {
margin:1.5em 0 .5em;
}
.post {
margin:.5em 0 1.5em;
border-bottom:1px dotted #cccccc;
padding-bottom:1.5em;
}
.post h3 {
margin:.25em 0 0;
padding:0 0 4px;
font-size:140%;
font-weight:normal;
line-height:1.4em;
color:#cc6600;
}
.post h3 a, .post h3 a:visited, .post h3 strong {
display:block;
text-decoration:none;
color:#cc6600;
font-weight:normal;
}
.post h3 strong, .post h3 a:hover {
color:#333333;
}
.post-body {
margin:0 0 .75em;
line-height:1.6em;
}
.post-body blockquote {
line-height:1.3em;
}
.post-footer {
margin: .75em 0;
color:#999999;
text-transform:uppercase;
letter-spacing:.1em;
font: normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif;
line-height: 1.4em;
}
.comment-link {
margin-left:.6em;
}
.post img, table.tr-caption-container {
padding:4px;
border:1px solid #cccccc;
}
.tr-caption-container img {
border: none;
padding: 0;
}
.post blockquote {
margin:1em 20px;
}
.post blockquote p {
margin:.75em 0;
}
/* Comments
----------------------------------------------- */
#comments h4 {
margin:1em 0;
font-weight: bold;
line-height: 1.4em;
text-transform:uppercase;
letter-spacing:.2em;
color: #999999;
}
#comments-block {
margin:1em 0 1.5em;
line-height:1.6em;
}
#comments-block .comment-author {
margin:.5em 0;
}
#comments-block .comment-body {
margin:.25em 0 0;
}
#comments-block .comment-footer {
margin:-.25em 0 2em;
line-height: 1.4em;
text-transform:uppercase;
letter-spacing:.1em;
}
#comments-block .comment-body p {
margin:0 0 .75em;
}
.deleted-comment {
font-style:italic;
color:gray;
}
.feed-links {
clear: both;
line-height: 2.5em;
}
#blog-pager-newer-link {
float: left;
}
#blog-pager-older-link {
float: right;
}
#blog-pager {
text-align: center;
}
/* Sidebar Content
----------------------------------------------- */
.sidebar {
color: #666666;
line-height: 1.5em;
}
.sidebar ul {
list-style:none;
margin:0 0 0;
padding:0 0 0;
}
.sidebar li {
margin:0;
padding-top:0;
padding-right:0;
padding-bottom:.25em;
padding-left:15px;
text-indent:-15px;
line-height:1.5em;
}
.sidebar .widget, .main .widget {
border-bottom:1px dotted #cccccc;
margin:0 0 1.5em;
padding:0 0 1.5em;
}
.main .Blog {
border-bottom-width: 0;
}
/* Profile
----------------------------------------------- */
.profile-img {
float: left;
margin-top: 0;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 0;
padding: 4px;
border: 1px solid #cccccc;
}
.profile-data {
margin:0;
text-transform:uppercase;
letter-spacing:.1em;
font: normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif;
color: #999999;
font-weight: bold;
line-height: 1.6em;
}
.profile-datablock {
margin:.5em 0 .5em;
}
.profile-textblock {
margin: 0.5em 0;
line-height: 1.6em;
}
.profile-link {
font: normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif;
text-transform: uppercase;
letter-spacing: .1em;
}
/* Footer
----------------------------------------------- */
#footer {
width:660px;
clear:both;
margin:0 auto;
padding-top:15px;
line-height: 1.6em;
text-transform:uppercase;
letter-spacing:.1em;
text-align: center;
}

--></style>
<link href="https://draft.blogger.com/dyn-css/authorization.css?targetBlogID=5417613544042855153&amp;zx=fa35311f-671e-4574-8b8e-3eacd4557487" media="all" onload="if(media!='all')media='all'" rel="stylesheet"><noscript><link href='https://draft.blogger.com/dyn-css/authorization.css?targetBlogID=5417613544042855153&amp;zx=fa35311f-671e-4574-8b8e-3eacd4557487' rel='stylesheet'/></noscript>
<meta name="google-adsense-platform-account" content="ca-host-pub-1556223355139109">
<meta name="google-adsense-platform-domain" content="blogspot.com">

<!-- data-ad-client=ca-pub-9986733645989591 -->

<script src="https://pagead2.googlesyndication.com/pagead/managed/js/adsense/m202408140101/show_ads_impl.js?bust=31086219"></script><script src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><script type="text/javascript" src="//pagead2.googlesyndication.com/pagead/js/google_top_exp.js"></script><style>.gc-bubbleDefault{background-color:transparent!important;text-align:left;padding:0!important;margin:0!important;border:0!important;table-layout:auto!important}.gc-reset{background-color:transparent!important;border:0!important;padding:0!important;margin:0!important;text-align:left}.pls-bubbleTop{border-bottom:1px solid #ccc!important}.pls-contentLeft,.pls-topTail,.pls-vertShimLeft{background-image:url(//ssl.gstatic.com/s2/oz/images/stars/po/bubblev1/border_3.gif)!important}.pls-topTail{background-repeat:repeat-x!important;background-position:bottom!important}.pls-vertShim{background-color:#fff!important;text-align:right}.tbl-grey .pls-vertShim{background-color:#f5f5f5!important}.pls-vertShimLeft{background-repeat:repeat-y!important;background-position:100%!important;height:4px}.pls-vertShimRight{height:4px}.pls-confirm-container .pls-vertShim{background-color:#fff3c2!important}.pls-contentWrap{background-color:#fff!important;position:relative!important;vertical-align:top}.pls-contentLeft{background-repeat:repeat-y;background-position:100%;vertical-align:top}.pls-dropRight{background-image:url(//ssl.gstatic.com/s2/oz/images/stars/po/bubblev1/bubbleDropR_3.png)!important;background-repeat:repeat-y!important;vertical-align:top}.pls-dropBL,.pls-dropTR .pls-dropBR,.pls-tailleft,.pls-vert,.pls-vert img{vertical-align:top}.pls-dropBottom{background-image:url(//ssl.gstatic.com/s2/oz/images/stars/po/bubblev1/bubbleDropB_3.png)!important;background-repeat:repeat-x!important;width:100%;vertical-align:top}.pls-topLeft{background:inherit!important;text-align:right;vertical-align:bottom}.pls-topRight{background:inherit!important;text-align:left;vertical-align:bottom}.pls-bottomLeft{background:inherit!important;text-align:right}.pls-bottomRight{background:inherit!important;text-align:left;vertical-align:top}.pls-tailbottom,.pls-tailleft,.pls-tailright,.pls-tailtop{display:none;position:relative}.pls-dropBL,.pls-dropBR,.pls-dropTR,.pls-tailbottom,.pls-tailleft,.pls-tailright,.pls-tailtop{background-image:url(//ssl.gstatic.com/s2/oz/images/stars/po/bubblev1/bubbleSprite_3.png)!important;background-repeat:no-repeat}.tbl-grey .pls-dropBL,.tbl-grey .pls-dropBR,.tbl-grey .pls-dropTR,.tbl-grey .pls-tailbottom,.tbl-grey .pls-tailleft,.tbl-grey .pls-tailright,.tbl-grey .pls-tailtop{background-image:url(//ssl.gstatic.com/s2/oz/images/stars/po/bubblev1/bubbleSprite-grey.png)!important}.pls-tailbottom{background-position:-23px 0}.pls-confirm-container .pls-tailbottom{background-position:-23px -10px}.pls-tailtop{background-position:-19px -20px}.pls-tailright{background-position:0 0}.pls-tailleft{background-position:-10px 0}.pls-tailtop{vertical-align:top}.gc-bubbleDefault td{line-height:0;font-size:0}.pls-tailbottom,.pls-topLeft img,.pls-topRight img{vertical-align:bottom}.bubbleDropTR,.pls-bottomLeft,.pls-bottomLeft img,.pls-dropBottom img,.pls-dropBottomL img,.pls-dropBottomR img{vertical-align:top}.pls-dropTR{background-position:0 -22px}.pls-dropBR{background-position:0 -27px}.pls-dropBL{background-position:0 -16px}.pls-spacerbottom,.pls-spacerleft,.pls-spacerright,.pls-spacertop{position:static!important}.pls-spinner{bottom:0;position:absolute;left:0;margin:auto;right:0;top:0}</style><meta http-equiv="origin-trial" content="AlK2UR5SkAlj8jjdEc9p3F3xuFYlF6LYjAML3EOqw1g26eCwWPjdmecULvBH5MVPoqKYrOfPhYVL71xAXI1IBQoAAAB8eyJvcmlnaW4iOiJodHRwczovL2RvdWJsZWNsaWNrLm5ldDo0NDMiLCJmZWF0dXJlIjoiV2ViVmlld1hSZXF1ZXN0ZWRXaXRoRGVwcmVjYXRpb24iLCJleHBpcnkiOjE3NTgwNjcxOTksImlzU3ViZG9tYWluIjp0cnVlfQ=="><meta http-equiv="origin-trial" content="Amm8/NmvvQfhwCib6I7ZsmUxiSCfOxWxHayJwyU1r3gRIItzr7bNQid6O8ZYaE1GSQTa69WwhPC9flq/oYkRBwsAAACCeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXN5bmRpY2F0aW9uLmNvbTo0NDMiLCJmZWF0dXJlIjoiV2ViVmlld1hSZXF1ZXN0ZWRXaXRoRGVwcmVjYXRpb24iLCJleHBpcnkiOjE3NTgwNjcxOTksImlzU3ViZG9tYWluIjp0cnVlfQ=="><meta http-equiv="origin-trial" content="A9uiHDzQFAhqALUhTgTYJcz9XrGH2y0/9AORwCSapUO/f7Uh7ysIzyszNkuWDLqNYg8446Uj48XIstBW1qv/wAQAAACNeyJvcmlnaW4iOiJodHRwczovL2RvdWJsZWNsaWNrLm5ldDo0NDMiLCJmZWF0dXJlIjoiRmxlZGdlQmlkZGluZ0FuZEF1Y3Rpb25TZXJ2ZXIiLCJleHBpcnkiOjE3Mjc4MjcxOTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"><meta http-equiv="origin-trial" content="A9R+gkZL3TWq+Z7RJ2L0c7ZN7FZD5z4mHmVvjrPitg/EMz9P3j5d3W7Vw5ZR9jtJGmWKltM4BO3smNzpCgwYuwwAAACTeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXN5bmRpY2F0aW9uLmNvbTo0NDMiLCJmZWF0dXJlIjoiRmxlZGdlQmlkZGluZ0FuZEF1Y3Rpb25TZXJ2ZXIiLCJleHBpcnkiOjE3Mjc4MjcxOTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"></head>
<body>
<div class="navbar section" id="navbar"><div class="widget Navbar" data-version="1" id="Navbar1"><script src="https://apis.google.com/_/scs/abc-static/_/js/k=gapi.lb.en.pGGAptgAK4s.O/m=gapi_iframes,gapi_iframes_style_bubble/rt=j/sv=1/d=1/ed=1/am=AAAg/rs=AHpOoo-Cic-4VdRMZ7mFCYOA3wzpF7O-6g/cb=gapi.loaded_0?le=scs" async=""></script><script type="text/javascript">
    function setAttributeOnload(object, attribute, val) {
      if(window.addEventListener) {
        window.addEventListener('load',
          function(){ object[attribute] = val; }, false);
      } else {
        window.attachEvent('onload', function(){ object[attribute] = val; });
      }
    }
  </script>
<div id="navbar-iframe-container"><iframe ng-non-bindable="" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="" tabindex="0" vspace="0" width="100%" id="navbar-iframe" name="navbar-iframe" src="https://draft.blogger.com/navbar.g?targetBlogID=5417613544042855153&amp;blogName=CUDA+Musing&amp;publishMode=PUBLISH_MODE_BLOGSPOT&amp;navbarType=BLUE&amp;layoutType=LAYOUTS&amp;searchRoot=https://cudamusing.blogspot.com/search&amp;blogLocale=en&amp;v=2&amp;homepageUrl=http://cudamusing.blogspot.com/&amp;vt=-7918623084262684314&amp;usegapi=1&amp;jsh=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.lb.en.pGGAptgAK4s.O%2Fam%3DAAAg%2Fd%3D1%2Frs%3DAHpOoo-Cic-4VdRMZ7mFCYOA3wzpF7O-6g%2Fm%3D__features__#id=navbar-iframe&amp;_gfid=navbar-iframe&amp;parent=http%3A%2F%2Fcudamusing.blogspot.com&amp;pfname=&amp;rpctoken=28507742"></iframe></div>
<script type="text/javascript" src="https://apis.google.com/js/platform.js" gapi_processed="true"></script>
<script type="text/javascript">
      gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() {
        if (gapi.iframes && gapi.iframes.getContext) {
          gapi.iframes.getContext().openChild({
              url: 'https://draft.blogger.com/navbar.g?targetBlogID\x3d5417613544042855153\x26blogName\x3dCUDA+Musing\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dLAYOUTS\x26searchRoot\x3dhttps://cudamusing.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://cudamusing.blogspot.com/\x26vt\x3d-7918623084262684314',
              where: document.getElementById("navbar-iframe-container"),
              id: "navbar-iframe"
          });
        }
      });
    </script><script type="text/javascript">
(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//pagead2.googlesyndication.com/pagead/js/google_top_exp.js';
var head = document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(script);
}})();
</script>
</div></div>
<div id="outer-wrapper"><div id="wrap2">
<!-- skip links for text browsers -->
<span id="skiplinks" style="display:none;">
<a href="#main">skip to main </a> |
      <a href="#sidebar">skip to sidebar</a>
</span>
<div id="header-wrapper">
<div class="header section" id="header"><div class="widget Header" data-version="1" id="Header1">
<div id="header-inner">
<div class="titlewrapper">
<h1 class="title">
CUDA Musing
</h1>
</div>
<div class="descriptionwrapper">
<p class="description"><span>Random collection of CUDA examples, tricks and suggestions.</span></p>
</div>
</div>
</div></div>
</div>
<div id="content-wrapper">
<div id="crosscol-wrapper" style="text-align:center">
<div class="crosscol no-items section" id="crosscol"></div>
</div>
<div id="main-wrapper">
<div class="main section" id="main"><div class="widget Blog" data-version="1" id="Blog1">
<div class="blog-posts hfeed">

          <div class="date-outer">
        
<h2 class="date-header"><span>Friday, June 17, 2016</span></h2>

          <div class="date-posts">
        
<div class="post-outer">
<div class="post hentry uncustomized-post-template" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<meta content="5417613544042855153" itemprop="blogId">
<meta content="5233873217007078838" itemprop="postId">
<a name="5233873217007078838"></a>
<h3 class="post-title entry-title" itemprop="name">
<a href="http://cudamusing.blogspot.com/2016/06/tensorflow-08-on-jetson-tk1.html">TensorFlow 0.8 on Jetson TK1</a>
</h3>
<div class="post-header">
<div class="post-header-line-1"></div>
</div>
<div class="post-body entry-content" id="post-body-5233873217007078838" itemprop="description articleBody">
<div style="text-align: justify;">
This post gives updated instructions on how to build TensorFlow 0.8 on Jetson TK1 now that NVIDIA has released a new compiler that can handle the variadic templates without compiler internal errors.</div>
<br>
If you just want to try to install the whl file, this is &nbsp;a direct link, &nbsp;<a href="https://drive.google.com/file/d/0B1uGKNpQ7xNqa2RRYlMtZXZ6WVk/view?usp=sharing" target="_blank">tensorflow-0.8.0-cp27-none-linux_armv7l.whl</a><br>
<br>
I am going to use the same approach highlighted in the previous post, basically use the CUDA runtime 6.5 and CUDDN v2 but compile the code with the newer 7.0 compiler.<br>
<div>
<br></div>
<br>
<b>Install the 7.0.76 compiler:</b><br>
<br>
Befo<span style="font-family: inherit;">re starting, you</span> will need to download the new compiler. NVIDIA does not make your life easy in finding the link (they would like you to use Jetpack, but I don't like to reformat a working system if not absolutely needed) but you can download the .deb package directly on your Jetson with:<br>
<div style="line-height: normal; min-height: 14px;">
<br></div>
<br>
<br>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">wget http://developer.download.nvidia.com/embedded/L4T/r24_Release_v1.0/CUDA/cuda-repo-l4t-7-0-local_7.0-76_armhf.deb</span></div>
<br>
Now we can install it as usual:<br>
<br>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">sudo dpkg -i cuda-repo-l4t-7-0-local_7.0-76_armhf.deb&nbsp;</span></div>
<div style="color: #323333; line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; letter-spacing: 0.0px;">sudo apt-get update</span></div>
<div style="line-height: normal; min-height: 14px;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;"><span style="color: #323333; letter-spacing: 0px;">sudo apt-get install cuda-toolkit-7-0</span><span style="letter-spacing: 0.0px;"></span></span></div>
<div style="line-height: normal; min-height: 14px;">
<span style="color: #323333; letter-spacing: 0px;"><br></span></div>
<div style="line-height: normal; min-height: 14px;">
At this point we need to restore the standard 6.5 toolchain as the default one (we just&nbsp;want the 7.0 compiler to generate the object files), since the current driver on the Jetson TK1will only work with the 6.5 runtime. Go to the /usr/local directory and remove the cuda symlink to cuda-7.0 and make a new one for 6.5:&nbsp;</div>
<div style="line-height: normal; min-height: 14px;">
<br></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">ubuntu@tegra-ubuntu:/usr/local$ sudo rm cuda</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">ubuntu@tegra-ubuntu:/usr/local$ sudo ln -s cuda-6.5/ cuda</span></div>
<div style="line-height: normal; min-height: 14px;">
<br></div>
<div style="line-height: normal; min-height: 14px;">
<span style="font-family: inherit; font-size: small;">You should see this output:</span><br>
<span style="font-family: inherit; font-size: small;"><br></span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">ubuntu@tegra-ubuntu:~$ nvcc -V</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">nvcc: NVIDIA (R) Cuda compiler driver</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">Copyright (c) 2005-2014 NVIDIA Corporation</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">Built on Fri_Dec_12_11:12:07_CST_2014</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">Cuda compilation tools, release 6.5, V6.5.35</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;"><br></span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">ubuntu@tegra-ubuntu:~$ /usr/local/cuda-7.0/bin/nvcc -V</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">nvcc: NVIDIA (R) Cuda compiler driver</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">Copyright (c) 2005-2015 NVIDIA Corporation</span></div>
<div style="line-height: normal;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">Built on Mon_Feb_22_15:38:26_CST_2016</span></div>
<div style="line-height: normal; min-height: 14px;">
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: 10px;">Cuda compilation tools, release 7.0, V7.0.74</span></div>
<div>
<br></div>
<div>
<b>Install protobuf and Bazel:</b></div>
<div>
For protobuf you can follow the instruction from the previous blog post ( the only change is the location of protobuf-java-3.0.0-beta-x.jar , now in the java/core/target subdirectory).</div>
<div>
Also for Bazel the procedure is similar, the only change required is the version, TF0.8 requires Bazel 0.1.4 so after cloning bazel, you will need to use the proper tag:</div>
<div>
<br></div>
<div>
<div>
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: xx-small;">$ git clone https://github.com/bazelbuild/bazel.git</span></div>
<div>
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: xx-small;">$ cd bazel</span></div>
<div>
<span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: xx-small;">$ git checkout tags/0.1.4</span></div>
</div>
<div>
<div style="line-height: normal;">
<div style="font-family: monaco;">
<br></div>
<div style="font-family: monaco;">
<b style="font-family: -webkit-standard;">Install TensorFlow 0.8:</b></div>
The first thing to do it is to check out the source code and select the proper version:<br>
<br>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
$ cd tensorflow</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
$ git checkout r0.8</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
<br></div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
<br></div>
</div>
</div>
<div>
<div style="color: #333333; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;">TensorFlow is expecting a 64bit system, w</span><span style="letter-spacing: 0px;">e will need to change all the reference from lib64 to lib. We can find all the files with the strings and apply all the changes with these commands:</span></div>
<div style="color: #333333; font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #333333; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0px;">$ cd tensorflow</span></div>
<div style="background-color: #ebebeb; color: #333333; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0px;">$ grep -Rl "lib64"| xargs sed -i 's/lib64/lib/g'</span></div>
<div style="color: #333333; font-family: Georgia, serif; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0px;"><b></b></span><br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;">TensorFlow officially supports Cuda devices with 3.5 and 5.2 compute capabilities. We want to target a gpu with compute capabilities 3.2.&nbsp;</span></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;">This can be done through TensorFlow unofficial settings with "configure" via the TF_UNOFFICIAL_SETTING variable.</span></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;">When prompted, specify that you only want a 3.2 compute capability device.</span></div>
</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;"><br></span></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;"><br></span></div>
<div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
ubuntu@tegra-ubuntu:~/tensorflow$ TF_UNOFFICIAL_SETTING=1 ./configure</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please specify the location of python. [Default is /usr/bin/python]:&nbsp;</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Do you wish to build TensorFlow with GPU support? [y/N] y</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
GPU support will be enabled for TensorFlow</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]:&nbsp;</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]:&nbsp;</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please specify the location where CUDA&nbsp; toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:&nbsp;</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please specify the Cudnn version you want to use. [Leave empty to use system default]:&nbsp;</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please specify the location where cuDNN&nbsp; library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:&nbsp;</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please specify a list of comma-separated Cuda compute capabilities you want to build with.</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Please note that each additional compute capability significantly increases your build time and binary size.</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
[Default is: "3.5,5.2"]: 3.2</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Setting up Cuda include</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Setting up Cuda lib</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Setting up Cuda bin</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Setting up Cuda nvvm</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
Configuration finished</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
Now that the initial set up is done, it is time to change the compiler used by Bazel.</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
ubuntu@tegra-ubuntu:~/tensorflow$ cd third_party/gpus/cuda/</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
ubuntu@tegra-ubuntu:~/tensorflow/third_party/gpus/cuda$ rm -fr bin nvvm</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
ubuntu@tegra-ubuntu:~/tensorflow/third_party/gpus/cuda$ cp -R /usr/local/cuda-7.0/bin/ bin</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
ubuntu@tegra-ubuntu:~/tensorflow/third_party/gpus/cuda$ cp -R /usr/local/cuda-7.0/nvvm/ nvvm</div>
</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
Before starting the build ( that is going to take a very long time), we will need to modify few files.</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<div style="color: #323333; font-family: Georgia; line-height: normal;">
<span style="letter-spacing: 0.0px;"><b>tensorflow/core/kernels/conv_ops_gpu_2.cu.cc:</b></span></div>
<div style="color: #323333; font-family: Georgia; line-height: normal;">
<span style="letter-spacing: 0.0px;">&nbsp;To avoid double instantiation, guard the second functor for InflatePadAndShuffle with:</span></div>
<div style="color: #5330e1; font-family: Monaco; font-size: 10px; line-height: normal;">
/* On ARMv7 Eigen::DenseIndex is typedefed to int */</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#ifndef __arm__</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
<span style="color: #34bd26;">template</span> <span style="color: #34bd26;">struct</span> functor::InflatePadAndShuffle<gpudevice span="" style="color: #34bd26;">float</gpudevice></div>
</div>
</div>
, <span style="color: #c33720;">4</span>,
<br>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Eigen::DenseIndex&gt;;</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#endif<span style="color: #323333; font-family: &quot;georgia&quot;; font-size: 16px; letter-spacing: 0px; line-height: normal;">&nbsp;</span></div>
<div style="color: #323333; line-height: normal;">
<span style="letter-spacing: 0.0px;"><b>tensorflow/core/kernels/conv_ops_gpu_3.cu.cc:</b></span></div>
<div style="color: #323333; font-family: Georgia; line-height: normal;">
<span style="letter-spacing: 0.0px;">&nbsp;To avoid double instantiation, guard the second functor&nbsp; for ShuffleAndReverse with:</span></div>
<div style="color: #5330e1; font-family: Monaco; font-size: 10px; line-height: normal;">
/* On ARMv7 Eigen::DenseIndex is typedefed to int */</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#ifndef __arm__</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
<span style="color: #34bd26;">template</span> <span style="color: #34bd26;">struct</span> functor::ShuffleAndReverse<gpudevice span="" style="color: #34bd26;">float</gpudevice></div>
, <span style="color: #c33720;">4</span>,
<br>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Eigen::DenseIndex&gt;;</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#endif</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<div style="color: #323333; line-height: normal;">
<span style="letter-spacing: 0.0px;"><b>tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:</b></span></div>
<div style="color: #323333; font-family: Georgia; line-height: normal;">
<span style="letter-spacing: 0.0px;">&nbsp;ARMv7 has no numa_node file. It should return 0 not -1, otherwise TensorFlow will crash at runtime. You can use the modification from the previous post or the following code:</span></div>
<div style="color: #323333; font-family: Georgia; line-height: normal;">
<span style="letter-spacing: 0.0px;"><br></span></div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
<span style="color: #34bd26;">static</span> <span style="color: #34bd26;">int</span> TryToReadNumaNode(<span style="color: #34bd26;">const</span> string &amp;pci_bus_id, <span style="color: #34bd26;">int</span> device_ordinal) {</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#ifdef __arm__</div>
<div style="color: #c33720; font-family: Monaco; font-size: 10px; line-height: normal;">
<span style="color: black;">&nbsp; LOG(INFO) &lt;&lt; </span>"ARMV7 does not support NUMA - returning NUMA node zero"<span style="color: black;">;</span></div>
<div style="color: #ce7924; font-family: Monaco; font-size: 10px; line-height: normal;">
<span style="color: black;">&nbsp; </span>return<span style="color: black;"> </span><span style="color: #c33720;">0</span><span style="color: black;">;</span></div>
<div style="color: #323333; font-family: Georgia; line-height: normal;">
</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#else</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp;........</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp;&nbsp;<span style="color: #ce7924;">return</span> kUnknownNumaNode;</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#endif</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
}</div>
</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div>
<b style="color: #323333; font-family: Georgia; font-size: 16px;">tensorflow/core/</b><span style="color: #323333; font-family: &quot;georgia&quot;;"><b>common_runtime/gpu/process_state.cc:</b></span></div>
<div>
<span style="color: #323333; font-family: &quot;georgia&quot;;">this &nbsp;is a new memory allocator, that is going to cause a floating point exception unless you change the following code:</span></div>
<div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
<span style="color: #ce7924;"><br></span></div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
<span style="color: #ce7924;">if</span> (kCudaHostMemoryUseBFC) {</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp; &nbsp; &nbsp; allocator =</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#ifdef __arm__</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ce7924;">new</span> BFCAllocator(<span style="color: #ce7924;">new</span> CUDAHostAllocator(se), <span style="color: #c33720;">1LL</span> &lt;&lt; <span style="color: #c33720;">31</span>,</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c33720;">true</span> <span style="color: #5330e1;">/*allow_growth*/</span>, <span style="color: #c33720;">"cuda_host_bfc"</span> <span style="color: #5330e1;">/*name*/</span>);</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#else</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ce7924;">new</span> BFCAllocator(<span style="color: #ce7924;">new</span> CUDAHostAllocator(se), <span style="color: #c33720;">1LL</span> &lt;&lt; <span style="color: #c33720;">36</span> <span style="color: #5330e1;">/*64GB max*/</span>,</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c33720;">true</span> <span style="color: #5330e1;">/*allow_growth*/</span>, <span style="color: #c33720;">"cuda_host_bfc"</span> <span style="color: #5330e1;">/*name*/</span>);</div>
<div style="color: #d53bd3; font-family: Monaco; font-size: 10px; line-height: normal;">
#endif</div>
<div style="font-family: Monaco; font-size: 10px; line-height: normal;">
&nbsp; &nbsp; } <span style="color: #ce7924;">else</span> {</div>
</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
We are now ready to build. The only thing left to do is to remove the check to disable the use of variadic templates in Eigen. I have not found a clean way to do it (someone with better Bezel skills may have a better idea). My solution is to &nbsp;start the build and then wait for the first failure:</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="background-color: #fafafa; color: #36474f; font-family: &quot;helvetica neue&quot;;">$bazel build -c opt --local_resources 2048,0.5,1.0 --verbose_failures -s --config=cuda //tensorflow/cc:tutorials_example_trainer</span></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a;">
<span style="background-color: white; color: #333333; font-family: &quot;georgia&quot; , serif; text-align: justify;">If on your first compile of tensorflow you get the following error:</span><br>
<br style="color: #333333; font-family: Georgia, serif; text-align: justify;">
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; text-align: justify;">ERROR: /home/ubuntu/tensorflow/tensorflow/cc/BUILD:61:1: error loading package 'tensorflow/core': Extension file not found. Unable to load package for '//google/protobuf:protobuf.bzl': BUILD file not found on package path and referenced by '//tensorflow/cc:tutorials_example_trainer'.</span><br style="color: #333333; text-align: justify;"><br style="color: #333333; text-align: justify;"><span style="background-color: white; color: #333333; text-align: justify;">You need to init update in the tensorflow repository to get the google/protobuf clone using:</span><br style="color: #333333; text-align: justify;"><br style="color: #333333; text-align: justify;"><span style="background-color: white; color: #333333; text-align: justify;">git submodule update --init&nbsp;</span></span></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br>
At this point, I can edit the file Macros.h in Eigen.</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
This file is located in the .cache directory:</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
ubuntu@tegra-ubuntu:~/.cache$ find . -name Macros.h -print</div>
<div style="color: #00364a; font-family: Monaco; font-size: 10px; line-height: normal;">
./bazel/_bazel_ubuntu/ad1e09741bb4109fbc70ef8216b59ee2/external/eigen_archive/eigen-eigen-3f653ace7d28/Eigen/src/Core/util/Macros.h</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
The nvcc check needs to be eliminated:</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<div>
<div class="udiff-line addition" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">
<pre class="source" style="background-color: #ddffdd; font-family: Consolas, Menlo, 'Liberation Mono', Courier, monospace; font-size: 12px; height: 18px; line-height: 18px; padding: 0px 0px 0px 72px;">-#if !defined(__NVCC__) || !defined(EIGEN_ARCH_ARM_OR_ARM64)</pre>
</div>
<div class="udiff-line common" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">
<div class="gutter" id="LEigen/src/Core/util/Macros.hF357T360" style="background-color: whitesmoke; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; height: 18px; left: 1px; margin: 0px; padding: 0px; position: absolute;">
<a class="line-numbers" data-fnum="357" data-tnum="360" href="https://bitbucket.org/eigen/eigen/commits/d0950ac79c0404047379eb5a927a176dbb9d12a5#LEigen/src/Core/util/Macros.hF357T360" style="-webkit-user-select: none; color: #333333; float: right; font-family: Consolas, Menlo, 'Liberation Mono', Courier, monospace; font-size: 12px; height: 18px; line-height: 18px; margin-top: 0px; text-decoration: none; width: 70px;"></a></div>
<pre class="source" style="font-family: Consolas, Menlo, 'Liberation Mono', Courier, monospace; font-size: 12px; height: 18px; line-height: 18px; padding: 0px 0px 0px 72px;"> #define EIGEN_HAS_VARIADIC_TEMPLATES 1</pre>
</div>
<div class="udiff-line common" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">
<div class="gutter" id="LEigen/src/Core/util/Macros.hF358T361" style="background-color: whitesmoke; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; height: 18px; left: 1px; margin: 0px; padding: 0px; position: absolute;">
<a class="line-numbers" data-fnum="358" data-tnum="361" href="https://bitbucket.org/eigen/eigen/commits/d0950ac79c0404047379eb5a927a176dbb9d12a5#LEigen/src/Core/util/Macros.hF358T361" style="-webkit-user-select: none; color: #333333; float: right; font-family: Consolas, Menlo, 'Liberation Mono', Courier, monospace; font-size: 12px; height: 18px; line-height: 18px; margin-top: 0px; text-decoration: none; width: 70px;"></a></div>
<pre class="source" style="font-family: Consolas, Menlo, 'Liberation Mono', Courier, monospace; font-size: 12px; height: 18px; line-height: 18px; padding: 0px 0px 0px 72px;"> #endif</pre>
</div>
<div class="udiff-line addition" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">
<div class="gutter" id="LEigen/src/Core/util/Macros.hT362" style="background-color: whitesmoke; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; height: 18px; left: 1px; margin: 0px; padding: 0px; position: absolute;">
<a class="line-numbers" data-tnum="362" href="https://bitbucket.org/eigen/eigen/commits/d0950ac79c0404047379eb5a927a176dbb9d12a5#LEigen/src/Core/util/Macros.hT362" style="-webkit-user-select: none; color: #333333; float: right; font-family: Consolas, Menlo, 'Liberation Mono', Courier, monospace; font-size: 12px; height: 18px; line-height: 18px; margin-top: 0px; text-decoration: none; width: 70px;"></a></div>
<pre class="source" style="background-color: #ddffdd; font-family: Consolas, Menlo, 'Liberation Mono', Courier, monospace; font-size: 12px; height: 18px; line-height: 18px; padding: 0px 0px 0px 72px;">-#endif</pre>
</div>
</div>
</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
We can now restart the build and it will go through.&nbsp;</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
After you are done, you can test it with:</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<br></div>
<div>
$ bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu<br>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;"><br></span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;">You should see a similar output:</span></div>
<div style="color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0px;"></span><br></div>
# Lots of output. This tutorial iteratively calculates the major eigenvalue of<br>
# a 2x2 matrix, on GPU. The last few lines look like this.<br>
000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]<br>
000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]<br>
000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]</div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;"><br></span></div>
<div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;">We are now ready to create the pip package and install it:</span></div>
# To build with GPU support:<br>
$ bazel build -c opt --local_resources 2048,0.5,1.0 --verbose_failures --config=cuda //tensorflow/tools/pip_package:build_pip_package<br>
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg<br>
# The name of the .whl file will depend on your platform.<br>
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.8.0-cp27-none-linux_armv7l.whl</div>
<div>
<br>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;">Congratulation, TensorFlow is now installed on your system.</span></div>
</div>
</div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;"><br></span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
Most of the tests are passing, but the image classification example is giving the wrong results. Now that the community can build it and play with it, someone can find the source of the error(s).</div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<br></div>
<div>
<span style="color: #36474f; font-family: &quot;helvetica&quot;; font-size: 16px;">I downloaded the python files from TensorFlow-Tutorial and they seem to work:</span></div>
<div>
<br></div>
<div>
git clone https://github.com/nlintz/TensorFlow-Tutorials.git</div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;"><br></span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0px;"><br></span></div>
<div style="clear: both;"></div>
</div>
<div class="post-footer">
<div class="post-footer-line post-footer-line-1">
<span class="post-author vcard">
Posted by
<span class="fn" itemprop="author" itemscope="itemscope" itemtype="http://schema.org/Person">
<meta content="https://draft.blogger.com/profile/06026735414532627847" itemprop="url">
<a class="g-profile" href="https://draft.blogger.com/profile/06026735414532627847" rel="author" title="author profile">
<span itemprop="name">Massimiliano</span>
</a>
</span>
</span>
<span class="post-timestamp">
at
<meta content="http://cudamusing.blogspot.com/2016/06/tensorflow-08-on-jetson-tk1.html" itemprop="url">
<a class="timestamp-link" href="http://cudamusing.blogspot.com/2016/06/tensorflow-08-on-jetson-tk1.html" rel="bookmark" title="permanent link"><abbr class="published" itemprop="datePublished" title="2016-06-17T11:59:00-07:00">11:59 AM</abbr></a>
</span>
<span class="post-comment-link">
<a class="comment-link" href="http://cudamusing.blogspot.com/2016/06/tensorflow-08-on-jetson-tk1.html#comment-form" onclick="">
16 comments:
  </a>
</span>
<span class="post-icons">
<span class="item-control blog-admin pid-1214496171">
<a href="https://draft.blogger.com/post-edit.g?blogID=5417613544042855153&amp;postID=5233873217007078838&amp;from=pencil" title="Edit Post">
<img alt="" class="icon-action" height="18" src="https://resources.blogblog.com/img/icon18_edit_allbkg.gif" width="18">
</a>
</span>
</span>
<div class="post-share-buttons goog-inline-block">
</div>
</div>
<div class="post-footer-line post-footer-line-2">
<span class="post-labels">
</span>
</div>
<div class="post-footer-line post-footer-line-3">
<span class="post-location">
</span>
</div>
</div>
</div>
</div>

          </div></div>
        

          <div class="date-outer">
        
<h2 class="date-header"><span>Friday, November 27, 2015</span></h2>

          <div class="date-posts">
        
<div class="post-outer">
<div class="post hentry uncustomized-post-template" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<meta content="5417613544042855153" itemprop="blogId">
<meta content="2768801506507736415" itemprop="postId">
<a name="2768801506507736415"></a>
<h3 class="post-title entry-title" itemprop="name">
<a href="http://cudamusing.blogspot.com/2015/11/building-tensorflow-for-jetson-tk1.html">Building TensorFlow for Jetson TK1</a>
</h3>
<div class="post-header">
<div class="post-header-line-1"></div>
</div>
<div class="post-body entry-content" id="post-body-2768801506507736415" itemprop="description articleBody">
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span style="font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;">Google recently released TensorFlow, an open source software library for numerical computation using data flow graphs.&nbsp;</span></span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<span style="font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="letter-spacing: 0px;">TensorFlow has a GPU &nbsp;backend built on CUDA, so I wanted to install it on a Jetson TK1. Even if the system did not meet the requirements ( CUDA 7.0 is not available and the GPU is a compute capability 3.2), I decided to give it a try anyway. &nbsp;This blog reports all the steps required to build TensorFlow from source, it is quite challenging but it can be done. Including all the prerequisites, the whole build will take several hours ( if you just want to try Tensorflow, you can download&nbsp;</span>the<span style="letter-spacing: 0px;">&nbsp;wheel file I generated and do a pip install. The&nbsp;</span>file is at&nbsp;https://drive.google.com/file/d/0B1uGKNpQ7xNqZ2pvSmc3SlZJS2c/view?usp=sharing )<span style="letter-spacing: 0px;">.</span><span style="font-size: 16px; letter-spacing: 0px;">&nbsp;</span></span><br>
<div style="font-size: 16px; min-height: 19px;">
<span style="font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="letter-spacing: 0.0px;"></span><br></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span style="font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;">TensorFlow is under active development and the coding is using a lot of advanced C++ features that really push the compiler, these instructions worked with the version available on 11/26 but new&nbsp;</span></span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span style="font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;">The first challenge is to build Bazel, another software developed at Google used as building system for TensorFlow. Bazel requires a protobuf version newer than the one presents in the Ubuntu 14.04 repos, so the first step will be to install protobuf 3 from source, since there are no prebuilt binary for ARM32.</span></span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 19px;">
<span style="letter-spacing: 0.0px;"><b>Java 8:</b></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">The first step is to install Java8, but this is quite simple since Oracle provides a package:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #f9f9f9; color: #323333; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo add-apt-repository ppa:webupd8team/java</span></div>
<div style="background-color: #f9f9f9; color: #323333; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo apt-get update</span></div>
<div style="background-color: #f9f9f9; color: #323333; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo apt-get install oracle-java8-installer</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 19px;">
<span style="letter-spacing: 0.0px;"><b>Protobuf:</b></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">In order to build protobuf and bazel, we will need several other packages. The exact list will &nbsp;depend on the status of your Jetson, &nbsp;but you will need at least these ones:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo apt-get install git zip unzip autoconf automake libtool curl zlib1g-dev &nbsp;</span></div>
<div style="font-size: 16px;">
<span style="font-family: &quot;helvetica neue&quot;; letter-spacing: 0px;"><br>
</span><span style="letter-spacing: 0.0px;">After downloading &nbsp;the latest source from github:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ git clone https://github.com/google/protobuf.git</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">you need to first generate the configuration file and then run make:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cd protobuf</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ ./autogen.sh&nbsp;</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ ./configure&nbsp;</span><span style="color: #323333; letter-spacing: 0.0px;">--prefix=/usr</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ make -j 4</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo make install</span></div>
<div style="font-size: 16px;">
<span style="font-family: &quot;helvetica neue&quot;; letter-spacing: 0px;"><br>
</span><span style="letter-spacing: 0.0px;">Protoc will be installed in /usr/lib and /usr/bin, this will be important when we run&nbsp;bazel since it tries to use a sandbox and will not find the libraries in /usr/local/lib.</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">You should see this output, if you have followed all the steps:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">ubuntu@tegra-ubuntu:~/protobuf$ protoc --version</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">libprotoc 3.0.0</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">We also need to build the java interface for protobuf, that will require Maven.</span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">Luckily maven is available from the repos, so we can just issue a:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo apt-get install maven</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">Go to the subdirectory java inside protobuf and type:</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$&nbsp;mvn package</span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">Once the build is completes, there will be &nbsp;a&nbsp;protobuf-java-3.0.0-beta-1.jar inside the target subdirectory.</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 19px;">
<span style="letter-spacing: 0.0px;"><b>Bazel:</b></span></div>
<div style="font-size: 19px; min-height: 23px;">
<span style="letter-spacing: 0.0px;"><b></b></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">We are now ready to tackle Bazel.</span></div>
<div style="background-color: #f9f9f9; color: #323333; font-size: 16px;">
<span style="letter-spacing: 0.0px;">The first step is to download the source code for Bazel ( using the 0.1.0 version, that it is known to work with Tensorflow).&nbsp;</span></div>
<div style="background-color: #f9f9f9; color: #323333; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ git clone https://github.com/bazelbuild/bazel.git</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cd bazel</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$git checkout tags/0.1.0</span></div>
<div style="background-color: #f9f9f9; font-family: Courier; font-size: 13px; min-height: 16px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Before compiling, we need to copy the protoc binary we just built as&nbsp;third_party/protobuf/protoc-linux-arm32.exe.</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We also need to copy the jar file from protobuf in the same directory. Bazel is expecting an alpha-3 version, but we have built a&nbsp; beta-1.</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">There is probably a better way of doing this, but just copying the file and rename it did the trick for me.</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cp /usr/bin/protoc &nbsp; third_party/protobuf/protoc-linux-arm32.exe</span></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cp ~/protobuf/java/target/protobuf-java-3.0.0-beta-1.jar&nbsp; third_party/protobuf/protobuf-java-3.0.0-alpha-3.jar</span></div>
<div style="background-color: #f9f9f9; color: #323333; font-size: 13px; min-height: 16px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We are now ready to compile bazel.&nbsp;</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #eeeeee; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ ./compile.sh</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">At the end of the compilation, the bazel binary will be in the output directory. You can add this directory</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">to your path or copy the binary in /usr/local/bin</span></div>
<div style="background-color: #f9f9f9; color: #323333; font-size: 13px; min-height: 16px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 19px;">
<span style="letter-spacing: 0.0px;"><b>TensorFlow</b></span></div>
<div style="font-size: 19px; min-height: 23px;">
<span style="letter-spacing: 0.0px;"><b></b></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We are now ready to tackle the TensorFlow build for GPU. Just be sure to have CUDA 6.5 and CUDNN 6.5 installed on your Jetson TK1.&nbsp;</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">You will also need some files from the CUDA 7.0 package ( cuda-repo-l4t-r23.1-7-0-local_7.0-71_armhf.deb ) that you can download from</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">the NVIDIA web site ( it is the one for Jetson TX1).</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">While Jetson TK1 cannot run the 7.0 runtime, since the driver shipped with the system does not support it, it is still &nbsp;possible to run the CUDA 7.0 compiler. We need the 7.0 compiler because some of the TensorFlow source files will generate an internal compiler error with the 6.5 nvcc.&nbsp;</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">All the libraries and runtime will be the standard 6.5 ones.&nbsp;</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">On my system I have also enabled some swap space. You can plug a USB memory stick,&nbsp; create a swap file and mount it with</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo mkswap /dev/sda</span></div>
<div style="background-color: #ebebeb; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo swapon /dev/sda&nbsp;</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">The first step to build TensorFlow is to clone the github repository:</span></div>
<div style="background-color: #ebebeb; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ git clone -recurse-submodules https://github.com/tensorflow/tensorflow&nbsp;</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">and install other dependencies:</span></div>
<div style="background-color: #ebebeb; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo apt-get install python-numpy swig python-dev</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">TensorFlow is expecting a 64bit system and has a bunch of library paths and libraries hard-coded in the files.</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Before starting the installation, we will need to modify several files.&nbsp; We will need to change all the reference from lib64 to lib and change the 7.0 libraries to 6.5.&nbsp; We can find all the files with the strings and apply all the changes with these commands:</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cd tensorflow</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ grep -Rl "lib64"| xargs sed -i 's/lib64/lib/g'</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ grep -Rl "so.7.0"| xargs sed -i 's/so\.7\.0/so\.6\.5/g'</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"><b></b></span><br></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">TensorFlow officially supports Cuda devices with 3.5 and 5.2 compute capabilities. We want to target a gpu with compute capabilities 3.2.&nbsp;</span></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">This can be done through TensorFlow unofficial settings with "configure" via the TF_UNOFFICIAL_SETTING variable.</span></div>
<div style="color: #00364a; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">When prompted, specify that you only want a 3.2 compute capability device.</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ TF_UNOFFICIAL_SETTING=1 ./configure</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;"># Same as the official settings above</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">WARNING: You are configuring unofficial settings in TensorFlow. Because some</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">external libraries are not backward compatible, these settings are largely</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">untested and unsupported.</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Please specify a list of comma-separated Cuda compute capabilities you want to</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">build with. You can find the compute capability of your device at:</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">https://developer.nvidia.com/cuda-gpus.</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Please note that each additional compute capability significantly increases</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">your build time and binary size. [Default is: "3.5,5.2"]: 3.2</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Setting up Cuda include</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Setting up Cuda lib</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Setting up Cuda bin</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Setting up Cuda nvvm</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Configuration finished</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">After the configure, bazel has copied or symlinked all the binaries and libraries needed for the build in&nbsp; the third_party/gpus/cuda subdirectory .</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">It is now time to replace the cuda compiler with the one from the 7.0 toolchain.</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We want to extract (not install) the files from the &nbsp;cuda-repo-l4t-r23.1-7-0-local_7.0-71_armhf.deb package with the following commands:</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ dpkg -x cuda-repo-l4t-r23.1-7-0-local_7.0-71_armhf.deb /tmp/cuda_repo</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cd /tmp/cuda_repo/var/cuda-repo-7-0-local</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ dpkg -x cuda-core-7-0_7.0-71_armhf.deb /tmp/cuda7.0</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ rm -fr /tmp/cuda_repo</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cd ~tensorflow/third_party/gpus/cuda</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ rm -fr bin nvvm</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cp -R&nbsp; /tmp/cuda7.0/usr/local/cuda-7.0/bin bin</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ cp -R /tmp/cuda7.0/usr/local/cuda-7.0/nvvm nvvm</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ rm -fr /tmp/cuda7.0</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">At this point, bazel is ready to use the 7.0 toolchain to compile Tensorflow.</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We still need to add the ARM target to the build.&nbsp;</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">This can be done adding the following lines to the </span><span style="letter-spacing: 0.0px; text-decoration: underline;">third_party/gpus/crosstool/CROSSTOOL file:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">default_toolchain {</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; cpu: "arm"</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; toolchain_identifier: "local_linux"</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Before starting the build, we need to edit few files to avoid compiler crashes and avoid double instantiations&nbsp;</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">(on ARM v7, Eigen::DenseIndex is&nbsp; typedefed to int):</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">third_party/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">tensorflow/core/kernels/conv_ops_gpu_2.cu.cc</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">tensorflow/core/kernels/conv_ops_gpu_3.cu.cc</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">tensorflow/stream_executor/cuda/cuda_gpu_executor.cc</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">tensorflow/core/kernels/adjust_contrast_op.h</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;"><b>third_party/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h: &nbsp;</b></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>the compiler is crashing when evaluating the code inside the ifdef at line 312. We can just take the alternative path.</span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Change line 312 to something like:</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#ifdef EIGEN_HAS_VARIADIC_TEMPLATES_TK1</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><b>tensorflow/core/kernels/conv_ops_gpu_2.cu.cc:</b></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>To avoid double instantiation, guard the second functor for InflateAnsShuffle with:</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">/* On ARMv7 Eigen::DenseIndex is typedefed to int */</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#ifndef __arm__</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">template struct functor::InflatePadAndShuffle<gpudevice 4="" float="" span=""></gpudevice></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Eigen::DenseIndex&gt;;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#endif</span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>We also need to comment the tensor.h include ( will crash the compiler)</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">//#include "tensorflow/core/public/tensor.h"</span></div>
<div style="font-size: 16px; min-height: 19px;">
<br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;"><b>tensorflow/core/kernels/conv_ops_gpu_3.cu.cc:</b></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>To avoid double instantiation, guard the second functor&nbsp; for ShuffleAndReverse with:</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">/* On ARMv7 Eigen::DenseIndex is typedefed to int */</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#ifndef __arm__</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">template struct functor::ShuffleAndReverse<gpudevice 4="" float="" span=""></gpudevice></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Eigen::DenseIndex&gt;;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#endif</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;"><b>tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:</b></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ARMv7 has no numa_node file. It should return 0 not -1, otherwise TensorFlow will crash at runtime:</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">FILE *file = fopen(filename.c_str(), "r");</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; if (file == nullptr) {</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; LOG(ERROR) &lt;&lt; "could not open file to read NUMA node: " &lt;&lt; filename;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#ifdef __arm__</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; // There is no numa_node on Jetson TK1</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; return 0;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#else</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; return kUnknownNumaNode;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#endif</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;"><b>tensorflow/core/kernels/adjust_contrast_op.h:</b></span></div>
<div style="font-size: 16px;">
<span style="letter-spacing: 0.0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>The compiler is crashing on some initializations, we need to rewrite them in a simpler way:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">//MF Eigen::array<int 4=""> scalar_broadcast{{batch, height, width, channels}};</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; Eigen::array<int 4=""> scalar_broadcast;</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; scalar_broadcast[0] = batch;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; scalar_broadcast[1] = height;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; scalar_broadcast[2] = width;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; scalar_broadcast[3] = channels;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#if !defined(EIGEN_HAS_INDEX_LIST)</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">//MF Eigen::array<int 2=""> reduction_axis{{1, 2}};</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">//MF Eigen::array<int 4=""> scalar{{1, 1, 1, 1}};</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">//MF Eigen::array<int 4=""> broadcast_dims{{1, height, width, 1}};</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">//MF Eigen::Tensor<int 4="">::Dimensions reshape_dims{{batch, 1, 1, channels}};</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp;&nbsp; &nbsp; Eigen::array<int 2=""> reduction_axis;</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; reduction_axis[0]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; reduction_axis[1]=2;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp;&nbsp; &nbsp; Eigen::array<int 4=""> scalar;</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; scalar[0]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; scalar[1]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; scalar[2]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; scalar[3]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp;&nbsp; &nbsp; Eigen::array<int 4=""> broadcast_dims;</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; broadcast_dims[0]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; broadcast_dims[1]=height;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; broadcast_dims[2]=width;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; broadcast_dims[3]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp;&nbsp; &nbsp; Eigen::Tensor<int 4="">::Dimensions reshape_dims;</int></span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; reshape_dims[0]=batch;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; reshape_dims[1]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; reshape_dims[2]=1;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">&nbsp; &nbsp; &nbsp; reshape_dims[3]=channels;</span></div>
<div style="background-color: #ebebeb; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">#else</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">The source code is now ready. Jeston TK1 has only 2GB of memory and bazel will try to compile several files at the same time.</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We want to avoid this, so we will pass a local_resource flag that will use only 2GB and half core (don't ask, if you specify one it will still try</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">to compile two files at the same time). This build will take a long time:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #fafafa; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$bazel build -c opt --local_resources 2048,0.5,1.0 --verbose_failures --config=cuda //tensorflow/cc:tutorials_example_trainer</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">If you get some failures during the build, keep trying, bazel scheduling seems to be non-deterministic and the Tensorflow code is really stressing the</span></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">compiler.</span></div>
<div style="font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Once the build is completed, we can test the code:</span></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu</span></div>
<div style="color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">You should see a similar output:</span></div>
<div style="color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;"># Lots of output. This tutorial iteratively calculates the major eigenvalue of</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;"># a 2x2 matrix, on GPU. The last few lines look like this.</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]</span></div>
<div style="color: #36474f; font-size: 14px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-size: 14px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We are now ready to create the pip package and install it:</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;"># To build with GPU support:</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ bazel build -c opt --local_resources 2048,0.5,1.0 --verbose_failures --config=cuda //tensorflow/tools/pip_package:build_pip_package</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;"># The name of the .whl file will depend on your platform.</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.5.0-cp27-none-linux_armv7l.whl</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Congratulation, TensorFlow is now installed on your system.</span></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">We can also try a more interesting example of image classification:</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">bazel build -c opt --local_resources 2048,0.5,1.0 --verbose_failures --config=cuda //tensorflow/examples/label_image/...</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="background-color: #f7f7f7; color: #323333; font-family: Consolas; font-size: 14px;">
<span style="letter-spacing: 0.0px;">$ wget https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip -O tensorflow/examples/label_image/data/inception5h.zip</span></div>
<div style="background-color: #f7f7f7; color: #323333; font-family: Consolas; font-size: 14px;">
<span style="letter-spacing: 0.0px;">$ unzip tensorflow/examples/label_image/data/inception5h.zip -d tensorflow/examples/label_image/data/</span></div>
<div style="background-color: #f7f7f7; color: #323333; font-family: Consolas; font-size: 14px;">
<span style="letter-spacing: 0.0px;">$ mv tensorflow/examples/label_image/data/tensorflow_inception_graph.pb tensorflow/examples/label_image/data/googlenet_graph.pb</span></div>
<div style="background-color: #f7f7f7; color: #323333; font-family: Consolas; font-size: 14px;">
<span style="letter-spacing: 0.0px;">$ mv tensorflow/examples/label_image/data/imagenet_comp_graph_label_strings.txt tensorflow/examples/label_image/data/googlenet_labels.txt&nbsp;</span></div>
<div style="color: #36474f; font-size: 14px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="color: #36474f; font-family: Helvetica; font-size: 16px;">
<span style="letter-spacing: 0.0px;">And run it with:</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">$ bazel-bin/tensorflow/examples/label_image/label_image</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 1</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:890] could not open file to read NUMA node: /sys/bus/pci/devices/0000:00:00.0/numa_node</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_init.cc:103] Found device 0 with properties:&nbsp;</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">name: GK20A</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">major: 3 minor: 2 memoryClockRate (GHz) 0.852</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">pciBusID 0000:00:00.0</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Total memory: 1.85GiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">Free memory: 218.46MiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_init.cc:127] DMA: 0&nbsp;</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_init.cc:137] 0: &nbsp; Y&nbsp;</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_device.cc:702] Creating TensorFlow device (/gpu:0) -&gt; (device: 0, name: GK20A, pci bus id: 0000:00:00.0)</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:42] Allocating 18.46MiB bytes.</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:52] GPU 0 memory begins at 0xa45ea000 extends to 0xa585f000</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 1.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 2.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 4.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 8.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 16.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 32.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 64.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 128.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 256.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 512.0KiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 1.00MiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 2.00MiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 4.00MiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 8.00MiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 16.00MiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:66] Creating bin of max chunk size 32.00MiB</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/direct_session.cc:60] Direct session inter op parallelism threads: 1</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_device.cc:702] Creating TensorFlow device (/gpu:0) -&gt; (device: 0, name: GK20A, pci bus id: 0000:00:00.0)</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/core/common_runtime/gpu/gpu_device.cc:702] Creating TensorFlow device (/gpu:0) -&gt; (device: 0, name: GK20A, pci bus id: 0000:00:00.0)</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/examples/label_image/main.cc:221] military uniform (866): 0.902268</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/examples/label_image/main.cc:221] bow tie (817): 0.05407</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/examples/label_image/main.cc:221] suit (794): 0.0113196</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/examples/label_image/main.cc:221] bulletproof vest (833): 0.0100269</span></div>
<div style="background-color: #ebebeb; color: #36474f; font-family: 'Helvetica Neue'; font-size: 16px;">
<span style="letter-spacing: 0.0px;">I tensorflow/examples/label_image/main.cc:221] bearskin (849): 0.00649747</span></div>
<div style="color: #36474f; font-size: 14px; min-height: 18px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<br>
<div style="font-size: 16px; min-height: 19px;">
<span style="letter-spacing: 0.0px;"></span><br></div>
<div style="clear: both;"></div>
</div>
<div class="post-footer">
<div class="post-footer-line post-footer-line-1">
<span class="post-author vcard">
Posted by
<span class="fn" itemprop="author" itemscope="itemscope" itemtype="http://schema.org/Person">
<meta content="https://draft.blogger.com/profile/06026735414532627847" itemprop="url">
<a class="g-profile" href="https://draft.blogger.com/profile/06026735414532627847" rel="author" title="author profile">
<span itemprop="name">Massimiliano</span>
</a>
</span>
</span>
<span class="post-timestamp">
at
<meta content="http://cudamusing.blogspot.com/2015/11/building-tensorflow-for-jetson-tk1.html" itemprop="url">
<a class="timestamp-link" href="http://cudamusing.blogspot.com/2015/11/building-tensorflow-for-jetson-tk1.html" rel="bookmark" title="permanent link"><abbr class="published" itemprop="datePublished" title="2015-11-27T13:09:00-08:00">1:09 PM</abbr></a>
</span>
<span class="post-comment-link">
<a class="comment-link" href="http://cudamusing.blogspot.com/2015/11/building-tensorflow-for-jetson-tk1.html#comment-form" onclick="">
12 comments:
  </a>
</span>
<span class="post-icons">
<span class="item-control blog-admin pid-1214496171">
<a href="https://draft.blogger.com/post-edit.g?blogID=5417613544042855153&amp;postID=2768801506507736415&amp;from=pencil" title="Edit Post">
<img alt="" class="icon-action" height="18" src="https://resources.blogblog.com/img/icon18_edit_allbkg.gif" width="18">
</a>
</span>
</span>
<div class="post-share-buttons goog-inline-block">
</div>
</div>
<div class="post-footer-line post-footer-line-2">
<span class="post-labels">
</span>
</div>
<div class="post-footer-line post-footer-line-3">
<span class="post-location">
</span>
</div>
</div>
</div>
</div>

          </div></div>
        

          <div class="date-outer">
        
<h2 class="date-header"><span>Saturday, October 12, 2013</span></h2>

          <div class="date-posts">
        
<div class="post-outer">
<div class="post hentry uncustomized-post-template" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<meta content="5417613544042855153" itemprop="blogId">
<meta content="2592200183433987592" itemprop="postId">
<a name="2592200183433987592"></a>
<h3 class="post-title entry-title" itemprop="name">
<a href="http://cudamusing.blogspot.com/2013/10/cuda-55-and-xcode-5.html">CUDA 5.5 and Xcode 5</a>
</h3>
<div class="post-header">
<div class="post-header-line-1"></div>
</div>
<div class="post-body entry-content" id="post-body-2592200183433987592" itemprop="description articleBody">
The latest Xcode 5 update seems to have broken nvcc.<br>
<div>
If you try to compile a &nbsp;CUDA program, you will see a similar error:</div>
<div>
<br></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;">%nvcc -c qr.cu</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">clang: error: unsupported option '-dumpspecs'</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">clang: error: no input files</span></div>
</div>
<div>
<br></div>
<div>
There is a simple workaround.</div>
<div>
<br></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;">%nvcc&nbsp;-ccbin=/usr/bin/clang</span>&nbsp;<span style="font-family: 'Courier New', Courier, monospace;">-c qr.cu</span></div>
<div>
<br></div>
</div>
<div>
A more convenient way of adding this, it is to define an alias for nvcc.</div>
<div>
You can add this line to your .bash_profile</div>
<div>
<br></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">alias nvcc='nvcc -ccbin=/usr/bin/clang'</span></div>
<div>
<br></div>
<div>
or just define it in your shell,</div>
<div>
<br></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">alias 'nvcc=nvcc -ccbin=/usr/bin/clang'</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br></span></div>
<div>
<br></div>
<div style="clear: both;"></div>
</div>
<div class="post-footer">
<div class="post-footer-line post-footer-line-1">
<span class="post-author vcard">
Posted by
<span class="fn" itemprop="author" itemscope="itemscope" itemtype="http://schema.org/Person">
<meta content="https://draft.blogger.com/profile/06026735414532627847" itemprop="url">
<a class="g-profile" href="https://draft.blogger.com/profile/06026735414532627847" rel="author" title="author profile">
<span itemprop="name">Massimiliano</span>
</a>
</span>
</span>
<span class="post-timestamp">
at
<meta content="http://cudamusing.blogspot.com/2013/10/cuda-55-and-xcode-5.html" itemprop="url">
<a class="timestamp-link" href="http://cudamusing.blogspot.com/2013/10/cuda-55-and-xcode-5.html" rel="bookmark" title="permanent link"><abbr class="published" itemprop="datePublished" title="2013-10-12T16:18:00-07:00">4:18 PM</abbr></a>
</span>
<span class="post-comment-link">
<a class="comment-link" href="http://cudamusing.blogspot.com/2013/10/cuda-55-and-xcode-5.html#comment-form" onclick="">
No comments:
  </a>
</span>
<span class="post-icons">
<span class="item-control blog-admin pid-1214496171">
<a href="https://draft.blogger.com/post-edit.g?blogID=5417613544042855153&amp;postID=2592200183433987592&amp;from=pencil" title="Edit Post">
<img alt="" class="icon-action" height="18" src="https://resources.blogblog.com/img/icon18_edit_allbkg.gif" width="18">
</a>
</span>
</span>
<div class="post-share-buttons goog-inline-block">
</div>
</div>
<div class="post-footer-line post-footer-line-2">
<span class="post-labels">
</span>
</div>
<div class="post-footer-line post-footer-line-3">
<span class="post-location">
</span>
</div>
</div>
</div>
</div>

          </div></div>
        

          <div class="date-outer">
        
<h2 class="date-header"><span>Wednesday, September 11, 2013</span></h2>

          <div class="date-posts">
        
<div class="post-outer">
<div class="post hentry uncustomized-post-template" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<meta content="5417613544042855153" itemprop="blogId">
<meta content="3965184539304603441" itemprop="postId">
<a name="3965184539304603441"></a>
<h3 class="post-title entry-title" itemprop="name">
<a href="http://cudamusing.blogspot.com/2013/09/calling-cuda-fortran-kernels-from-matlab.html">Calling CUDA Fortran kernels from MATLAB</a>
</h3>
<div class="post-header">
<div class="post-header-line-1"></div>
</div>
<div class="post-body entry-content" id="post-body-3965184539304603441" itemprop="description articleBody">
The latest MATLAB versions, starting from 2010b, &nbsp;have a very cool feature that enables calling CUDA C kernels from MATLAB code.<br>
This is much better and simpler than writing MEX files to call CUDA code ( being the original author of the first CUDA MEX files and of the NVIDIA white-paper, I am speaking from experience) and it is a very powerful tool.<br>
<br>
Let's take a very simple CUDA C code, add.cu, &nbsp;that adds a scalar to a vector:<br>
<br>
<br>
<span style="font-family: Courier New, Courier, monospace;">__global__ void add(double * in, double a, int N) &nbsp;{</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;int idx = blockIdx.x * blockDim.x + threadIdx.x;</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;if (idx &lt; N) {</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; &nbsp; &nbsp;in[idx] += a;</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp;}</span><br>
<span style="font-family: Courier New, Courier, monospace;">}</span><br>
<br>
<div>
The full documentation is available at<br>
<a href="http://www.mathworks.com/help/distcomp/executing-cuda-or-ptx-code-on-the-gpu.html" target="_blank">http://www.mathworks.com/help/distcomp/executing-cuda-or-ptx-code-on-the-gpu.html</a><br>
I am just going to summarize the required steps:<br>
<br></div>
<ul>
<li>Generate a PTX &nbsp;file from the kernel source</li>
<ul>
<li><i>nvcc -ptx -arch sm_20 add.cu</i></li>
</ul>
<li><i><span style="font-style: normal;">Construct the kernel object from the PTX file</span></i></li>
<ul>
<li><i><span style="font-style: normal;"><i>k=parallel.gpu.CUDAKernel('add.ptx','add.cu');</i></span></i></li>
</ul>
<li>Set up the block and grid configuration, for example 28 blocks of 256 threads each:</li>
<ul>
<li><i>k.ThreadBlockSize=[256 1 1]</i></li>
<li><i>k.GridSize=[28 1 1]</i></li>
</ul>
<li>Execute the kernel.</li>
<ul>
<li><i>o = feval(k,rand(10,1),2.,10)</i></li>
<li>The gpu array o contains the output of the kernel</li>
</ul>
</ul>
<ol><ul>
</ul>
</ol>
<br>
It is possible to do the same with CUDA Fortran.<br>
First of all, we will need to rewrite the code in CUDA Fortran (shameless plug, if you want<br>
to learn more about &nbsp;CUDA Fortran there is a very good book you can pre-order from Amazon,<br>
"<span style="background-color: white; font-family: Times, 'Times New Roman', serif;"><a href="http://www.amazon.com/CUDA-Fortran-Scientists-Engineers-Programming/dp/0124169708" target="_blank">CUDA Fortran for Scientists and Engineers: Best Practices for Efficient CUDA Fortran Programming</a>"). This is the equivalent code :</span><br>
<br>
<span style="font-family: Courier New, Courier, monospace;">attributes(global) subroutine add(a, b, N)</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; implicit none</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; double precision, intent(inout) :: a(*)</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; double precision, value :: b</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; integer , value :: N</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; integer :: i</span><br>
<span style="font-family: Courier New, Courier, monospace;"><br></span>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; i = threadIdx%x+(blockIdx%x-1)*blockDim%x</span><br>
<span style="font-family: Courier New, Courier, monospace;">&nbsp; &nbsp; if ( i &lt;=N) a(i) = a(i)+b</span><br>
<span style="font-family: Courier New, Courier, monospace;"><br></span>
<span style="font-family: Courier New, Courier, monospace;">&nbsp;end subroutine add</span><br>
<div>
<br></div>
For the generation of the PTX file, instead of invoking nvcc, we will call pgf90 with the right<br>
flags to generate the PTX file:<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pgf90 -c -Mcuda=keepptx,cc20 &nbsp;addf.cuf<br>
<ul>
</ul>
The keepptx flag will generate the PTX file for compute capabilities 2.0, addf.n001.ptx.<br>
If the compute capabilities are missing or if you specify multiple targets, the PGI compiler will generate different PTX files, &nbsp;you will need to inspect the ptx files to check the compute capabilities, the ordering is just an enumeration. We can perform this step from a OS shell or from inside MATLAB.<br>
In order to invoke the compiler from the MATLAB prompt, we need to load the proper bash variables issuing the command:<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setenv('BASH_ENV','~/.bash_profile');<br>
<br>
and then invoking the pgf90 invocation preceded by an exclamation point. The exclamation point indicates that the rest of the input line is issued as a command to the operating system.<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;!pgf90 -c -Mcuda=keepptx,cc20 &nbsp;addf.cuf<br>
<br>
<br>
<div style="text-align: left;">
In order to load the PTX file in MATLAB, we need to slightly change the syntax.</div>
<div style="text-align: left;">
When loading the PTX file generated by CUDA C, we were passing both the PTX file name and</div>
<div style="text-align: left;">
the original CUDA C file. In this way, MATLAB will automatically discover the prototype of the function. There are other ways, in which we explicitly pass the prototype signature to&nbsp;parallel.gpu.CUDAKernel.&nbsp;</div>
<br>
This is what we need to load the PTX file generated from CUDA Fortran.<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp;kf=parallel.gpu.CUDAKernel('addf.n001.ptx',' double *, double, int ');<br>
<br>
Once we have created the kernel object kf, the calling sequence is the same one we used before.<br>
We will set up the block and grid configuration, for example 28 blocks of 256 threads each:<br>
<br>
<ol><ul>
<li>kf.ThreadBlockSize=[256 1 1]</li>
<li>kf.GridSize=[28 1 1]</li>
</ul>
</ol>
and execute the kernel.<br>
<ol><ul>
<li>of = feval(kf,rand(10,1),2.,10)</li>
</ul>
</ol>
<div>
<br></div>
<div>
This is the full sequence of the MATLAB code with a verbose output to check all the intermediate steps:</div>
<div>
<br></div>
<div>
% Create a 1D array of doubles with 10 elements</div>
<div>
i1=gpuArray(rand(10,1))</div>
<div>
% Create the kernel object from the PTX file with explicit prototype<br>
kf=parallel.gpu.CUDAKernel('addf.n001.ptx',' double *, double, int ')</div>
<div>
% Set execution configuration<br>
kf.ThreadBlockSize=[256 1 1]<br>
kf.GridSize=[28 1 1]</div>
<div>
% Execute the kernel<br>
of=feval(kf,i1,10.,10)</div>
<br>
<br>
An important point for the CUDA Fortran kernels is that you cannot use&nbsp;Fortran assumed-shape arguments, which require the compiler to build and pass the descriptor as an extra argument.<br>
<br>
<br>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
Now that we understand all the steps, let's move to something more complex and discuss few more points.</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
We are going to implement a kernel to compute the sum of an array using a single pass with atomic lock</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
( the implementation and accuracy of parallel sum are discussed in details in Chapter 5 of the before mentioned book).</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
The kernel is embedded in a module, since we are using a global variable for the lock.&nbsp;</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
There is no limitation in the number of elements that the routine can handle, aside from the fact that we are using 32 bit size integers&nbsp;</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
for the addressing , each thread will process multiple data if needed.</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
This is the code:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
module sumgpu</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; implicit none</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; integer, parameter :: fp_kind = kind(0.0d0)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; integer, device::&nbsp; lock=0</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
contains</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; attributes(global) subroutine sum(input,totalsum,N)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; real(fp_kind), intent(in) :: input(N)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; real(fp_kind) :: totalsum(1)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; integer,value :: N</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; real(fp_kind), shared, dimension(256) :: psum</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; integer :: i,index, inext</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; real(fp_kind) :: lsum</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; index=threadIdx%x+(BlockIdx%x-1)*BlockDim%x</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; lsum = 0._fp_kind</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; do i=index,N,BlockDim%x*GridDim%x</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; lsum = lsum+ input(i)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; end do</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; ! Local reduction per block</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; index=threadIdx%x</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; psum(index)=lsum</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; call syncthreads()</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; inext=blockDim%x/2</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; do while ( inext &gt;=1 )</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; if (index &lt;=inext) psum(index)=psum(index)+psum(index+inext)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; inext = inext /2</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; call syncthreads()</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; end do</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; ! Final reduction among block with atomic lock</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; if (index == 1) then</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; do while ( atomiccas(lock,0,1) == 1)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; end do</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; totalsum(1)=totalsum(1)+psum(1)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; call threadfence()</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; lock =0</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; end if</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; end subroutine sum</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
end module sumgpu</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
If we generate and load the module as seen before, we can observe the following:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&gt;&gt; kf=parallel.gpu.CUDAKernel('sumSingleBlock.n001.ptx','double *, double *, int')</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf =&nbsp;</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; CUDAKernel with properties:</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; ThreadBlockSize: [1 1 1]</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; MaxThreadsPerBlock: 1024</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GridSize: [1 1 1]</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; SharedMemorySize: 0</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EntryPoint: 'sumgpu_sum_'</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; MaxNumLHSArguments: 2</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; NumRHSArguments: 3</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ArgumentTypes: {'inout double vector'&nbsp; 'inout double vector'&nbsp; 'in int32 scalar'}</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
The entry point is now sumgpu_sum_, even if the subroutine was named sum. This is a consequence of being embedded in a module.</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
When&nbsp; the CUDA Fortran compiler generate the PTX file, it renames the subroutine entry as a concatenation of the module name, the subroutine name and a trailing underscore.</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
While this is not important when the module contains a single subroutine, it is&nbsp; crucial for situations in which multiple entry points are defined. If the module had&nbsp; multiple subroutines,&nbsp; we would have received an error when trying to load the PTX file:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&gt;&gt; kf=parallel.gpu.CUDAKernel('sumSingleBlock.n001.ptx','double *, double *, int')</div>
<div style="color: #b92d5d; font-family: 'Courier New'; font-size: 13px;">
Error using handleKernelArgs (line 61)</div>
<div style="color: #b92d5d; font-family: 'Courier New'; font-size: 13px;">
Found more than one entry point in the PTX code.&nbsp; Possible names are:</div>
<div style="color: #b92d5d; font-family: 'Courier New'; font-size: 13px;">
sumgpu_sum_</div>
<div style="color: #b92d5d; font-family: 'Courier New'; font-size: 13px;">
sumgpu_sum2_</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
In this case, we would have to modify the command syntax and add an extra argument at the end of the list that specify the entry point.</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&gt;&gt; kf=parallel.gpu.CUDAKernel('sumSingleBlock.n001.ptx','double *, double *, int','<span style="color: #b92d5d;">sumgpu_sum_'</span>)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf =&nbsp;</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; CUDAKernel with properties:</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; ThreadBlockSize: [1 1 1]</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; MaxThreadsPerBlock: 1024</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GridSize: [1 1 1]</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; SharedMemorySize: 0</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EntryPoint: 'sumgpu_sum_'</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; MaxNumLHSArguments: 2</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; NumRHSArguments: 3</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ArgumentTypes: {'inout double vector'&nbsp; 'inout double vector'&nbsp; 'in int32 scalar'}</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
The command now completes correctly.&nbsp; However, with the&nbsp; prototype signature we specified, the first array that in the original code was</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
with intent(in), since it is only an input to the subroutine is now marked as 'inout double vector'.&nbsp; This is not a major problem, but we will</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
need to remember when using the object in MATLAB to specify two vectors as output on the left hand side.</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
We can fix the problem, changing the prototype signature to:</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&gt;&gt; kf=parallel.gpu.CUDAKernel('sumSingleBlock.n001.ptx','const double *, double *, int','sumgpu_sum_')</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf =&nbsp;</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; CUDAKernel with properties:</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; ThreadBlockSize: [1 1 1]</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; MaxThreadsPerBlock: 1024</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GridSize: [1 1 1]</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; SharedMemorySize: 0</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EntryPoint: 'sumgpu_sum_'</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp; &nbsp; MaxNumLHSArguments: 1</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; NumRHSArguments: 3</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ArgumentTypes: {'in double vector'&nbsp; 'inout double vector'&nbsp; 'in int32 scalar'}</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
where we have replaced the 'double *' to 'const double *' to reflect that the array is read-only.&nbsp;</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
We are now ready to run the code:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
%Generate an array of 1024 elements on the CPU</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
a=rand(1024,1);</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
% Copy the array to a GPU array ag</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
ag=gpuArray(a);</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
%Generate the kernel object and setup the execution configuration</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf=parallel.gpu.CUDAKernel('sumSingleBlock.n001.ptx','const double *, double *, int');</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf.ThreadBlockSize=[256 1 1];</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf.GridSize=[28 1 1];</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
% Initialize the sum to zero</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
sumg=gpuArray.zeros(1,'double');</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
% Invoke the kernel</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
disp('CUDA Fortran kernel:')</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
sumg=feval(kf,ag,sumg,1024)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
% Recompute the sum using the intrinsic MATLAB function</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
disp('Intrinsic MATLAB sum on GPU:')</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
sum_matlab=sum(ag)</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
%Check the result</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
disp('Difference:')</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
sumg-sum_matlab</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
obtaining the following output:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
CUDA Fortran kernel:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
sumg =</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
&nbsp; 509.2181</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
Intrinsic MATLAB sum on GPU:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
sum_matlab =</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
&nbsp; 509.2181</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
Difference:</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
ans =</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
&nbsp;&nbsp; &nbsp; 0</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
Now that we are confident that the code is running properly and giving the correct results, we can do some performance testing.</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
We will generate 50 millions random number directly on the GPU and then compute their sum.</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
%Set up random number generation on the GPU</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
seed=0;</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
gpu_stream = parallel.gpu.RandStream('CombRecursive','Seed',seed);</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
parallel.gpu.RandStream.setGlobalStream(gpu_stream);</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
N=50000000;</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
%Generate the random numbers directly on the GPU</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
ag=gpuArray.randn(N,1);</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
%Generate the kernel object and setup the execution configuration</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf=parallel.gpu.CUDAKernel('sumSingleBlock.n001.ptx','const double *, double *, int');</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf.ThreadBlockSize=[256 1 1];</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
kf.GridSize=[128 1 1];</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
% Initialize the sum to zero</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
sumg=gpuArray.zeros(1,'double');</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
% Invoke the kernel and time the execution</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
tic;sumg=feval(kf,ag,sumg,N);toc</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
% Invoke the intrinsic sum and time the execution</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
tic;sum(ag);toc</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
The output indicates that this version is slightly faster than the native sum, that is however more convenient to use.</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
Elapsed time is 0.000357 seconds.</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px;">
Elapsed time is 0.000393 seconds.</div>
<div style="color: #323333; font-family: 'Courier New'; font-size: 13px; min-height: 15px;">
<br></div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
The real goal of using CUDA Fortran kernels is not to reimplement the intrinsic functions but to implement new capabilities or just re-use</div>
<div style="color: #323333; font-family: Georgia; font-size: 13px;">
standalone code that was already written in a very productive environment such as MATLAB.</div>
<div>
<br></div>
<br>
<br>
<br>
<div style="clear: both;"></div>
</div>
<div class="post-footer">
<div class="post-footer-line post-footer-line-1">
<span class="post-author vcard">
Posted by
<span class="fn" itemprop="author" itemscope="itemscope" itemtype="http://schema.org/Person">
<meta content="https://draft.blogger.com/profile/06026735414532627847" itemprop="url">
<a class="g-profile" href="https://draft.blogger.com/profile/06026735414532627847" rel="author" title="author profile">
<span itemprop="name">Massimiliano</span>
</a>
</span>
</span>
<span class="post-timestamp">
at
<meta content="http://cudamusing.blogspot.com/2013/09/calling-cuda-fortran-kernels-from-matlab.html" itemprop="url">
<a class="timestamp-link" href="http://cudamusing.blogspot.com/2013/09/calling-cuda-fortran-kernels-from-matlab.html" rel="bookmark" title="permanent link"><abbr class="published" itemprop="datePublished" title="2013-09-11T12:39:00-07:00">12:39 PM</abbr></a>
</span>
<span class="post-comment-link">
<a class="comment-link" href="http://cudamusing.blogspot.com/2013/09/calling-cuda-fortran-kernels-from-matlab.html#comment-form" onclick="">
4 comments:
  </a>
</span>
<span class="post-icons">
<span class="item-control blog-admin pid-1214496171">
<a href="https://draft.blogger.com/post-edit.g?blogID=5417613544042855153&amp;postID=3965184539304603441&amp;from=pencil" title="Edit Post">
<img alt="" class="icon-action" height="18" src="https://resources.blogblog.com/img/icon18_edit_allbkg.gif" width="18">
</a>
</span>
</span>
<div class="post-share-buttons goog-inline-block">
</div>
</div>
<div class="post-footer-line post-footer-line-2">
<span class="post-labels">
</span>
</div>
<div class="post-footer-line post-footer-line-3">
<span class="post-location">
</span>
</div>
</div>
</div>
</div>

        </div></div>
      
</div>
<div class="blog-pager" id="blog-pager">
<span id="blog-pager-older-link">
<a class="blog-pager-older-link" href="http://cudamusing.blogspot.com/search?updated-max=2013-09-11T12:39:00-07:00&amp;max-results=7" id="Blog1_blog-pager-older-link" title="Older Posts">Older Posts</a>
</span>
<a class="home-link" href="http://cudamusing.blogspot.com/">Home</a>
</div>
<div class="clear"></div>
<div class="blog-feeds">
<div class="feed-links">
Subscribe to:
<a class="feed-link" href="http://cudamusing.blogspot.com/feeds/posts/default" target="_blank" type="application/atom+xml">Posts (Atom)</a>
</div>
</div>
</div></div>
</div>
<div id="sidebar-wrapper">
<div class="sidebar section" id="sidebar"><div class="widget BlogSearch" data-version="1" id="BlogSearch1">
<h2 class="title">Search This Blog</h2>
<div class="widget-content">
<div id="BlogSearch1_form">
<form action="http://cudamusing.blogspot.com/search" class="gsc-search-box" target="_top">
<table cellpadding="0" cellspacing="0" class="gsc-search-box">
<tbody>
<tr>
<td class="gsc-input">
<input autocomplete="off" class="gsc-input" name="q" size="10" title="search" type="text" value="">
</td>
<td class="gsc-search-button">
<input class="gsc-search-button" title="search" type="submit" value="Search">
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
<div class="clear"></div>
</div><div class="widget AdSense" data-version="1" id="AdSense1">
<div class="widget-content">
<script type="text/javascript"><!--
google_ad_client="pub-9986733645989591";
google_ad_host="pub-1556223355139109";
google_ad_width=200;
google_ad_height=200;
google_ad_format="200x200_as";
google_ad_type="text_image";
google_ad_host_channel="0001";
google_color_border="FFFFFF";
google_color_bg="FFFFFF";
google_color_link="999999";
google_color_url="5588AA";
google_color_text="666666";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><ins class="adsbygoogle adsbygoogle-noablate" data-ad-client="pub-9986733645989591" data-ad-format="200x200_as" data-ad-height="200" data-ad-host="pub-1556223355139109" data-ad-host-channel="0001" data-ad-type="text_image" data-ad-width="200" data-color-bg="FFFFFF" data-color-border="FFFFFF" data-color-link="999999" data-color-text="666666" data-color-url="5588AA" data-adsbygoogle-status="done" style="display: inline-block; width: 200px; height: 200px;" data-ad-status="unfilled"><div id="aswift_0_host" style="border: none; height: 200px; width: 200px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block;"><iframe id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;border:0;width:200px;height:200px;" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" width="200" height="200" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-9986733645989591&amp;output=html&amp;h=200&amp;adk=1156497998&amp;adf=2809941920&amp;w=200&amp;lmt=1710347096&amp;ad_type=text_image&amp;format=200x200_as&amp;color_bg=FFFFFF&amp;color_border=FFFFFF&amp;color_link=999999&amp;color_text=666666&amp;color_url=5588AA&amp;url=http%3A%2F%2Fcudamusing.blogspot.com%2F&amp;host=pub-1556223355139109&amp;h_ch=0001&amp;wgl=1&amp;dt=1724073037495&amp;bpp=5421&amp;bdt=5345&amp;idt=5752&amp;shv=r20240814&amp;mjsv=m202408140101&amp;ptt=5&amp;saldr=sd&amp;abxe=1&amp;cookie_enabled=1&amp;eoidce=1&amp;correlator=3622026127887&amp;frm=20&amp;pv=2&amp;u_tz=0&amp;u_his=2&amp;u_h=1080&amp;u_w=1920&amp;u_ah=1080&amp;u_aw=1920&amp;u_cd=24&amp;u_sd=1&amp;adx=1386&amp;ady=253&amp;biw=1905&amp;bih=1080&amp;scr_x=0&amp;scr_y=0&amp;eid=44759875%2C44759926%2C44759837%2C42532523%2C44795921%2C95334528%2C95334830%2C95337870%2C95340753%2C31086219%2C95335248&amp;oid=2&amp;pvsid=493045032819310&amp;tmod=1388720003&amp;uas=0&amp;nvt=1&amp;fc=896&amp;brdim=0%2C0%2C0%2C0%2C1920%2C0%2C1920%2C1080%2C1920%2C1080&amp;vis=1&amp;rsz=%7C%7CoeE%7C&amp;abl=CS&amp;pfx=0&amp;fu=0&amp;bc=23&amp;bz=1&amp;psd=W251bGwsbnVsbCxudWxsLDNd&amp;ifi=1&amp;uci=a!1&amp;fsb=1&amp;dtd=5790" data-google-container-id="a!1" tabindex="0" title="Advertisement" aria-label="Advertisement" data-load-complete="true"></iframe></div></ins>
<div class="clear"></div>
</div>
</div><div class="widget Followers" data-version="1" id="Followers1">
<h2 class="title">Followers</h2>
<div class="widget-content">
<div id="Followers1-wrapper">
<div style="margin-right:2px;">
<div><script type="text/javascript" src="https://apis.google.com/js/platform.js" gapi_processed="true"></script>
<div id="followers-iframe-container"><iframe ng-non-bindable="" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="" tabindex="0" vspace="0" width="100%" id="I0_1724073037515" name="I0_1724073037515" src="https://draft.blogger.com/followers.g?blogID=5417613544042855153&amp;colors=Cgt0cmFuc3BhcmVudBILdHJhbnNwYXJlbnQaByM2NjY2NjYiByM1NTg4YWEqByNmZmZmZmYyByNjYzY2MDA6ByM2NjY2NjZCByM1NTg4YWFKByM5OTk5OTlSByM1NTg4YWFaC3RyYW5zcGFyZW50&amp;pageSize=21&amp;origin=http://cudamusing.blogspot.com/&amp;usegapi=1&amp;jsh=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.lb.en.pGGAptgAK4s.O%2Fam%3DAAAg%2Fd%3D1%2Frs%3DAHpOoo-Cic-4VdRMZ7mFCYOA3wzpF7O-6g%2Fm%3D__features__#id=I0_1724073037515&amp;_gfid=I0_1724073037515&amp;parent=http%3A%2F%2Fcudamusing.blogspot.com&amp;pfname=&amp;rpctoken=13026850" height="123"></iframe></div>
<script type="text/javascript">
    window.followersIframe = null;
    function followersIframeOpen(url) {
      gapi.load("gapi.iframes", function() {
        if (gapi.iframes && gapi.iframes.getContext) {
          window.followersIframe = gapi.iframes.getContext().openChild({
            url: url,
            where: document.getElementById("followers-iframe-container"),
            messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER,
            messageHandlers: {
              '_ready': function(obj) {
                window.followersIframe.getIframeEl().height = obj.height;
              },
              'reset': function() {
                window.followersIframe.close();
                followersIframeOpen("https://draft.blogger.com/followers.g?blogID\x3d5417613544042855153\x26colors\x3dCgt0cmFuc3BhcmVudBILdHJhbnNwYXJlbnQaByM2NjY2NjYiByM1NTg4YWEqByNmZmZmZmYyByNjYzY2MDA6ByM2NjY2NjZCByM1NTg4YWFKByM5OTk5OTlSByM1NTg4YWFaC3RyYW5zcGFyZW50\x26pageSize\x3d21\x26origin\x3dhttp://cudamusing.blogspot.com/");
              },
              'open': function(url) {
                window.followersIframe.close();
                followersIframeOpen(url);
              },
              'blogger-ping': function() {
              }
            }
          });
        }
      });
    }
    followersIframeOpen("https://draft.blogger.com/followers.g?blogID\x3d5417613544042855153\x26colors\x3dCgt0cmFuc3BhcmVudBILdHJhbnNwYXJlbnQaByM2NjY2NjYiByM1NTg4YWEqByNmZmZmZmYyByNjYzY2MDA6ByM2NjY2NjZCByM1NTg4YWFKByM5OTk5OTlSByM1NTg4YWFaC3RyYW5zcGFyZW50\x26pageSize\x3d21\x26origin\x3dhttp://cudamusing.blogspot.com/");
  </script></div>
</div>
</div>
<div class="clear"></div>
</div>
</div><div class="widget BlogArchive" data-version="1" id="BlogArchive1">
<h2>Blog Archive</h2>
<div class="widget-content">
<div id="ArchiveList">
<div id="BlogArchive1_ArchiveList">
<ul class="hierarchy">
<li class="archivedate expanded">
<a class="toggle" href="javascript:void(0)">
<span class="zippy toggle-open">

        ▼&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2016/">
2016
</a>
<span class="post-count" dir="ltr">(1)</span>
<ul class="hierarchy">
<li class="archivedate expanded">
<a class="toggle" href="javascript:void(0)">
<span class="zippy toggle-open">

        ▼&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2016/06/">
June
</a>
<span class="post-count" dir="ltr">(1)</span>
<ul class="posts">
<li><a href="http://cudamusing.blogspot.com/2016/06/tensorflow-08-on-jetson-tk1.html">TensorFlow 0.8 on Jetson TK1</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2015/">
2015
</a>
<span class="post-count" dir="ltr">(1)</span>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2015/11/">
November
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2013/">
2013
</a>
<span class="post-count" dir="ltr">(3)</span>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2013/10/">
October
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2013/09/">
September
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2013/07/">
July
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2012/">
2012
</a>
<span class="post-count" dir="ltr">(3)</span>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2012/11/">
November
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2012/10/">
October
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2012/09/">
September
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2011/">
2011
</a>
<span class="post-count" dir="ltr">(4)</span>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2011/11/">
November
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2011/08/">
August
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2011/06/">
June
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2011/05/">
May
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2010/">
2010
</a>
<span class="post-count" dir="ltr">(3)</span>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2010/07/">
July
</a>
<span class="post-count" dir="ltr">(1)</span>
</li>
</ul>
<ul class="hierarchy">
<li class="archivedate collapsed">
<a class="toggle" href="javascript:void(0)">
<span class="zippy">

        ►&nbsp;
      
</span>
</a>
<a class="post-count-link" href="http://cudamusing.blogspot.com/2010/05/">
May
</a>
<span class="post-count" dir="ltr">(2)</span>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
</div><div class="widget Profile" data-version="1" id="Profile1">
<h2>About Me</h2>
<div class="widget-content">
<dl class="profile-datablock">
<dt class="profile-data">
<a class="profile-name-link g-profile" href="https://draft.blogger.com/profile/06026735414532627847" rel="author" style="background-image: url(//draft.blogger.com/img/logo-16.png);">
Massimiliano
</a>
</dt>
</dl>
<a class="profile-link" href="https://draft.blogger.com/profile/06026735414532627847" rel="author">View my complete profile</a>
<div class="clear"></div>
</div>
</div></div>
</div>
<!-- spacer for skins that want sidebar and main to be the same height-->
<div class="clear">&nbsp;</div>
</div>
<!-- end content-wrapper -->
<div id="footer-wrapper">
<div class="footer no-items section" id="footer"></div>
</div>
</div></div>
<!-- end outer-wrapper -->

<script type="text/javascript" src="https://www.blogger.com/static/v1/widgets/3499193034-widgets.js"></script>
<script type="text/javascript">
window['__wavt'] = 'AOuZoY5EYNrIxOkm2m0Fh2FimpYxIHhB0A:1724073032063';_WidgetManager._Init('//draft.blogger.com/rearrange?blogID\x3d5417613544042855153','//cudamusing.blogspot.com/','5417613544042855153');
_WidgetManager._SetDataContext([{'name': 'blog', 'data': {'blogId': '5417613544042855153', 'title': 'CUDA Musing', 'url': 'http://cudamusing.blogspot.com/', 'canonicalUrl': 'http://cudamusing.blogspot.com/', 'homepageUrl': 'http://cudamusing.blogspot.com/', 'searchUrl': 'http://cudamusing.blogspot.com/search', 'canonicalHomepageUrl': 'http://cudamusing.blogspot.com/', 'blogspotFaviconUrl': 'http://cudamusing.blogspot.com/favicon.ico', 'bloggerUrl': 'https://draft.blogger.com', 'hasCustomDomain': false, 'httpsEnabled': true, 'enabledCommentProfileImages': true, 'gPlusViewType': 'FILTERED_POSTMOD', 'adultContent': false, 'analyticsAccountNumber': '', 'encoding': 'UTF-8', 'locale': 'en', 'localeUnderscoreDelimited': 'en', 'languageDirection': 'ltr', 'isPrivate': false, 'isMobile': false, 'isMobileRequest': false, 'mobileClass': '', 'isPrivateBlog': false, 'isDynamicViewsAvailable': true, 'feedLinks': '\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22CUDA Musing - Atom\x22 href\x3d\x22http://cudamusing.blogspot.com/feeds/posts/default\x22 /\x3e\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/rss+xml\x22 title\x3d\x22CUDA Musing - RSS\x22 href\x3d\x22http://cudamusing.blogspot.com/feeds/posts/default?alt\x3drss\x22 /\x3e\n\x3clink rel\x3d\x22service.post\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22CUDA Musing - Atom\x22 href\x3d\x22https://draft.blogger.com/feeds/5417613544042855153/posts/default\x22 /\x3e\n', 'meTag': '\x3clink rel\x3d\x22me\x22 href\x3d\x22https://draft.blogger.com/profile/06026735414532627847\x22 /\x3e\n', 'adsenseClientId': 'ca-pub-9986733645989591', 'adsenseHostId': 'ca-host-pub-1556223355139109', 'adsenseHasAds': true, 'adsenseAutoAds': false, 'boqCommentIframeForm': true, 'loginRedirectParam': '', 'view': '', 'dynamicViewsCommentsSrc': '//www.blogblog.com/dynamicviews/4224c15c4e7c9321/js/comments.js', 'dynamicViewsScriptSrc': '//www.blogblog.com/dynamicviews/9d46b36f46d467c5', 'plusOneApiSrc': 'https://apis.google.com/js/platform.js', 'disableGComments': true, 'interstitialAccepted': false, 'sharing': {'platforms': [{'name': 'Get link', 'key': 'link', 'shareMessage': 'Get link', 'target': ''}, {'name': 'Facebook', 'key': 'facebook', 'shareMessage': 'Share to Facebook', 'target': 'facebook'}, {'name': 'BlogThis!', 'key': 'blogThis', 'shareMessage': 'BlogThis!', 'target': 'blog'}, {'name': 'Twitter', 'key': 'twitter', 'shareMessage': 'Share to Twitter', 'target': 'twitter'}, {'name': 'Pinterest', 'key': 'pinterest', 'shareMessage': 'Share to Pinterest', 'target': 'pinterest'}, {'name': 'Email', 'key': 'email', 'shareMessage': 'Email', 'target': 'email'}], 'disableGooglePlus': true, 'googlePlusShareButtonWidth': 0, 'googlePlusBootstrap': '\x3cscript type\x3d\x22text/javascript\x22\x3ewindow.___gcfg \x3d {\x27lang\x27: \x27en\x27};\x3c/script\x3e'}, 'hasCustomJumpLinkMessage': false, 'jumpLinkMessage': 'Read more', 'pageType': 'index', 'pageName': '', 'pageTitle': 'CUDA Musing'}}, {'name': 'features', 'data': {}}, {'name': 'messages', 'data': {'edit': 'Edit', 'linkCopiedToClipboard': 'Link copied to clipboard!', 'ok': 'Ok', 'postLink': 'Post Link'}}, {'name': 'template', 'data': {'isResponsive': false, 'isAlternateRendering': false, 'isCustom': false}}, {'name': 'view', 'data': {'classic': {'name': 'classic', 'url': '?view\x3dclassic'}, 'flipcard': {'name': 'flipcard', 'url': '?view\x3dflipcard'}, 'magazine': {'name': 'magazine', 'url': '?view\x3dmagazine'}, 'mosaic': {'name': 'mosaic', 'url': '?view\x3dmosaic'}, 'sidebar': {'name': 'sidebar', 'url': '?view\x3dsidebar'}, 'snapshot': {'name': 'snapshot', 'url': '?view\x3dsnapshot'}, 'timeslide': {'name': 'timeslide', 'url': '?view\x3dtimeslide'}, 'isMobile': false, 'title': 'CUDA Musing', 'description': 'Random collection of CUDA examples, tricks and suggestions.', 'url': 'http://cudamusing.blogspot.com/', 'type': 'feed', 'isSingleItem': false, 'isMultipleItems': true, 'isError': false, 'isPage': false, 'isPost': false, 'isHomepage': true, 'isArchive': false, 'isLabelSearch': false}}]);
_WidgetManager._RegisterWidget('_NavbarView', new _WidgetInfo('Navbar1', 'navbar', document.getElementById('Navbar1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_HeaderView', new _WidgetInfo('Header1', 'header', document.getElementById('Header1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_BlogView', new _WidgetInfo('Blog1', 'main', document.getElementById('Blog1'), {'cmtInteractionsEnabled': false, 'lightboxEnabled': true, 'lightboxModuleUrl': 'https://www.blogger.com/static/v1/jsbin/47261028-lbx.js', 'lightboxCssUrl': 'https://www.blogger.com/static/v1/v-css/13464135-lightbox_bundle.css'}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_BlogSearchView', new _WidgetInfo('BlogSearch1', 'sidebar', document.getElementById('BlogSearch1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_AdSenseView', new _WidgetInfo('AdSense1', 'sidebar', document.getElementById('AdSense1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_FollowersView', new _WidgetInfo('Followers1', 'sidebar', document.getElementById('Followers1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_BlogArchiveView', new _WidgetInfo('BlogArchive1', 'sidebar', document.getElementById('BlogArchive1'), {'languageDirection': 'ltr', 'loadingMessage': 'Loading\x26hellip;'}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_ProfileView', new _WidgetInfo('Profile1', 'sidebar', document.getElementById('Profile1'), {}, 'displayModeFull'));
</script>

<ins class="adsbygoogle adsbygoogle-noablate" data-adsbygoogle-status="done" style="display: none !important;" data-ad-status="unfilled"><div id="aswift_1_host" style="border: none; height: 0px; width: 0px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block;"><iframe id="aswift_1" name="aswift_1" style="left:0;position:absolute;top:0;border:0;width:undefinedpx;height:undefinedpx;" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-9986733645989591&amp;output=html&amp;adk=1812271804&amp;adf=3025194257&amp;abgtt=1&amp;lmt=1710347096&amp;plat=3%3A16%2C4%3A16%2C9%3A32776%2C16%3A8388608%2C17%3A32%2C24%3A32%2C25%3A32%2C30%3A1081344%2C32%3A32%2C41%3A32%2C42%3A32&amp;format=0x0&amp;url=http%3A%2F%2Fcudamusing.blogspot.com%2F&amp;host=pub-1556223355139109&amp;h_ch=0001&amp;pra=7&amp;wgl=1&amp;easpi=0&amp;aihb=0&amp;asro=0&amp;ailel=29~32~27~1~2~4~6~7~8~9~10~11~12~13~14~15~16~17~18~19~20~21~24~30~34&amp;aiael=29~32~27~1~2~4~6~7~8~9~10~11~12~13~14~15~16~17~18~19~20~21~24~30~34&amp;aicel=33&amp;aifxl=32_7~27_4~30_19&amp;aiixl=29_5~32_9~27_3~30_6&amp;aslmct=0.7&amp;asamct=0.7&amp;aiict=1&amp;dt=1724073042916&amp;bpp=2&amp;bdt=10766&amp;idt=380&amp;shv=r20240814&amp;mjsv=m202408140101&amp;ptt=9&amp;saldr=aa&amp;abxe=1&amp;cookie_enabled=1&amp;eoidce=1&amp;prev_fmts=200x200_as&amp;nras=1&amp;correlator=3622026127887&amp;pv_h_ch=0001&amp;frm=20&amp;pv=1&amp;u_tz=0&amp;u_his=2&amp;u_h=1080&amp;u_w=1920&amp;u_ah=1080&amp;u_aw=1920&amp;u_cd=24&amp;u_sd=1&amp;adx=-12245933&amp;ady=-12245933&amp;biw=1905&amp;bih=1080&amp;scr_x=0&amp;scr_y=0&amp;eid=44759875%2C44759926%2C44759837%2C42532523%2C44795921%2C95334528%2C95334830%2C95337870%2C95340753%2C31086219%2C95335248&amp;oid=2&amp;pvsid=493045032819310&amp;tmod=1388720003&amp;uas=0&amp;nvt=1&amp;fsapi=1&amp;fc=896&amp;brdim=0%2C0%2C0%2C0%2C1920%2C0%2C1920%2C1080%2C1920%2C1080&amp;vis=1&amp;rsz=%7C%7Cs%7C&amp;abl=NS&amp;cms=1&amp;fu=32768&amp;bc=23&amp;bz=1&amp;psd=W251bGwsbnVsbCxudWxsLDNd&amp;ifi=2&amp;uci=a!2&amp;fsb=1&amp;dtd=404" data-google-container-id="a!2" tabindex="0" title="Advertisement" aria-label="Advertisement" data-load-complete="true"></iframe></div></ins><iframe src="https://www.google.com/recaptcha/api2/aframe" width="0" height="0" style="display: none;"></iframe></body><iframe id="google_esf" name="google_esf" src="https://googleads.g.doubleclick.net/pagead/html/r20240814/r20110914/zrt_lookup.html" style="display: none;"></iframe></html>