2016-10-24 19:26:42 +00:00
|
|
|
-- Copyright 2016 TensorFlow authors.
|
|
|
|
--
|
|
|
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
-- you may not use this file except in compliance with the License.
|
|
|
|
-- You may obtain a copy of the License at
|
|
|
|
--
|
|
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
--
|
|
|
|
-- Unless required by applicable law or agreed to in writing, software
|
|
|
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
-- See the License for the specific language governing permissions and
|
|
|
|
-- limitations under the License.
|
|
|
|
|
|
|
|
{-# LANGUAGE GADTs #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE RankNTypes #-}
|
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
|
|
|
|
|
|
module TensorFlow.ControlFlow
|
|
|
|
( -- * Dependencies
|
|
|
|
withControlDependencies
|
|
|
|
, group
|
|
|
|
-- * Operations
|
|
|
|
, noOp
|
|
|
|
) where
|
|
|
|
|
|
|
|
import TensorFlow.BuildOp
|
|
|
|
import TensorFlow.Build
|
|
|
|
import TensorFlow.Nodes
|
|
|
|
|
|
|
|
-- | Modify a 'Build' action, such that all new ops rendered in it will depend
|
|
|
|
-- on the nodes in the first argument.
|
2017-03-18 12:08:53 -07:00
|
|
|
withControlDependencies :: (MonadBuild m, Nodes t) => t -> m a -> m a
|
2016-10-24 19:26:42 +00:00
|
|
|
withControlDependencies deps act = do
|
2017-03-18 12:08:53 -07:00
|
|
|
nodes <- build $ getNodes deps
|
2016-10-24 19:26:42 +00:00
|
|
|
withNodeDependencies nodes act
|
|
|
|
|
|
|
|
-- TODO(judahjacobson): Reimplement withDependencies.
|
|
|
|
|
|
|
|
-- | Create an op that groups multiple operations.
|
|
|
|
--
|
|
|
|
-- When this op finishes, all ops in the input @n@ have finished. This op has
|
|
|
|
-- no output.
|
2017-03-18 12:08:53 -07:00
|
|
|
group :: (MonadBuild m, Nodes t) => t -> m ControlNode
|
2017-04-06 15:10:33 -07:00
|
|
|
group deps = withControlDependencies deps noOp
|
2016-10-24 19:26:42 +00:00
|
|
|
|
|
|
|
-- | Does nothing. Only useful as a placeholder for control edges.
|
2017-04-06 15:10:33 -07:00
|
|
|
noOp :: MonadBuild m => m ControlNode
|
|
|
|
noOp = build $ buildOp [] $ opDef "NoOp"
|