blob: d3c97dfe9fbec9fbf8d943c4494c9d1da18f2346 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>设备(Device) &mdash; singa 2.0.0 documentation</title>
<script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'2.0.0',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="张量(Tensor)" href="tensor.html" />
<link rel="prev" title="软件架构" href="software_stack.html" />
<link href="../_static/style.css" rel="stylesheet" type="text/css">
<!--link href="../_static/fontawesome-all.min.css" rel="stylesheet" type="text/css"-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css"
integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<style>
.fa:hover {
opacity: 0.7;
}
.fab:hover {
opacity: 0.7;
}
</style>
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home"> singa
<img src="../_static/singa.png" class="logo" alt="Logo"/>
</a>
<div class="version">
latest
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">文档</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="installation.html">安装</a></li>
<li class="toctree-l2"><a class="reference internal" href="software_stack.html">软件架构</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">设备(Device)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id1">特定设备</a></li>
<li class="toctree-l3"><a class="reference internal" href="#python-api">Python API</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#singa-device-create-cuda-gpus-num">singa.device.create_cuda_gpus(num)</a></li>
<li class="toctree-l4"><a class="reference internal" href="#singa-device-create-cuda-gpus-on-device-ids">singa.device.create_cuda_gpus_on(device_ids)</a></li>
<li class="toctree-l4"><a class="reference internal" href="#singa-device-get-default-device">singa.device.get_default_device()</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="tensor.html">张量(Tensor)</a></li>
<li class="toctree-l2"><a class="reference internal" href="layer.html">层(Layer)</a></li>
<li class="toctree-l2"><a class="reference internal" href="net.html">前馈网络</a></li>
<li class="toctree-l2"><a class="reference internal" href="initializer.html">初始化器(Initializer)</a></li>
<li class="toctree-l2"><a class="reference internal" href="loss.html">损失(Loss)</a></li>
<li class="toctree-l2"><a class="reference internal" href="metric.html">度量(Metric)</a></li>
<li class="toctree-l2"><a class="reference internal" href="optimizer.html">优化器(Optimizer)</a></li>
<li class="toctree-l2"><a class="reference internal" href="data.html">数据(Data)</a></li>
<li class="toctree-l2"><a class="reference internal" href="image_tool.html">图像工具</a></li>
<li class="toctree-l2"><a class="reference internal" href="snapshot.html">Snapshot</a></li>
<li class="toctree-l2"><a class="reference internal" href="utils.html">Utils</a></li>
<li class="toctree-l2"><a class="reference internal" href="model_zoo/index.html">模型库</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../downloads.html">下载 SINGA</a></li>
</ul>
<p class="caption"><span class="caption-text">开发</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../develop/schedule.html">开发时间表</a></li>
<li class="toctree-l1"><a class="reference internal" href="../develop/how-contribute.html">如何贡献给 SINGA</a></li>
<li class="toctree-l1"><a class="reference internal" href="../develop/contribute-code.html">如何贡献代码</a></li>
</ul>
<p class="caption"><span class="caption-text">社区</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../community/source-repository.html">源代码库</a></li>
<li class="toctree-l1"><a class="reference internal" href="../community/mail-lists.html">项目邮件列表</a></li>
<li class="toctree-l1"><a class="reference internal" href="../community/issue-tracking.html">问题追踪</a></li>
<li class="toctree-l1"><a class="reference internal" href="../community/team-list.html">SINGA团队</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">singa</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> &raquo;</li>
<li><a href="index.html">文档</a> &raquo;</li>
<li>设备(Device)</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="device">
<h1>设备(Device)<a class="headerlink" href="#device" title="Permalink to this headline"></a></h1>
<p>设备抽象代表了任何基于内存和计算单元的硬件设备。所有<a class="reference external" href="tensor.html">Tensor操作</a>由寄宿的设备进行调度以执行。Tensor内存也由设备内存管理器进行管理。因此,内存优化和执行都由Device类进行实现。</p>
<div class="section" id="id1">
<h2>特定设备<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h2>
<p>目前,SINGA有三种Device实现,</p>
<ol class="simple">
<li>CudaGPU: 在Nvidia GPU卡上运行Cuda代码</li>
<li>CppCPU:在CPU上运行Cpp代码</li>
<li>OpenclGPU: GPU卡上运行OpenCL代码</li>
</ol>
</div>
<div class="section" id="python-api">
<h2>Python API<a class="headerlink" href="#python-api" title="Permalink to this headline"></a></h2>
<p>此脚本包括Device类和它的子类,用户可以调用singa::Device和它的方法。</p>
<hr class="docutils" />
<div class="section" id="singa-device-create-cuda-gpus-num">
<h3>singa.device.create_cuda_gpus(num)<a class="headerlink" href="#singa-device-create-cuda-gpus-num" title="Permalink to this headline"></a></h3>
<p>创建一个列表的CudaGPU设备。</p>
<p><strong>参数:</strong></p>
<ul class="simple">
<li><strong>num(int)</strong> - 创建的设备数目</li>
</ul>
<p><strong>返回值:</strong> 一个列表CudaGPU设备</p>
</div>
<hr class="docutils" />
<div class="section" id="singa-device-create-cuda-gpus-on-device-ids">
<h3>singa.device.create_cuda_gpus_on(device_ids)<a class="headerlink" href="#singa-device-create-cuda-gpus-on-device-ids" title="Permalink to this headline"></a></h3>
<p>创建一个列表的CudaGPU设备。</p>
<p><strong>参数:</strong></p>
<ul class="simple">
<li><strong>device_ids(list)</strong> - 一个列表的显卡ID</li>
</ul>
<p><strong>返回值:</strong> 一个列表CudaGPU设备</p>
</div>
<hr class="docutils" />
<div class="section" id="singa-device-get-default-device">
<h3>singa.device.get_default_device()<a class="headerlink" href="#singa-device-get-default-device" title="Permalink to this headline"></a></h3>
<p>获取默认的CppCPU设备。</p>
<hr class="docutils" />
<p>下面的代码展示了创建设备的例子:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">singa</span> <span class="kn">import</span> <span class="n">device</span>
<span class="n">cuda</span> <span class="o">=</span> <span class="n">device</span><span class="o">.</span><span class="n">create_cuda_gpu_on</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="c1"># use GPU card of ID 0</span>
<span class="n">host</span> <span class="o">=</span> <span class="n">device</span><span class="o">.</span><span class="n">get_default_device</span><span class="p">()</span> <span class="c1"># get the default host device (a CppCPU)</span>
<span class="n">ary1</span> <span class="o">=</span> <span class="n">device</span><span class="o">.</span><span class="n">create_cuda_gpus</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># create 2 devices, starting from ID 0</span>
<span class="n">ary2</span> <span class="o">=</span> <span class="n">device</span><span class="o">.</span><span class="n">create_cuda_gpus</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span> <span class="c1"># create 2 devices on ID 0 and 2</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="tensor.html" class="btn btn-neutral float-right" title="张量(Tensor)" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="software_stack.html" class="btn btn-neutral float-left" title="软件架构" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2019 The Apache Software Foundation. All rights reserved. Apache SINGA, Apache, the Apache feather logo, and the Apache SINGA project logos are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book"> singa </span>
v: latest
<span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
<dl>
<dt>Languages</dt>
<dd><a href="../../index.html">English</a></dd>
<dd><a href=".././index.html">中文</a></dd>
</dl>
<dl>
<dt>Versions</dt>
<dd><a href="http://singa.apache.org/v0.3.0/">0.3</a></dd>
<dd><a href="http://singa.apache.org/v1.1.0/">1.1</a></dd>
</dl>
</div>
<a href="http://www.apache.org"
style="color:lightblue;padding: 5px; font-size: 10px; text-align: center; text-decoration: none; margin: 5px 2px;">Foundation</a>
<a href="http://www.apache.org/events/current-event"
style="color:lightblue;padding: 5px; font-size: 10px; text-align: center; text-decoration: none; margin: 5px 2px;">Events</a>
<a href="http://www.apache.org/foundation/thanks.html"
style="color:lightblue;padding: 5px; font-size: 10px; text-align: center; text-decoration: none; margin: 5px 2px;">Thanks</a>
<a href="http://www.apache.org/foundation/sponsorship.html"
style="color:lightblue;padding: 5px; font-size: 10px; text-align: center; text-decoration: none; margin: 5px 2px;">Sponsorship</a>
<a href="http://www.apache.org/licenses/"
style="color:lightblue;padding: 5px; font-size: 10px; text-align: center; text-decoration: none; margin: 5px 2px;">License</a>
<br>
<a href="https://github.com/apache/singa" class="fa fa-github"
style="padding: 10px; font-size: 20px; width: 30px; text-align: center; text-decoration: none; margin: 5px 2px;"></a>
<a href="https://aws.amazon.com/marketplace/seller-profile?id=5bcac385-12c4-4802-aec7-351e09b77b4c" class="fab fa-aws"
style="padding: 10px; font-size: 20px; width: 30px; text-align: center; text-decoration: none; margin: 5px 2px;"></a>
<a href="https://hub.docker.com/r/apache/singa/" class="fab fa-docker"
style="padding: 10px; font-size: 20px; width: 30px; text-align: center; text-decoration: none; margin: 5px 2px;"></a>
<a href="https://www.linkedin.com/groups/13550034" class="fa fa-linkedin"
style="padding: 10px; font-size: 20px; width: 30px; text-align: center; text-decoration: none; margin: 5px 2px;"></a>
<a href="https://twitter.com/ApacheSinga" class="fa fa-twitter"
style="padding: 10px; font-size: 20px; width: 30px; text-align: center; text-decoration: none; margin: 5px 2px;"></a>
<a href="https://www.facebook.com/Apache-SINGA-347284219056544/" class="fa fa-facebook"
style="padding: 10px; font-size: 20px; width: 30px; text-align: center; text-decoration: none; margin: 5px 2px;"></a>
<a href="https://www.researchgate.net/project/Apache-SINGA" class="fab fa-researchgate"
style="padding: 10px; font-size: 20px; width: 30px; text-align: center; text-decoration: none; margin: 5px 2px;"></a>
</div>
<a href="https://github.com/apache/singa">
<img style="position: absolute; top: 0; right: 0; border: 0; z-index: 10000;"
src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub">
</a>
</body>
</html>