mirror of
https://github.com/tensorflow/haskell.git
synced 2025-01-28 03:35:02 +01:00
ea8b62e47b
* Trivial script for regenerating haddocks: exclude .haddock files. * Haddock regen
254 lines
53 KiB
HTML
254 lines
53 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html>
|
|
<head>
|
|
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
|
|
<title>src/TensorFlow/Internal/FFI.hs</title>
|
|
<link type='text/css' rel='stylesheet' href='hscolour.css' />
|
|
</head>
|
|
<body>
|
|
<pre><a name="line-1"></a><span class='hs-comment'>-- Copyright 2016 TensorFlow authors.</span>
|
|
<a name="line-2"></a><span class='hs-comment'>--</span>
|
|
<a name="line-3"></a><span class='hs-comment'>-- Licensed under the Apache License, Version 2.0 (the "License");</span>
|
|
<a name="line-4"></a><span class='hs-comment'>-- you may not use this file except in compliance with the License.</span>
|
|
<a name="line-5"></a><span class='hs-comment'>-- You may obtain a copy of the License at</span>
|
|
<a name="line-6"></a><span class='hs-comment'>--</span>
|
|
<a name="line-7"></a><span class='hs-comment'>-- <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a></span>
|
|
<a name="line-8"></a><span class='hs-comment'>--</span>
|
|
<a name="line-9"></a><span class='hs-comment'>-- Unless required by applicable law or agreed to in writing, software</span>
|
|
<a name="line-10"></a><span class='hs-comment'>-- distributed under the License is distributed on an "AS IS" BASIS,</span>
|
|
<a name="line-11"></a><span class='hs-comment'>-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
|
|
<a name="line-12"></a><span class='hs-comment'>-- See the License for the specific language governing permissions and</span>
|
|
<a name="line-13"></a><span class='hs-comment'>-- limitations under the License.</span>
|
|
<a name="line-14"></a>
|
|
<a name="line-15"></a><span class='hs-comment'>{-# LANGUAGE DeriveDataTypeable #-}</span>
|
|
<a name="line-16"></a><span class='hs-comment'>{-# LANGUAGE OverloadedStrings #-}</span>
|
|
<a name="line-17"></a>
|
|
<a name="line-18"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span><span class='hs-varop'>.</span><span class='hs-conid'>FFI</span>
|
|
<a name="line-19"></a> <span class='hs-layout'>(</span> <span class='hs-conid'>TensorFlowException</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span>
|
|
<a name="line-20"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Session</span>
|
|
<a name="line-21"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>withSession</span>
|
|
<a name="line-22"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>extendGraph</span>
|
|
<a name="line-23"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>run</span>
|
|
<a name="line-24"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>TensorData</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span>
|
|
<a name="line-25"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>setSessionConfig</span>
|
|
<a name="line-26"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>setSessionTarget</span>
|
|
<a name="line-27"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>getAllOpList</span>
|
|
<a name="line-28"></a> <span class='hs-comment'>-- * Internal helper.</span>
|
|
<a name="line-29"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>useProtoAsVoidPtrLen</span>
|
|
<a name="line-30"></a> <span class='hs-layout'>)</span>
|
|
<a name="line-31"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-32"></a>
|
|
<a name="line-33"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Concurrent</span><span class='hs-varop'>.</span><span class='hs-conid'>Async</span> <span class='hs-layout'>(</span><span class='hs-conid'>Async</span><span class='hs-layout'>,</span> <span class='hs-varid'>async</span><span class='hs-layout'>,</span> <span class='hs-varid'>cancel</span><span class='hs-layout'>,</span> <span class='hs-varid'>waitCatch</span><span class='hs-layout'>)</span>
|
|
<a name="line-34"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Concurrent</span><span class='hs-varop'>.</span><span class='hs-conid'>MVar</span> <span class='hs-layout'>(</span><span class='hs-conid'>MVar</span><span class='hs-layout'>,</span> <span class='hs-varid'>modifyMVarMasked_</span><span class='hs-layout'>,</span> <span class='hs-varid'>newMVar</span><span class='hs-layout'>,</span> <span class='hs-varid'>takeMVar</span><span class='hs-layout'>)</span>
|
|
<a name="line-35"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Exception</span> <span class='hs-layout'>(</span><span class='hs-conid'>Exception</span><span class='hs-layout'>,</span> <span class='hs-varid'>throwIO</span><span class='hs-layout'>,</span> <span class='hs-varid'>bracket</span><span class='hs-layout'>,</span> <span class='hs-varid'>finally</span><span class='hs-layout'>,</span> <span class='hs-varid'>mask_</span><span class='hs-layout'>)</span>
|
|
<a name="line-36"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span> <span class='hs-layout'>(</span><span class='hs-varid'>when</span><span class='hs-layout'>)</span>
|
|
<a name="line-37"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Int</span> <span class='hs-layout'>(</span><span class='hs-conid'>Int64</span><span class='hs-layout'>)</span>
|
|
<a name="line-38"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Typeable</span> <span class='hs-layout'>(</span><span class='hs-conid'>Typeable</span><span class='hs-layout'>)</span>
|
|
<a name="line-39"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Word</span> <span class='hs-layout'>(</span><span class='hs-conid'>Word8</span><span class='hs-layout'>)</span>
|
|
<a name="line-40"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span><span class='hs-layout'>,</span> <span class='hs-conid'>FunPtr</span><span class='hs-layout'>,</span> <span class='hs-varid'>nullPtr</span><span class='hs-layout'>,</span> <span class='hs-varid'>castPtr</span><span class='hs-layout'>)</span>
|
|
<a name="line-41"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>C</span><span class='hs-varop'>.</span><span class='hs-conid'>String</span> <span class='hs-layout'>(</span><span class='hs-conid'>CString</span><span class='hs-layout'>)</span>
|
|
<a name="line-42"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>ForeignPtr</span> <span class='hs-layout'>(</span><span class='hs-varid'>newForeignPtr</span><span class='hs-layout'>,</span> <span class='hs-varid'>withForeignPtr</span><span class='hs-layout'>)</span>
|
|
<a name="line-43"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Marshal</span><span class='hs-varop'>.</span><span class='hs-conid'>Alloc</span> <span class='hs-layout'>(</span><span class='hs-varid'>free</span><span class='hs-layout'>)</span>
|
|
<a name="line-44"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Marshal</span><span class='hs-varop'>.</span><span class='hs-conid'>Array</span> <span class='hs-layout'>(</span><span class='hs-varid'>withArrayLen</span><span class='hs-layout'>,</span> <span class='hs-varid'>peekArray</span><span class='hs-layout'>,</span> <span class='hs-varid'>mallocArray</span><span class='hs-layout'>,</span> <span class='hs-varid'>copyArray</span><span class='hs-layout'>)</span>
|
|
<a name="line-45"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-conid'>Unsafe</span> <span class='hs-layout'>(</span><span class='hs-varid'>unsafePerformIO</span><span class='hs-layout'>)</span>
|
|
<a name="line-46"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>B</span>
|
|
<a name="line-47"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>T</span>
|
|
<a name="line-48"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span><span class='hs-varop'>.</span><span class='hs-conid'>Encoding</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>T</span>
|
|
<a name="line-49"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span><span class='hs-varop'>.</span><span class='hs-conid'>Encoding</span><span class='hs-varop'>.</span><span class='hs-conid'>Error</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>T</span>
|
|
<a name="line-50"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-conid'>Storable</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>S</span>
|
|
<a name="line-51"></a>
|
|
<a name="line-52"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ProtoLens</span> <span class='hs-layout'>(</span><span class='hs-conid'>Message</span><span class='hs-layout'>,</span> <span class='hs-varid'>encodeMessage</span><span class='hs-layout'>)</span>
|
|
<a name="line-53"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Proto</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensorflow</span><span class='hs-varop'>.</span><span class='hs-conid'>Core</span><span class='hs-varop'>.</span><span class='hs-conid'>Framework</span><span class='hs-varop'>.</span><span class='hs-conid'>Graph</span> <span class='hs-layout'>(</span><span class='hs-conid'>GraphDef</span><span class='hs-layout'>)</span>
|
|
<a name="line-54"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Proto</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensorflow</span><span class='hs-varop'>.</span><span class='hs-conid'>Core</span><span class='hs-varop'>.</span><span class='hs-conid'>Framework</span><span class='hs-varop'>.</span><span class='hs-conid'>Types</span> <span class='hs-layout'>(</span><span class='hs-conid'>DataType</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
|
|
<a name="line-55"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Proto</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensorflow</span><span class='hs-varop'>.</span><span class='hs-conid'>Core</span><span class='hs-varop'>.</span><span class='hs-conid'>Protobuf</span><span class='hs-varop'>.</span><span class='hs-conid'>Config</span> <span class='hs-layout'>(</span><span class='hs-conid'>ConfigProto</span><span class='hs-layout'>)</span>
|
|
<a name="line-56"></a>
|
|
<a name="line-57"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span><span class='hs-varop'>.</span><span class='hs-conid'>Raw</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Raw</span>
|
|
<a name="line-58"></a>
|
|
<a name="line-59"></a><a name="TensorFlowException"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>TensorFlowException</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>TensorFlowException</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Code</span> <span class='hs-conid'>T</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span>
|
|
<a name="line-60"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Show</span><span class='hs-layout'>,</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>,</span> <span class='hs-conid'>Typeable</span><span class='hs-layout'>)</span>
|
|
<a name="line-61"></a>
|
|
<a name="line-62"></a><a name="instance%20Exception%20TensorFlowException"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Exception</span> <span class='hs-conid'>TensorFlowException</span>
|
|
<a name="line-63"></a>
|
|
<a name="line-64"></a><a name="TensorData"></a><span class='hs-comment'>-- | All of the data needed to represent a tensor.</span>
|
|
<a name="line-65"></a><a name="TensorData"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>TensorData</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>TensorData</span>
|
|
<a name="line-66"></a> <span class='hs-layout'>{</span> <span class='hs-varid'>tensorDataDimensions</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Int64</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-67"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>tensorDataType</span> <span class='hs-keyglyph'>::</span> <span class='hs-varop'>!</span><span class='hs-conid'>DataType</span>
|
|
<a name="line-68"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>tensorDataBytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-varop'>!</span><span class='hs-layout'>(</span><span class='hs-conid'>S</span><span class='hs-varop'>.</span><span class='hs-conid'>Vector</span> <span class='hs-conid'>Word8</span><span class='hs-layout'>)</span>
|
|
<a name="line-69"></a> <span class='hs-layout'>}</span>
|
|
<a name="line-70"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Show</span><span class='hs-layout'>,</span> <span class='hs-conid'>Eq</span><span class='hs-layout'>)</span>
|
|
<a name="line-71"></a>
|
|
<a name="line-72"></a><a name="withSession"></a><span class='hs-comment'>-- | Runs the given action after creating a session with options</span>
|
|
<a name="line-73"></a><span class='hs-comment'>-- populated by the given optionSetter.</span>
|
|
<a name="line-74"></a><span class='hs-definition'>withSession</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>SessionOptions</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span><span class='hs-layout'>)</span>
|
|
<a name="line-75"></a> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-conid'>IO</span> <span class='hs-conid'>()</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Session</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
|
|
<a name="line-76"></a> <span class='hs-comment'>-- ^ The action can spawn concurrent tasks which will</span>
|
|
<a name="line-77"></a> <span class='hs-comment'>-- be canceled before withSession returns.</span>
|
|
<a name="line-78"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
|
|
<a name="line-79"></a><span class='hs-definition'>withSession</span> <span class='hs-varid'>optionSetter</span> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-80"></a> <span class='hs-varid'>drain</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newMVar</span> <span class='hs-conid'>[]</span>
|
|
<a name="line-81"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>cleanup</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-82"></a> <span class='hs-comment'>-- Closes the session to nudge the pending run calls to fail and exit.</span>
|
|
<a name="line-83"></a> <span class='hs-varid'>finally</span> <span class='hs-layout'>(</span><span class='hs-varid'>checkStatus</span> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>closeSession</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-84"></a> <span class='hs-varid'>runners</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>takeMVar</span> <span class='hs-varid'>drain</span>
|
|
<a name="line-85"></a> <span class='hs-comment'>-- Collects all runners before deleting the session.</span>
|
|
<a name="line-86"></a> <span class='hs-varid'>mapM_</span> <span class='hs-varid'>shutDownRunner</span> <span class='hs-varid'>runners</span>
|
|
<a name="line-87"></a> <span class='hs-varid'>checkStatus</span> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>deleteSession</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span>
|
|
<a name="line-88"></a> <span class='hs-varid'>bracket</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>newSessionOptions</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>deleteSessionOptions</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>options</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
|
|
<a name="line-89"></a> <span class='hs-varid'>optionSetter</span> <span class='hs-varid'>options</span>
|
|
<a name="line-90"></a> <span class='hs-varid'>bracket</span>
|
|
<a name="line-91"></a> <span class='hs-layout'>(</span><span class='hs-varid'>checkStatus</span> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>newSession</span> <span class='hs-varid'>options</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
|
|
<a name="line-92"></a> <span class='hs-varid'>cleanup</span>
|
|
<a name="line-93"></a> <span class='hs-layout'>(</span><span class='hs-varid'>action</span> <span class='hs-layout'>(</span><span class='hs-varid'>asyncCollector</span> <span class='hs-varid'>drain</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
|
|
<a name="line-94"></a>
|
|
<a name="line-95"></a><a name="asyncCollector"></a><span class='hs-definition'>asyncCollector</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MVar</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Async</span> <span class='hs-conid'>()</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
|
|
<a name="line-96"></a><span class='hs-definition'>asyncCollector</span> <span class='hs-varid'>drain</span> <span class='hs-varid'>runner</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>modifyMVarMasked_</span> <span class='hs-varid'>drain</span> <span class='hs-varid'>launchAndRecord</span>
|
|
<a name="line-97"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-98"></a> <span class='hs-varid'>launchAndRecord</span> <span class='hs-varid'>restRunners</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conop'>:</span> <span class='hs-varid'>restRunners</span><span class='hs-layout'>)</span> <span class='hs-varop'><$></span> <span class='hs-varid'>async</span> <span class='hs-varid'>runner</span>
|
|
<a name="line-99"></a>
|
|
<a name="line-100"></a><a name="shutDownRunner"></a><span class='hs-definition'>shutDownRunner</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Async</span> <span class='hs-conid'>()</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
|
|
<a name="line-101"></a><span class='hs-definition'>shutDownRunner</span> <span class='hs-varid'>r</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-102"></a> <span class='hs-varid'>cancel</span> <span class='hs-varid'>r</span>
|
|
<a name="line-103"></a> <span class='hs-comment'>-- TODO(gnezdo): manage exceptions better than print.</span>
|
|
<a name="line-104"></a> <span class='hs-varid'>either</span> <span class='hs-varid'>print</span> <span class='hs-layout'>(</span><span class='hs-varid'>const</span> <span class='hs-layout'>(</span><span class='hs-varid'>return</span> <span class='hs-conid'>()</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varop'>=<<</span> <span class='hs-varid'>waitCatch</span> <span class='hs-varid'>r</span>
|
|
<a name="line-105"></a>
|
|
<a name="line-106"></a><a name="extendGraph"></a><span class='hs-definition'>extendGraph</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Session</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GraphDef</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
|
|
<a name="line-107"></a><span class='hs-definition'>extendGraph</span> <span class='hs-varid'>session</span> <span class='hs-varid'>pb</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-108"></a> <span class='hs-varid'>useProtoAsVoidPtrLen</span> <span class='hs-varid'>pb</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ptr</span> <span class='hs-varid'>len</span> <span class='hs-keyglyph'>-></span>
|
|
<a name="line-109"></a> <span class='hs-varid'>checkStatus</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>extendGraph</span> <span class='hs-varid'>session</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>len</span>
|
|
<a name="line-110"></a>
|
|
<a name="line-111"></a>
|
|
<a name="line-112"></a><a name="run"></a><span class='hs-definition'>run</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Session</span>
|
|
<a name="line-113"></a> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-layout'>,</span> <span class='hs-conid'>TensorData</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- ^ Feeds.</span>
|
|
<a name="line-114"></a> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- ^ Fetches.</span>
|
|
<a name="line-115"></a> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- ^ Targets.</span>
|
|
<a name="line-116"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>TensorData</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-117"></a><span class='hs-definition'>run</span> <span class='hs-varid'>session</span> <span class='hs-varid'>feeds</span> <span class='hs-varid'>fetches</span> <span class='hs-varid'>targets</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-118"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>nullTensor</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>nullPtr</span>
|
|
<a name="line-119"></a> <span class='hs-comment'>-- Use mask to avoid leaking input tensors before they are passed to 'run'</span>
|
|
<a name="line-120"></a> <span class='hs-comment'>-- and output tensors before they are passed to 'createTensorData'.</span>
|
|
<a name="line-121"></a> <span class='hs-varid'>mask_</span> <span class='hs-varop'>$</span>
|
|
<a name="line-122"></a> <span class='hs-comment'>-- Feeds</span>
|
|
<a name="line-123"></a> <span class='hs-varid'>withStringArrayLen</span> <span class='hs-layout'>(</span><span class='hs-varid'>fst</span> <span class='hs-varop'><$></span> <span class='hs-varid'>feeds</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>feedsLen</span> <span class='hs-varid'>feedNames</span> <span class='hs-keyglyph'>-></span>
|
|
<a name="line-124"></a> <span class='hs-varid'>mapM</span> <span class='hs-layout'>(</span><span class='hs-varid'>createRawTensor</span> <span class='hs-varop'>.</span> <span class='hs-varid'>snd</span><span class='hs-layout'>)</span> <span class='hs-varid'>feeds</span> <span class='hs-varop'>>>=</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>feedTensors</span> <span class='hs-keyglyph'>-></span>
|
|
<a name="line-125"></a> <span class='hs-varid'>withArrayLen</span> <span class='hs-varid'>feedTensors</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-keyword'>_</span> <span class='hs-varid'>cFeedTensors</span> <span class='hs-keyglyph'>-></span>
|
|
<a name="line-126"></a> <span class='hs-comment'>-- Fetches.</span>
|
|
<a name="line-127"></a> <span class='hs-varid'>withStringArrayLen</span> <span class='hs-varid'>fetches</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>fetchesLen</span> <span class='hs-varid'>fetchNames</span> <span class='hs-keyglyph'>-></span>
|
|
<a name="line-128"></a> <span class='hs-comment'>-- tensorOuts is an array of null Tensor pointers that will be filled</span>
|
|
<a name="line-129"></a> <span class='hs-comment'>-- by the call to Raw.run.</span>
|
|
<a name="line-130"></a> <span class='hs-varid'>withArrayLen</span> <span class='hs-layout'>(</span><span class='hs-varid'>replicate</span> <span class='hs-varid'>fetchesLen</span> <span class='hs-varid'>nullTensor</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-keyword'>_</span> <span class='hs-varid'>tensorOuts</span> <span class='hs-keyglyph'>-></span>
|
|
<a name="line-131"></a> <span class='hs-comment'>-- Targets.</span>
|
|
<a name="line-132"></a> <span class='hs-varid'>withStringArrayLen</span> <span class='hs-varid'>targets</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>targetsLen</span> <span class='hs-varid'>ctargets</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
|
|
<a name="line-133"></a> <span class='hs-varid'>checkStatus</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>run</span>
|
|
<a name="line-134"></a> <span class='hs-varid'>session</span>
|
|
<a name="line-135"></a> <span class='hs-varid'>nullPtr</span>
|
|
<a name="line-136"></a> <span class='hs-varid'>feedNames</span> <span class='hs-varid'>cFeedTensors</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>feedsLen</span><span class='hs-layout'>)</span>
|
|
<a name="line-137"></a> <span class='hs-varid'>fetchNames</span> <span class='hs-varid'>tensorOuts</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>fetchesLen</span><span class='hs-layout'>)</span>
|
|
<a name="line-138"></a> <span class='hs-varid'>ctargets</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>targetsLen</span><span class='hs-layout'>)</span>
|
|
<a name="line-139"></a> <span class='hs-varid'>nullPtr</span>
|
|
<a name="line-140"></a> <span class='hs-varid'>outTensors</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>peekArray</span> <span class='hs-varid'>fetchesLen</span> <span class='hs-varid'>tensorOuts</span>
|
|
<a name="line-141"></a> <span class='hs-varid'>mapM</span> <span class='hs-varid'>createTensorData</span> <span class='hs-varid'>outTensors</span>
|
|
<a name="line-142"></a>
|
|
<a name="line-143"></a>
|
|
<a name="line-144"></a><span class='hs-comment'>-- Internal.</span>
|
|
<a name="line-145"></a>
|
|
<a name="line-146"></a>
|
|
<a name="line-147"></a><a name="withStringList"></a><span class='hs-comment'>-- | Use a list of ByteString as a list of CString.</span>
|
|
<a name="line-148"></a><span class='hs-definition'>withStringList</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>CString</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
|
|
<a name="line-149"></a><span class='hs-definition'>withStringList</span> <span class='hs-varid'>strings</span> <span class='hs-varid'>fn</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>go</span> <span class='hs-varid'>strings</span> <span class='hs-conid'>[]</span>
|
|
<a name="line-150"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-151"></a> <span class='hs-varid'>go</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>cs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fn</span> <span class='hs-layout'>(</span><span class='hs-varid'>reverse</span> <span class='hs-varid'>cs</span><span class='hs-layout'>)</span>
|
|
<a name="line-152"></a> <span class='hs-comment'>-- TODO(fmayle): Is it worth using unsafeAsCString here?</span>
|
|
<a name="line-153"></a> <span class='hs-varid'>go</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-varid'>cs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-varid'>useAsCString</span> <span class='hs-varid'>x</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>c</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>go</span> <span class='hs-varid'>xs</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span><span class='hs-conop'>:</span><span class='hs-varid'>cs</span><span class='hs-layout'>)</span>
|
|
<a name="line-154"></a>
|
|
<a name="line-155"></a>
|
|
<a name="line-156"></a><a name="withStringArrayLen"></a><span class='hs-comment'>-- | Use a list of ByteString as an array of CString.</span>
|
|
<a name="line-157"></a><span class='hs-definition'>withStringArrayLen</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ptr</span> <span class='hs-conid'>CString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
|
|
<a name="line-158"></a><span class='hs-definition'>withStringArrayLen</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>fn</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>withStringList</span> <span class='hs-varid'>xs</span> <span class='hs-layout'>(</span><span class='hs-varop'>`withArrayLen`</span> <span class='hs-varid'>fn</span><span class='hs-layout'>)</span>
|
|
<a name="line-159"></a>
|
|
<a name="line-160"></a>
|
|
<a name="line-161"></a><a name="createRawTensor"></a><span class='hs-comment'>-- | Create a Raw.Tensor from a TensorData.</span>
|
|
<a name="line-162"></a><span class='hs-definition'>createRawTensor</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TensorData</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensor</span>
|
|
<a name="line-163"></a><span class='hs-definition'>createRawTensor</span> <span class='hs-layout'>(</span><span class='hs-conid'>TensorData</span> <span class='hs-varid'>dims</span> <span class='hs-varid'>dt</span> <span class='hs-varid'>byteVec</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-164"></a> <span class='hs-varid'>withArrayLen</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>dims</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>cdimsLen</span> <span class='hs-varid'>cdims</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
|
|
<a name="line-165"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>len</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>S</span><span class='hs-varop'>.</span><span class='hs-varid'>length</span> <span class='hs-varid'>byteVec</span>
|
|
<a name="line-166"></a> <span class='hs-varid'>dest</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mallocArray</span> <span class='hs-varid'>len</span>
|
|
<a name="line-167"></a> <span class='hs-conid'>S</span><span class='hs-varop'>.</span><span class='hs-varid'>unsafeWith</span> <span class='hs-varid'>byteVec</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>x</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>copyArray</span> <span class='hs-varid'>dest</span> <span class='hs-varid'>x</span> <span class='hs-varid'>len</span>
|
|
<a name="line-168"></a> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>newTensor</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varop'>$</span> <span class='hs-varid'>fromEnum</span> <span class='hs-varid'>dt</span><span class='hs-layout'>)</span>
|
|
<a name="line-169"></a> <span class='hs-varid'>cdims</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>cdimsLen</span><span class='hs-layout'>)</span>
|
|
<a name="line-170"></a> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>dest</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>len</span><span class='hs-layout'>)</span>
|
|
<a name="line-171"></a> <span class='hs-varid'>tensorDeallocFunPtr</span> <span class='hs-varid'>nullPtr</span>
|
|
<a name="line-172"></a>
|
|
<a name="line-173"></a><a name="tensorDeallocFunPtr"></a><span class='hs-comment'>{-# NOINLINE tensorDeallocFunPtr #-}</span>
|
|
<a name="line-174"></a><span class='hs-definition'>tensorDeallocFunPtr</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>FunPtr</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>TensorDeallocFn</span>
|
|
<a name="line-175"></a><span class='hs-definition'>tensorDeallocFunPtr</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafePerformIO</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>wrapTensorDealloc</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>x</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>free</span> <span class='hs-varid'>x</span>
|
|
<a name="line-176"></a>
|
|
<a name="line-177"></a><a name="createTensorData"></a><span class='hs-comment'>-- | Create a TensorData from a Raw.Tensor.</span>
|
|
<a name="line-178"></a><span class='hs-comment'>--</span>
|
|
<a name="line-179"></a><span class='hs-comment'>-- Takes ownership of the Raw.Tensor.</span>
|
|
<a name="line-180"></a><span class='hs-definition'>createTensorData</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensor</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>TensorData</span>
|
|
<a name="line-181"></a><span class='hs-definition'>createTensorData</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-182"></a> <span class='hs-comment'>-- Read dimensions.</span>
|
|
<a name="line-183"></a> <span class='hs-varid'>numDims</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>numDims</span> <span class='hs-varid'>t</span>
|
|
<a name="line-184"></a> <span class='hs-varid'>dims</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mapM</span> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>dim</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0</span><span class='hs-keyglyph'>..</span><span class='hs-varid'>numDims</span><span class='hs-comment'>-</span><span class='hs-num'>1</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-185"></a> <span class='hs-comment'>-- Read type.</span>
|
|
<a name="line-186"></a> <span class='hs-varid'>dtype</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>toEnum</span> <span class='hs-varop'>.</span> <span class='hs-varid'>fromEnum</span> <span class='hs-varop'><$></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>tensorType</span> <span class='hs-varid'>t</span>
|
|
<a name="line-187"></a> <span class='hs-comment'>-- Read data.</span>
|
|
<a name="line-188"></a> <span class='hs-varid'>len</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>fromIntegral</span> <span class='hs-varop'><$></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>tensorByteSize</span> <span class='hs-varid'>t</span>
|
|
<a name="line-189"></a> <span class='hs-varid'>bytes</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>castPtr</span> <span class='hs-varop'><$></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>tensorData</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>IO</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-conid'>Word8</span><span class='hs-layout'>)</span>
|
|
<a name="line-190"></a> <span class='hs-comment'>-- TODO(fmayle): Don't copy the data.</span>
|
|
<a name="line-191"></a> <span class='hs-varid'>v</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>S</span><span class='hs-varop'>.</span><span class='hs-varid'>fromList</span> <span class='hs-varop'><$></span> <span class='hs-varid'>peekArray</span> <span class='hs-varid'>len</span> <span class='hs-varid'>bytes</span>
|
|
<a name="line-192"></a> <span class='hs-comment'>-- Free tensor.</span>
|
|
<a name="line-193"></a> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>deleteTensor</span> <span class='hs-varid'>t</span>
|
|
<a name="line-194"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-conid'>TensorData</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>dims</span><span class='hs-layout'>)</span> <span class='hs-varid'>dtype</span> <span class='hs-varid'>v</span>
|
|
<a name="line-195"></a>
|
|
<a name="line-196"></a><a name="checkStatus"></a><span class='hs-comment'>-- | Runs the given action which does FFI calls updating a provided</span>
|
|
<a name="line-197"></a><span class='hs-comment'>-- status object. If the status is not OK it is thrown as</span>
|
|
<a name="line-198"></a><span class='hs-comment'>-- TensorFlowException.</span>
|
|
<a name="line-199"></a><span class='hs-definition'>checkStatus</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>Status</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
|
|
<a name="line-200"></a><span class='hs-definition'>checkStatus</span> <span class='hs-varid'>fn</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-201"></a> <span class='hs-varid'>bracket</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>newStatus</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>deleteStatus</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>status</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
|
|
<a name="line-202"></a> <span class='hs-varid'>result</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>fn</span> <span class='hs-varid'>status</span>
|
|
<a name="line-203"></a> <span class='hs-varid'>code</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>getCode</span> <span class='hs-varid'>status</span>
|
|
<a name="line-204"></a> <span class='hs-varid'>when</span> <span class='hs-layout'>(</span><span class='hs-varid'>code</span> <span class='hs-varop'>/=</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>TF_OK</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-205"></a> <span class='hs-varid'>msg</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>T</span><span class='hs-varop'>.</span><span class='hs-varid'>decodeUtf8With</span> <span class='hs-conid'>T</span><span class='hs-varop'>.</span><span class='hs-varid'>lenientDecode</span> <span class='hs-varop'><$></span>
|
|
<a name="line-206"></a> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>message</span> <span class='hs-varid'>status</span> <span class='hs-varop'>>>=</span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-varid'>packCString</span><span class='hs-layout'>)</span>
|
|
<a name="line-207"></a> <span class='hs-varid'>throwIO</span> <span class='hs-varop'>$</span> <span class='hs-conid'>TensorFlowException</span> <span class='hs-varid'>code</span> <span class='hs-varid'>msg</span>
|
|
<a name="line-208"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>result</span>
|
|
<a name="line-209"></a>
|
|
<a name="line-210"></a><a name="setSessionConfig"></a><span class='hs-definition'>setSessionConfig</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ConfigProto</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>SessionOptions</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
|
|
<a name="line-211"></a><span class='hs-definition'>setSessionConfig</span> <span class='hs-varid'>pb</span> <span class='hs-varid'>opt</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-212"></a> <span class='hs-varid'>useProtoAsVoidPtrLen</span> <span class='hs-varid'>pb</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ptr</span> <span class='hs-varid'>len</span> <span class='hs-keyglyph'>-></span>
|
|
<a name="line-213"></a> <span class='hs-varid'>checkStatus</span> <span class='hs-layout'>(</span><span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>setConfig</span> <span class='hs-varid'>opt</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>len</span><span class='hs-layout'>)</span>
|
|
<a name="line-214"></a>
|
|
<a name="line-215"></a><a name="setSessionTarget"></a><span class='hs-definition'>setSessionTarget</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>SessionOptions</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
|
|
<a name="line-216"></a><span class='hs-definition'>setSessionTarget</span> <span class='hs-varid'>target</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-varid'>useAsCString</span> <span class='hs-varid'>target</span> <span class='hs-varop'>.</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>setTarget</span>
|
|
<a name="line-217"></a>
|
|
<a name="line-218"></a><a name="useProtoAsVoidPtrLen"></a><span class='hs-comment'>-- | Serializes the given msg and provides it as (ptr,len) argument</span>
|
|
<a name="line-219"></a><span class='hs-comment'>-- to the given action.</span>
|
|
<a name="line-220"></a><span class='hs-definition'>useProtoAsVoidPtrLen</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Message</span> <span class='hs-varid'>msg</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span>
|
|
<a name="line-221"></a> <span class='hs-varid'>msg</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-varid'>a</span>
|
|
<a name="line-222"></a><span class='hs-definition'>useProtoAsVoidPtrLen</span> <span class='hs-varid'>msg</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-varid'>useAsCStringLen</span> <span class='hs-layout'>(</span><span class='hs-varid'>encodeMessage</span> <span class='hs-varid'>msg</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
|
|
<a name="line-223"></a> <span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>bytes</span><span class='hs-layout'>,</span> <span class='hs-varid'>len</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varid'>bytes</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>len</span><span class='hs-layout'>)</span>
|
|
<a name="line-224"></a>
|
|
<a name="line-225"></a><a name="getAllOpList"></a><span class='hs-comment'>-- | Returns the serialized OpList of all OpDefs defined in this</span>
|
|
<a name="line-226"></a><span class='hs-comment'>-- address space.</span>
|
|
<a name="line-227"></a><span class='hs-definition'>getAllOpList</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>IO</span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span>
|
|
<a name="line-228"></a><span class='hs-definition'>getAllOpList</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-229"></a> <span class='hs-varid'>foreignPtr</span> <span class='hs-keyglyph'><-</span>
|
|
<a name="line-230"></a> <span class='hs-varid'>mask_</span> <span class='hs-layout'>(</span><span class='hs-varid'>newForeignPtr</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>deleteBuffer</span> <span class='hs-varop'>=<<</span> <span class='hs-varid'>checkCall</span><span class='hs-layout'>)</span>
|
|
<a name="line-231"></a> <span class='hs-comment'>-- Makes a copy because it is more reliable than eviscerating</span>
|
|
<a name="line-232"></a> <span class='hs-comment'>-- Buffer to steal its memory (including custom deallocator).</span>
|
|
<a name="line-233"></a> <span class='hs-varid'>withForeignPtr</span> <span class='hs-varid'>foreignPtr</span> <span class='hs-varop'>$</span>
|
|
<a name="line-234"></a> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-varid'>packCStringLen</span> <span class='hs-varop'>=<<</span> <span class='hs-conid'>(,)</span>
|
|
<a name="line-235"></a> <span class='hs-varop'><$></span> <span class='hs-layout'>(</span><span class='hs-varid'>castPtr</span> <span class='hs-varop'><$></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>getBufferData</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span>
|
|
<a name="line-236"></a> <span class='hs-varop'><*></span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varop'><$></span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>getBufferLength</span> <span class='hs-varid'>ptr</span><span class='hs-layout'>)</span>
|
|
<a name="line-237"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-238"></a> <span class='hs-varid'>checkCall</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-239"></a> <span class='hs-varid'>p</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-varid'>getAllOpList</span>
|
|
<a name="line-240"></a> <span class='hs-varid'>when</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span> <span class='hs-varop'>==</span> <span class='hs-varid'>nullPtr</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>throwIO</span> <span class='hs-varid'>exception</span><span class='hs-layout'>)</span>
|
|
<a name="line-241"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>p</span>
|
|
<a name="line-242"></a> <span class='hs-varid'>exception</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>TensorFlowException</span>
|
|
<a name="line-243"></a> <span class='hs-conid'>Raw</span><span class='hs-varop'>.</span><span class='hs-conid'>TF_UNKNOWN</span> <span class='hs-str'>"GetAllOpList failure, check logs"</span>
|
|
</pre></body>
|
|
</html>
|