2016-10-24 21:26:42 +02: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.
|
2017-08-08 18:48:59 +02:00
|
|
|
{-# LANGUAGE CPP #-}
|
2016-10-24 21:26:42 +02:00
|
|
|
|
2017-02-09 23:20:43 +01:00
|
|
|
-- | Generates the wrappers for Ops shipped with tensorflow.
|
2016-10-24 21:26:42 +02:00
|
|
|
module Main where
|
|
|
|
|
2017-05-11 01:29:31 +02:00
|
|
|
import Distribution.PackageDescription
|
|
|
|
( PackageDescription(..)
|
|
|
|
, libBuildInfo
|
|
|
|
, hsSourceDirs
|
|
|
|
)
|
2017-08-08 18:48:59 +02:00
|
|
|
import qualified Distribution.Simple.BuildPaths as BuildPaths
|
2016-10-24 21:26:42 +02:00
|
|
|
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo)
|
|
|
|
import Distribution.Simple
|
|
|
|
( defaultMainWithHooks
|
|
|
|
, simpleUserHooks
|
|
|
|
, UserHooks(..)
|
|
|
|
)
|
|
|
|
import Data.List (intercalate)
|
|
|
|
import Data.ProtoLens (decodeMessage)
|
|
|
|
import System.Directory (createDirectoryIfMissing)
|
|
|
|
import System.Exit (exitFailure)
|
|
|
|
import System.FilePath ((</>))
|
|
|
|
import System.IO (hPutStrLn, stderr)
|
|
|
|
import TensorFlow.Internal.FFI (getAllOpList)
|
|
|
|
import TensorFlow.OpGen (docOpList, OpGenFlags(..))
|
|
|
|
import Text.PrettyPrint.Mainland (prettyLazyText)
|
|
|
|
import qualified Data.Text.Lazy.IO as Text
|
|
|
|
|
|
|
|
main = defaultMainWithHooks generatingOpsWrappers
|
|
|
|
|
|
|
|
-- TODO: Generalize for user libraries by replacing getAllOpList with
|
|
|
|
-- a wrapper around TF_LoadLibrary. The complicated part is interplay
|
|
|
|
-- between bazel and Haskell build system.
|
|
|
|
generatingOpsWrappers :: UserHooks
|
|
|
|
generatingOpsWrappers = hooks
|
|
|
|
{ buildHook = \p l h f -> generateSources l >> buildHook hooks p l h f
|
|
|
|
, haddockHook = \p l h f -> generateSources l >> haddockHook hooks p l h f
|
|
|
|
, replHook = \p l h f args -> generateSources l
|
|
|
|
>> replHook hooks p l h f args
|
|
|
|
}
|
|
|
|
where
|
|
|
|
flagsBuilder dir = OpGenFlags
|
|
|
|
{ outputFile = dir </> "Core.hs"
|
|
|
|
, prefix = "TensorFlow.GenOps"
|
|
|
|
, excludeList = intercalate "," blackList
|
|
|
|
}
|
|
|
|
hooks = simpleUserHooks
|
|
|
|
generateSources :: LocalBuildInfo -> IO ()
|
|
|
|
generateSources l = do
|
|
|
|
let dir = autogenModulesDir l </> "TensorFlow/GenOps"
|
|
|
|
createDirectoryIfMissing True dir
|
|
|
|
let flags = flagsBuilder dir
|
|
|
|
pb <- getAllOpList
|
|
|
|
case decodeMessage pb of
|
|
|
|
Left e -> hPutStrLn stderr e >> exitFailure
|
|
|
|
Right x -> Text.writeFile (outputFile flags)
|
|
|
|
(prettyLazyText 80 $ docOpList flags x)
|
|
|
|
|
2017-05-11 01:29:31 +02:00
|
|
|
-- | Add the autogen directory to the hs-source-dirs of all the targets in the
|
|
|
|
-- .cabal file. Used to fool 'sdist' by pointing it to the generated source
|
|
|
|
-- files.
|
|
|
|
fudgePackageDesc
|
|
|
|
:: LocalBuildInfo -> PackageDescription -> PackageDescription
|
|
|
|
fudgePackageDesc lbi p = p
|
|
|
|
{ library =
|
|
|
|
(\lib -> lib { libBuildInfo = fudgeBuildInfo (libBuildInfo lib) })
|
|
|
|
<$> library p
|
|
|
|
}
|
|
|
|
where
|
|
|
|
fudgeBuildInfo bi =
|
|
|
|
bi { hsSourceDirs = autogenModulesDir lbi : hsSourceDirs bi }
|
|
|
|
|
2016-10-24 21:26:42 +02:00
|
|
|
blackList =
|
2017-03-17 21:53:19 +01:00
|
|
|
[ -- Requires the "func" type:
|
2017-10-19 19:41:55 +02:00
|
|
|
"FilterDataset"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "BatchFunction"
|
|
|
|
, "Case"
|
|
|
|
, "ChooseFastestBranchDataset"
|
|
|
|
, "ExperimentalGroupByReducerDataset"
|
|
|
|
, "ExperimentalGroupByWindowDataset"
|
|
|
|
, "ExperimentalMapAndBatchDataset"
|
|
|
|
, "ExperimentalMapDataset"
|
|
|
|
, "ExperimentalNumaMapAndBatchDataset"
|
|
|
|
, "ExperimentalParallelInterleaveDataset"
|
|
|
|
, "ExperimentalScanDataset"
|
|
|
|
, "ExperimentalTakeWhileDataset"
|
|
|
|
, "FilterDataset"
|
2017-10-19 19:41:55 +02:00
|
|
|
, "FlatMapDataset"
|
2018-05-14 21:55:33 +02:00
|
|
|
, "For"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "GeneratorDataset"
|
2018-07-24 23:17:08 +02:00
|
|
|
, "GroupByReducerDataset"
|
2017-10-19 19:41:55 +02:00
|
|
|
, "GroupByWindowDataset"
|
2018-05-14 21:55:33 +02:00
|
|
|
, "If"
|
2017-10-19 19:41:55 +02:00
|
|
|
, "InterleaveDataset"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "LegacyParallelInterleaveDatasetV2"
|
|
|
|
, "LoadDataset"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "MapAndBatchDataset"
|
2018-07-24 23:17:08 +02:00
|
|
|
, "MapAndBatchDatasetV2"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "MapDataset"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "MapDefun"
|
2017-10-19 19:41:55 +02:00
|
|
|
, "OneShotIterator"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "ParallelInterleaveDataset"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "ParallelInterleaveDatasetV2"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "ParallelInterleaveDatasetV3"
|
|
|
|
, "ParallelInterleaveDatasetV4"
|
2017-10-19 19:41:55 +02:00
|
|
|
, "ParallelMapDataset"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "ParallelMapDatasetV2"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "ParseSequenceExample"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "ParseSequenceExampleV2"
|
|
|
|
, "ParseSingleSequenceExample"
|
2018-07-24 23:17:08 +02:00
|
|
|
, "PartitionedCall"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "ReduceDataset"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "RemoteCall"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "SaveDataset"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "ScanDataset"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "SnapshotDatasetV2"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "StatefulPartitionedCall"
|
2021-02-09 18:08:46 +01:00
|
|
|
, "StatelessCase"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "StatelessIf"
|
|
|
|
, "StatelessWhile"
|
2017-10-19 19:41:55 +02:00
|
|
|
, "SymbolicGradient"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "TakeWhileDataset"
|
2021-02-09 18:08:46 +01:00
|
|
|
, "TPUCompile"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "TPUPartitionedCall"
|
2018-05-14 21:55:33 +02:00
|
|
|
, "TPUReplicate"
|
|
|
|
, "While"
|
2018-07-24 23:17:08 +02:00
|
|
|
, "XlaIf"
|
|
|
|
, "XlaLaunch"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "XlaReduce"
|
2018-07-24 23:17:08 +02:00
|
|
|
, "XlaReduceWindow"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "XlaSelectAndScatter"
|
2020-11-06 20:32:21 +01:00
|
|
|
, "XlaScatter"
|
2018-07-24 23:17:08 +02:00
|
|
|
, "XlaWhile"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "_If"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "_TPUReplicate"
|
2018-04-17 18:24:31 +02:00
|
|
|
, "_While"
|
2019-07-15 23:16:58 +02:00
|
|
|
, "_XlaCompile"
|
2016-10-24 21:26:42 +02:00
|
|
|
]
|
2017-08-08 18:48:59 +02:00
|
|
|
|
|
|
|
autogenModulesDir :: LocalBuildInfo -> FilePath
|
|
|
|
#if MIN_VERSION_Cabal(2,0,0)
|
|
|
|
autogenModulesDir = BuildPaths.autogenPackageModulesDir
|
|
|
|
#else
|
|
|
|
autogenModulesDir = BuildPaths.autogenModulesDir
|
|
|
|
#endif
|