├── .dockerignore ├── Dockerfile ├── README.md ├── docker-compose.yml ├── fixtures ├── graph.pb ├── labels.txt └── test.txt ├── main.go ├── main_test.go ├── tmp ├── speech_dataset │ ├── go │ │ └── 9fac5701_nohash_2.wav │ └── on │ │ └── 0a9f9af7_nohash_1.wav └── speech_recognition_graph.pb └── vendor └── github.com └── tensorflow └── tensorflow ├── AUTHORS ├── LICENSE ├── tensorflow ├── compiler │ ├── mlir │ │ ├── lite │ │ │ ├── tests │ │ │ │ └── legalize-tf.mlir │ │ │ └── transforms │ │ │ │ ├── legalize_patterns.td │ │ │ │ └── legalize_tf.cc │ │ └── xla │ │ │ ├── tests │ │ │ ├── legalize-control-flow.mlir │ │ │ ├── legalize-tf.mlir │ │ │ └── legalize-to-std.mlir │ │ │ └── transforms │ │ │ ├── legalize_control_flow.cc │ │ │ ├── legalize_tf.cc │ │ │ ├── legalize_tf_patterns.td │ │ │ ├── legalize_to_standard.cc │ │ │ └── legalize_to_standard_patterns.td │ └── xla │ │ └── service │ │ └── gpu │ │ ├── cudnn_conv_padding_legalization.cc │ │ └── cudnn_conv_padding_legalization.h └── go │ ├── BUILD │ ├── README.md │ ├── android.go │ ├── attrs.go │ ├── context.go │ ├── doc.go │ ├── graph.go │ ├── lib.go │ ├── operation.go │ ├── saved_model.go │ ├── session.go │ ├── shape.go │ ├── status.go │ ├── tensor.go │ ├── tensor_handle.go │ ├── test.sh │ └── version.go └── third_party ├── eigen3 └── LICENSE ├── examples └── eager │ └── spinn │ └── LICENSE ├── fft2d └── LICENSE ├── gpus ├── crosstool │ └── LICENSE └── cuda │ └── LICENSE ├── hadoop └── LICENSE.txt ├── icu └── data │ └── LICENSE ├── mkl └── LICENSE ├── mkl_dnn └── LICENSE ├── mlir └── LICENSE.TXT ├── nccl └── LICENSE ├── ngraph └── LICENSE ├── sycl └── sycl │ └── LICENSE.text ├── tensorrt └── LICENSE └── toolchains └── preconfig ├── centos6 └── tensorrt5 │ └── LICENSE ├── ubuntu14.04 └── tensorrt5 │ └── LICENSE └── ubuntu16.04 └── tensorrt5 └── LICENSE /.dockerignore: -------------------------------------------------------------------------------- 1 | tmp 2 | vendor -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow 2 | 3 | RUN apt-get update && apt-get install -y --no-install-recommends \ 4 | g++ \ 5 | gcc \ 6 | libc6-dev \ 7 | make \ 8 | pkg-config \ 9 | wget \ 10 | git \ 11 | && rm -rf /var/lib/apt/lists/* 12 | 13 | ENV GOLANG_VERSION 1.13.4 14 | 15 | RUN set -eux; \ 16 | \ 17 | # this "case" statement is generated via "update.sh" 18 | dpkgArch="$(dpkg --print-architecture)"; \ 19 | case "${dpkgArch##*-}" in \ 20 | amd64) goRelArch='linux-amd64'; goRelSha256='692d17071736f74be04a72a06dab9cac1cd759377bd85316e52b2227604c004c' ;; \ 21 | armhf) goRelArch='linux-armv6l'; goRelSha256='9f76e6353c9ae2dcad1731b7239531eb8be2fe171f29f2a9c5040945a930fd41' ;; \ 22 | arm64) goRelArch='linux-arm64'; goRelSha256='8b8d99eb07206f082468fb4d0ec962a819ae45d54065fc1ed6e2c502e774aaf0' ;; \ 23 | i386) goRelArch='linux-386'; goRelSha256='497934398ca57c7c207ce3388f099823923b4c7b74394d6ed64cd2d3751aecb8' ;; \ 24 | ppc64el) goRelArch='linux-ppc64le'; goRelSha256='815bf3c7100e73cfac50c4a07c8eeb4b0458a49ffa0e13a74a6cf7ad8e2a6499' ;; \ 25 | s390x) goRelArch='linux-s390x'; goRelSha256='efc6947e8eb0a6409f4c8ba62b00ae4e54404064bc221df1b73364a95945a350' ;; \ 26 | *) goRelArch='src'; goRelSha256='95dbeab442ee2746b9acf0934c8e2fc26414a0565c008631b04addb8c02e7624'; \ 27 | echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \ 28 | esac; \ 29 | \ 30 | url="https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \ 31 | wget -O go.tgz "$url"; \ 32 | echo "${goRelSha256} *go.tgz" | sha256sum -c -; \ 33 | tar -C /usr/local -xzf go.tgz; \ 34 | rm go.tgz; \ 35 | \ 36 | if [ "$goRelArch" = 'src' ]; then \ 37 | echo >&2; \ 38 | echo >&2 'error: UNIMPLEMENTED'; \ 39 | echo >&2 'TODO install golang-any from jessie-backports for GOROOT_BOOTSTRAP (and uninstall after build)'; \ 40 | echo >&2; \ 41 | exit 1; \ 42 | fi; \ 43 | \ 44 | export PATH="/usr/local/go/bin:$PATH"; \ 45 | go version 46 | 47 | ENV GOPATH /go 48 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 49 | 50 | RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" 51 | 52 | # Install TensorFlow C library 53 | RUN curl -L \ 54 | "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz" | \ 55 | tar -C "/usr/local" -xz 56 | RUN ldconfig 57 | # Hide some warnings 58 | ENV TF_CPP_MIN_LOG_LEVEL 2 59 | 60 | RUN go get -d github.com/tensorflow/tensorflow/tensorflow/go 61 | RUN go test github.com/tensorflow/tensorflow/tensorflow/go 62 | 63 | EXPOSE 6006 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-speak 2 | 3 | Speech recognition challenge with TensorFlow and Go. 4 | 5 | Your challenge, should you choose to accept it is to use the TensorFlow Go package to import a trained model and apply it to a wav file. 6 | 7 | ### Prerequisites: 8 | - [Docker](https://www.docker.com/) 9 | - optional: [Go](https://golang.org/doc/install) - we will have go running inside the docker container 10 | 11 | **We will _NOT_ be installing TensorFlow locally in this exercise but use a docker container instead.* 12 | 13 | #### Setup 14 | In your terminal (from inside the root directory of this repository): 15 | ```bash 16 | docker-compose run speech_recognition /bin/bash 17 | ``` 18 | Your terminal should now be running bash from inside the docker container we've setup for this task. 19 | 20 | #### Train the model 21 | To train our model we will be following the first part of the [TensorFlow tutorial for audio recognition](https://missinglink.ai/guides/tensorflow/tensorflow-speech-recognition-two-quick-tutorials/). 22 | 23 | The Python scripts are already inside the container. 24 | Run: 25 | 26 | ```bash 27 | cd /go/src/github.com/tensorflow/tensorflow/tensorflow/examples/speech_commands 28 | python train.py \ 29 | --data_dir=$APP_DIR/tmp/speech_dataset/ \ 30 | --summaries_dir=$APP_DIR/tmp/retrain_logs \ 31 | --train_dir=$APP_DIR/tmp/speech_commands_train 32 | ``` 33 | 34 | If the training stopped in the middle you can check your 35 | speech_commands_train directory for the latest checkpoint and 36 | rerun the train.py script with `--start_checkpoint=$APP_DIR/tmp/speech_commands_train/conv.ckpt-[last-checkpoint-number]` 37 | 38 | ####Save the model (graph) 39 | ```bash 40 | python freeze.py \ 41 | --start_checkpoint=$APP_DIR/tmp/speech_commands_train/conv.ckpt-1000 \ 42 | --output_file=$APP_DIR/tmp/speech_recognition_graph.pb 43 | ``` 44 | 45 | ####Run the (failing) tests 46 | ```bash 47 | cd $APP_DIR 48 | go test 49 | ``` 50 | Implement the code until tests pass 51 | 52 | 53 | ####Run your code to see the results 54 | ```bash 55 | go run main.go 56 | ``` 57 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | 4 | speech_recognition: 5 | image: ronnas/go-tf 6 | ports: 7 | - "6006:6006" 8 | volumes: 9 | - .:/go/src/github.com/wwgberlin/go-speak/ 10 | networks: 11 | - network 12 | environment: 13 | - APP_DIR=/go/src/github.com/wwgberlin/go-speak 14 | working_dir: /go/src/github.com/wwgberlin/go-speak 15 | 16 | 17 | networks: 18 | network: -------------------------------------------------------------------------------- /fixtures/graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwgberlin/go-speak/3fdec6861bc4b360008a0c29b4761a7469f3836f/fixtures/graph.pb -------------------------------------------------------------------------------- /fixtures/labels.txt: -------------------------------------------------------------------------------- 1 | label 1 2 | label 2 -------------------------------------------------------------------------------- /fixtures/test.txt: -------------------------------------------------------------------------------- 1 | I am a test -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | tf "github.com/tensorflow/tensorflow/tensorflow/go" 5 | "io/ioutil" 6 | "os" 7 | "bufio" 8 | "fmt" 9 | "errors" 10 | "log" 11 | "reflect" 12 | ) 13 | 14 | const ( 15 | graphFilePath = "./tmp/speech_recognition_graph.pb" 16 | wavFilePath = "./tmp/speech_dataset/go/9fac5701_nohash_2.wav" 17 | labelsFilePath = "./tmp/speech_commands_train/conv_labels.txt" 18 | ) 19 | 20 | func main() { 21 | wavData, err := readWavDataFromFile(wavFilePath) 22 | if err != nil { 23 | log.Fatal(err) 24 | } 25 | labels, err := readLabelsFromFile(labelsFilePath) 26 | if err != nil { 27 | log.Fatal(err) 28 | } 29 | 30 | graph, err := importGraph(graphFilePath) 31 | if err != nil { 32 | log.Fatal(err) 33 | } 34 | res, err := runGraph(graph, wavData, labels) 35 | if err != nil { 36 | log.Fatal(err) 37 | } 38 | fmt.Println(res) 39 | } 40 | 41 | // Read the entire wav file using ioutil.ReadFile (https://golang.org/pkg/io/ioutil/#ReadFile) 42 | // return the bytes slice and error 43 | func readWavDataFromFile(wavFilePath string) ([]byte, error) { 44 | return ioutil.ReadFile(wavFilePath) 45 | } 46 | 47 | // Open the labels file using os.Open (https://golang.org/pkg/os/#Open) 48 | // return an error if necessary. 49 | // Pass the returned file to bufio.NewScanner to read the lines (https://golang.org/pkg/bufio/#Scanner 50 | // --checkout the lines example) return the error is necessary. 51 | // don't forget to close the file. 52 | func readLabelsFromFile(labelsFilePath string) ([]string, error) { 53 | lfile, err := os.Open(labelsFilePath) 54 | if err != nil { 55 | return nil, err 56 | } 57 | defer lfile.Close() 58 | 59 | //https://golang.org/pkg/bufio/#example_Scanner_lines 60 | s := bufio.NewScanner(lfile) 61 | var labels []string 62 | for s.Scan() { 63 | labels = append(labels, s.Text()) 64 | } 65 | return labels, s.Err() 66 | } 67 | 68 | // Read the entire graph file using ioutil.ReadFile (https://golang.org/pkg/io/ioutil/#ReadFile) 69 | // What is a graph? https://www.tensorflow.org/api_docs/python/tf/Graph 70 | // instantiate a new Graph using tf.NewGraph (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#NewGraph) 71 | // Import the bytes read to the graph using the method 72 | // Import with empty prefix (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#Graph.Import) 73 | func importGraph(graphFilePath string) (*tf.Graph, error) { 74 | return nil, errors.New("not implemented") 75 | } 76 | 77 | //1, Create a new session using tf.NewSession (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#Session) 78 | // What is a TensorFlow session? Read here https://danijar.com/what-is-a-tensorflow-session/ 79 | // 80 | //2. Define a tensor from our "stringified" wavData (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#NewTensor) 81 | // What's a Tensor? https://www.tensorflow.org/api_docs/python/tf/Tensor. 82 | // Let's name it simply "tensor". Don't forget to return an error if necessary. 83 | // 84 | //3. Using the outputOperationName get the Operation from the graph (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#Graph.Operation) 85 | // What's an Operation? https://www.tensorflow.org/api_docs/python/tf/Operation 86 | // From the operation let's take the 0th output (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#Operation.Output) 87 | // let's call our result "softmaxTensor". 88 | // 89 | //4. Define another tenstor from graph operation with output(similar to 4) this time using the inputOperationName this time 90 | // (and the 0th output), let's name our result "inputOperation". 91 | // 92 | //5. Define a map from an Output type to a *Tensor type and instantiate it with one key value pair: 93 | // our inputOperation variable and our "tensor" variable (the one with the wavData) 94 | // 95 | //6. Run the session (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#Session.Run) 96 | // with the map we've instantiated above and an Output slice containing exactly one item - our softmaxTensor. 97 | // and use fmtOutput to format the result. 98 | // Return the respective error if necessary. 99 | // 100 | //7. Run the tests. 101 | func runGraph(graph *tf.Graph, wavData []byte, labels []string) (string, error) { 102 | const ( 103 | inputOperationName = "wav_data" //Name of WAVE data input node in model. 104 | outputOperationName = "labels_softmax" //Name of node outputting a prediction in the model 105 | ) 106 | 107 | //YOUR CODE GOES HERE! 108 | 109 | // Uncomment this code when the output variable is defined: 110 | return "", nil 111 | } 112 | 113 | func fmtOutput(output []*tf.Tensor, labels []string) string { 114 | var str string 115 | for i := 0; i < len(output); i++ { 116 | if reflect.TypeOf(output[i].Value()).Kind() == reflect.Slice { 117 | s := reflect.ValueOf(output[i].Value()) 118 | 119 | for j := 0; j < s.Len(); j++ { 120 | r := s.Index(j) 121 | 122 | if r.Kind() == reflect.Slice { 123 | for k := 0; k < r.Len(); k++ { 124 | q := r.Index(k) 125 | humanString := labels[k] + ":\t" 126 | str += fmt.Sprint(humanString, q, "\n") 127 | } 128 | } 129 | } 130 | } 131 | } 132 | return str 133 | } 134 | -------------------------------------------------------------------------------- /main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "testing" 5 | "os" 6 | "reflect" 7 | ) 8 | 9 | func Test_readWavDataFromFile(t *testing.T) { 10 | //failure 11 | b, err := readWavDataFromFile("./fixtures/doesnt-exist.txt") 12 | if err != nil { 13 | if !os.IsNotExist(err) { 14 | t.Fatalf("readWavDataFromFile was expected to return the error returned from ioutil.ReadFile") 15 | } 16 | } else { 17 | t.Fatalf("readWavDataFromFile was expected to fail") 18 | } 19 | if b != nil { 20 | t.Fatalf("readWavDataFromFile was expected return a nil byte slice") 21 | } 22 | 23 | //success 24 | b, err = readWavDataFromFile("./fixtures/test.txt") 25 | if err != nil { 26 | t.Fatalf("readWavDataFromFile was expected to success, returned error: %s", err) 27 | } 28 | if string(b) != "I am a test" { 29 | t.Fatalf("readWavDataFromFile was expected to return the contents of the given file but instead returned '%v'", b) 30 | } 31 | } 32 | 33 | func Test_readLabelsFromFile(t *testing.T) { 34 | //failure 35 | s, err := readLabelsFromFile("./fixtures/doesntexist.txt") 36 | if err != nil { 37 | if !os.IsNotExist(err) { 38 | t.Fatalf("readLabelsFromFile was expected to return the error returned from ioutil.ReadFile") 39 | } 40 | } else { 41 | t.Fatalf("readLabelsFromFile was expected to fail") 42 | } 43 | if s != nil { 44 | t.Fatalf("readLabelsFromFile was expected return a nil string slice") 45 | } 46 | 47 | //success 48 | s, err = readLabelsFromFile("./fixtures/labels.txt") 49 | if err != nil { 50 | t.Fatal("readLabelsFromFile was expected to succeed") 51 | } 52 | if len(s) != 2 { 53 | t.Fatal("readLabelsFromFile was expected to return a slice containing the lines of the given file") 54 | } 55 | if !reflect.DeepEqual(s, []string{"label 1", "label 2"}) { 56 | t.Fatalf("unexpected return value from readLabelsFromFile: '%v'", s) 57 | } 58 | } 59 | 60 | func Test_importGraph(t *testing.T) { 61 | //failure 62 | g, err := importGraph("./fixtures/doesnt_exist.pb") 63 | if err != nil { 64 | if !os.IsNotExist(err) { 65 | t.Fatalf("importGraph was expected to return the error returned from ioutil.ReadFile") 66 | } 67 | } else { 68 | t.Fatalf("importGraph was expected to fail") 69 | } 70 | if g != nil { 71 | t.Fatalf("importGraph was expected return a nil string slice") 72 | } 73 | 74 | //bad file 75 | g, err = importGraph("./fixtures/labels.txt") 76 | if err == nil { 77 | t.Fatalf("importGraph was expected to fail") 78 | } 79 | if g != nil { 80 | t.Fatalf("importGraph was expected return a nil graph") 81 | } 82 | 83 | //success 84 | g, err = importGraph("./fixtures/graph.pb") 85 | if err != nil { 86 | t.Fatal("importGraph was expected to succeed") 87 | } 88 | if g == nil { 89 | t.Fatal("importGraph was expected to return a valid Graph object but returned nil") 90 | } 91 | if g.Operation("wav_data") == nil { 92 | t.Fatal("importGraph did not import graph object properly using the file path") 93 | } 94 | 95 | } 96 | 97 | func Test_runGraph(t *testing.T) { 98 | const expected = "_silence_:\t0.0014208348\n" + 99 | "_unknown_:\t0.0832541\n" + 100 | "yes:\t0.016642008\n" + 101 | "no:\t0.083147325\n" + 102 | "up:\t0.059981856\n" + 103 | "down:\t0.13438535\n" + 104 | "left:\t0.054391935\n" + 105 | "right:\t0.043705765\n" + 106 | "on:\t0.26739722\n" + 107 | "off:\t0.10459701\n" + 108 | "stop:\t0.101431474\n" + 109 | "go:\t0.049645092\n" 110 | 111 | graph, _ := importGraph("./fixtures/graph.pb") 112 | wavData, _ := readWavDataFromFile("./tmp/speech_dataset/on/0a9f9af7_nohash_1.wav") 113 | labels, _ := readLabelsFromFile(labelsFilePath) 114 | if str, _ := runGraph(graph, wavData, labels); str != expected { 115 | t.Fatalf("runGraph was expected to return: '%s' but returned: '%s'", expected, str) 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /tmp/speech_dataset/go/9fac5701_nohash_2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwgberlin/go-speak/3fdec6861bc4b360008a0c29b4761a7469f3836f/tmp/speech_dataset/go/9fac5701_nohash_2.wav -------------------------------------------------------------------------------- /tmp/speech_dataset/on/0a9f9af7_nohash_1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwgberlin/go-speak/3fdec6861bc4b360008a0c29b4761a7469f3836f/tmp/speech_dataset/on/0a9f9af7_nohash_1.wav -------------------------------------------------------------------------------- /tmp/speech_recognition_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwgberlin/go-speak/3fdec6861bc4b360008a0c29b4761a7469f3836f/tmp/speech_recognition_graph.pb -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of TensorFlow authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Google Inc. 10 | Yuan Tang 11 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 The TensorFlow Authors. All rights reserved. 2 | 3 | Apache License 4 | Version 2.0, January 2004 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | END OF TERMS AND CONDITIONS 179 | 180 | APPENDIX: How to apply the Apache License to your work. 181 | 182 | To apply the Apache License to your work, attach the following 183 | boilerplate notice, with the fields enclosed by brackets "[]" 184 | replaced with your own identifying information. (Don't include 185 | the brackets!) The text should be enclosed in the appropriate 186 | comment syntax for the file format. We also recommend that a 187 | file or class name and description of purpose be included on the 188 | same "printed page" as the copyright notice for easier 189 | identification within third-party archives. 190 | 191 | Copyright [yyyy] [name of copyright owner] 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. 204 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/lite/transforms/legalize_tf.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This transformation pass converts operations in TensorFlow dialect into 17 | // operations that are legal in the TensorFlow Lite dialect. Operations that 18 | // can be legalized to TensorFlow Lite dialect with simple replacements are part 19 | // of this pass and other operations that may create extra ops should be part of 20 | // the PrepareTF pass which should be run before this pass. That way any 21 | // constant folding opportunities from the extra ops can be exploited by the 22 | // constant folding support for the TensorFlow ops. 23 | 24 | #include 25 | 26 | #include "llvm/ADT/StringSwitch.h" 27 | #include "mlir/Dialect/QuantOps/FakeQuantSupport.h" // TF:local_config_mlir 28 | #include "mlir/Dialect/QuantOps/UniformSupport.h" // TF:local_config_mlir 29 | #include "mlir/IR/Attributes.h" // TF:local_config_mlir 30 | #include "mlir/IR/PatternMatch.h" // TF:local_config_mlir 31 | #include "mlir/IR/StandardTypes.h" // TF:local_config_mlir 32 | #include "mlir/Pass/Pass.h" // TF:local_config_mlir 33 | #include "mlir/Support/Functional.h" // TF:local_config_mlir 34 | #include "mlir/Support/LLVM.h" // TF:local_config_mlir 35 | #include "tensorflow/compiler/mlir/lite/ir/tfl_ops.h" 36 | #include "tensorflow/compiler/mlir/lite/transforms/passes.h" 37 | #include "tensorflow/compiler/mlir/lite/utils/attribute_utils.h" 38 | #include "tensorflow/compiler/mlir/lite/utils/quantization_utils.h" 39 | #include "tensorflow/compiler/mlir/lite/utils/validators.h" 40 | #include "tensorflow/compiler/mlir/tensorflow/ir/tf_ops.h" 41 | 42 | namespace mlir { 43 | namespace TFL { 44 | 45 | //===----------------------------------------------------------------------===// 46 | // The actual LegalizeTF Pass. 47 | namespace { 48 | 49 | // Legalize operations in functions. 50 | struct LegalizeTF : public FunctionPass { 51 | void runOnFunction() override; 52 | }; 53 | 54 | #include "tensorflow/compiler/mlir/lite/transforms/generated_legalize_tf.inc" 55 | 56 | #define DECL_CONVERT_OP(tf_op) \ 57 | struct ConvertTF##tf_op##Op : public RewritePattern { \ 58 | explicit ConvertTF##tf_op##Op(MLIRContext* context) \ 59 | : RewritePattern(TF::tf_op##Op::getOperationName(), 1, context) {} \ 60 | PatternMatchResult matchAndRewrite( \ 61 | Operation* op, PatternRewriter& rewriter) const override; \ 62 | } 63 | 64 | // TODO(antiagainst): Define this pattern in a table-driven manner once variadic 65 | // operands are properly supported in declarative rewrite rule specification. 66 | 67 | DECL_CONVERT_OP(Concat); 68 | DECL_CONVERT_OP(ConcatV2); 69 | DECL_CONVERT_OP(MatMul); 70 | DECL_CONVERT_OP(Pack); 71 | DECL_CONVERT_OP(Split); 72 | DECL_CONVERT_OP(SplitV); 73 | DECL_CONVERT_OP(Unpack); 74 | 75 | #undef DECL_CONVERT_OP 76 | 77 | PatternMatchResult ConvertTFConcatOp::matchAndRewrite( 78 | Operation* op, PatternRewriter& rewriter) const { 79 | auto tf_concat_op = cast(op); 80 | 81 | SmallVector values(tf_concat_op.values()); 82 | auto output_type = tf_concat_op.output()->getType(); 83 | // Extract axis attribute from constant concat_dims tensor 84 | ElementsAttr axis; 85 | if (!matchPattern(tf_concat_op.concat_dim(), m_Constant(&axis))) 86 | return matchFailure(); 87 | 88 | StringAttr fused_activation_function = 89 | StringAttr::get("NONE", rewriter.getContext()); 90 | rewriter.replaceOpWithNewOp( 91 | op, output_type, values, mlir::TFL::ExtractSingleElementAsInteger(axis), 92 | fused_activation_function); 93 | return matchSuccess(); 94 | } 95 | 96 | PatternMatchResult ConvertTFConcatV2Op::matchAndRewrite( 97 | Operation* op, PatternRewriter& rewriter) const { 98 | auto tf_concat_op = cast(op); 99 | 100 | SmallVector values(tf_concat_op.values()); 101 | auto output_type = tf_concat_op.output()->getType(); 102 | // Extract axis attribute from constant axis tensor 103 | ElementsAttr axis; 104 | if (!matchPattern(tf_concat_op.axis(), m_Constant(&axis))) 105 | return matchFailure(); 106 | 107 | StringAttr fused_activation_function = 108 | StringAttr::get("NONE", rewriter.getContext()); 109 | rewriter.replaceOpWithNewOp( 110 | op, output_type, values, ExtractSingleElementAsInteger(axis), 111 | fused_activation_function); 112 | return matchSuccess(); 113 | } 114 | 115 | // The following is effectively: 116 | // def : Pat< 117 | // (TF_MatMulOp $a, $b, ConstBoolAttrFalse:$transpose_a, 118 | // ConstBoolAttrTrue:$transpose_b), 119 | // (TFL_FullyConnectedOp:$__0 $a, $b, 120 | // NoInput.pattern, TFL_AF_None, TFL_FCWO_Default, ConstBoolAttrFalse)>; 121 | PatternMatchResult ConvertTFMatMulOp::matchAndRewrite( 122 | Operation* op, PatternRewriter& rewriter) const { 123 | auto tf_matmul_op = cast(op); 124 | if (tf_matmul_op.transpose_a()) return matchFailure(); 125 | if (!tf_matmul_op.transpose_b()) return matchFailure(); 126 | 127 | Type output_type = tf_matmul_op.getResult()->getType(); 128 | // TODO(jpienaar): Follow up post shuffle discussion. 129 | auto no_input = rewriter.create( 130 | op->getLoc(), rewriter.getNoneType(), rewriter.getUnitAttr()); 131 | auto fc_op = rewriter.create( 132 | op->getLoc(), ArrayRef{output_type}, op->getOperand(0), 133 | op->getOperand(1), no_input, rewriter.getStringAttr("NONE"), 134 | rewriter.getStringAttr("DEFAULT"), rewriter.getBoolAttr(false)); 135 | rewriter.replaceOp(op, {fc_op.getResult(0)}); 136 | return matchSuccess(); 137 | } 138 | 139 | PatternMatchResult ConvertTFPackOp::matchAndRewrite( 140 | Operation* op, PatternRewriter& rewriter) const { 141 | auto tf_pack_op = cast(op); 142 | 143 | SmallVector values(tf_pack_op.values()); 144 | auto output_type = tf_pack_op.output()->getType(); 145 | auto values_count = rewriter.getI32IntegerAttr(tf_pack_op.N().getZExtValue()); 146 | // Axis can be negative. 147 | auto axis = rewriter.getI32IntegerAttr(tf_pack_op.axis().getSExtValue()); 148 | 149 | rewriter.replaceOpWithNewOp(op, output_type, values, values_count, 150 | axis); 151 | return matchSuccess(); 152 | } 153 | 154 | PatternMatchResult ConvertTFSplitOp::matchAndRewrite( 155 | Operation* op, PatternRewriter& rewriter) const { 156 | auto tf_split_op = cast(op); 157 | 158 | auto output_types = functional::map([](Value* v) { return v->getType(); }, 159 | tf_split_op.output()); 160 | // Number of splits cannot be negative. 161 | auto num_split = 162 | rewriter.getI32IntegerAttr(tf_split_op.num_split().getZExtValue()); 163 | 164 | rewriter.replaceOpWithNewOp(op, output_types, 165 | tf_split_op.split_dim(), 166 | tf_split_op.value(), num_split); 167 | return matchSuccess(); 168 | } 169 | 170 | PatternMatchResult ConvertTFSplitVOp::matchAndRewrite( 171 | Operation* op, PatternRewriter& rewriter) const { 172 | auto tf_splitv_op = cast(op); 173 | 174 | auto output_types = functional::map([](Value* v) { return v->getType(); }, 175 | tf_splitv_op.output()); 176 | // Number of splits cannot be negative. 177 | auto num_split = 178 | rewriter.getI32IntegerAttr(tf_splitv_op.num_split().getZExtValue()); 179 | 180 | rewriter.replaceOpWithNewOp( 181 | op, output_types, tf_splitv_op.value(), tf_splitv_op.size_splits(), 182 | tf_splitv_op.split_dim(), num_split); 183 | return matchSuccess(); 184 | } 185 | 186 | PatternMatchResult ConvertTFUnpackOp::matchAndRewrite( 187 | Operation* op, PatternRewriter& rewriter) const { 188 | auto tf_unpack_op = cast(op); 189 | 190 | auto* input = tf_unpack_op.value(); 191 | auto output_types = functional::map([](Value* v) { return v->getType(); }, 192 | tf_unpack_op.output()); 193 | auto num = rewriter.getI32IntegerAttr(tf_unpack_op.num().getZExtValue()); 194 | // Axis can be negative. 195 | auto axis = rewriter.getI32IntegerAttr(tf_unpack_op.axis().getSExtValue()); 196 | 197 | rewriter.replaceOpWithNewOp(op, output_types, input, num, axis); 198 | return matchSuccess(); 199 | } 200 | 201 | void LegalizeTF::runOnFunction() { 202 | OwningRewritePatternList patterns; 203 | auto* ctx = &getContext(); 204 | auto func = getFunction(); 205 | 206 | // Add the generated patterns to the list. 207 | populateWithGenerated(ctx, &patterns); 208 | patterns.insert(ctx); 211 | applyPatternsGreedily(func, std::move(patterns)); 212 | } 213 | 214 | } // namespace 215 | 216 | // Creates an instance of the TensorFlow Lite dialect LegalizeTF pass. 217 | FunctionPassBase* CreateLegalizeTFPass() { return new LegalizeTF(); } 218 | 219 | static PassRegistration pass( 220 | "tfl-legalize-tf", "Legalize from TensorFlow to TensorFlow Lite dialect"); 221 | 222 | } // namespace TFL 223 | } // namespace mlir 224 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/tests/legalize-control-flow.mlir: -------------------------------------------------------------------------------- 1 | // RUN: tf-opt -xla-legalize-control-flow %s -o - | FileCheck %s 2 | 3 | // CHECK-LABEL: func @cond(%arg0: tensor) -> tensor { 4 | func @cond(%arg0: tensor) -> tensor { 5 | // CHECK-NEXT: %0 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "LT", name = "compare.2"} : (tensor, tensor) -> tensor 6 | %0 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "LT", name = "compare.2"} : (tensor, tensor) -> tensor 7 | // CHECK-NEXT: return %0 : tensor 8 | return %0 : tensor 9 | } 10 | 11 | // CHECK-LABEL: func @loop(%arg0: tensor) -> tensor { 12 | func @loop(%arg0: tensor) -> tensor { 13 | // CHECK-NEXT: %0 = xla_hlo.add %arg0, %arg0 {name = "compare.0"} : tensor 14 | %0 = "xla_hlo.add"(%arg0, %arg0) {name = "compare.0"} : (tensor, tensor) -> tensor 15 | // CHECK-NEXT: return %0 : tensor 16 | return %0 : tensor 17 | } 18 | 19 | // CHECK-LABEL: func @main(%arg0: tensor) -> tensor { 20 | func @main(%arg0: tensor) -> tensor { 21 | // CHECK-NEXT: br ^bb1(%arg0 : tensor) 22 | // CHECK-NEXT: b1(%0: tensor): 23 | // CHECK-NEXT: %1 = call @cond(%0) : (tensor) -> tensor 24 | // CHECK-NEXT: %2 = extract_element %1[] : tensor 25 | // CHECK-NEXT: cond_br %2, ^bb2(%0 : tensor), ^bb3(%0 : tensor) 26 | // CHECK-NEXT: b2(%3: tensor): // pred: ^bb1 27 | // CHECK-NEXT: %4 = call @loop(%3) : (tensor) -> tensor 28 | // CHECK-NEXT: br ^bb1(%4 : tensor) 29 | // CHECK-NEXT: b3(%5: tensor): // pred: ^bb1 30 | %0 = "xla_hlo.while"(%arg0) {body = @loop, cond = @cond} : (tensor) -> tensor 31 | // CHECK-NEXT: return %5 : tensor 32 | return %0 : tensor 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/tests/legalize-tf.mlir: -------------------------------------------------------------------------------- 1 | // RUN: tf-opt -xla-legalize-tf %s | FileCheck %s 2 | 3 | //===----------------------------------------------------------------------===// 4 | // BatchNorm op legalizations. 5 | //===----------------------------------------------------------------------===// 6 | 7 | // CHECK-LABEL: fusedBatchNorm_notraining 8 | func @fusedBatchNorm_notraining(%arg0: tensor<8x8x8x8xf32>, %arg1: tensor<8xf32>, %arg2: tensor<8xf32>, %arg3: tensor<8xf32>, %arg4: tensor<8xf32>) -> (tensor<8x8x8x8xf32>) { 9 | // CHECK-NEXT: "xla_hlo.batch_norm_inference"(%arg0, %arg1, %arg2, %arg3, %arg4) {epsilon = 1.000000e-03 : f32, feature_index = 3 : i64} : (tensor<8x8x8x8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>) -> tensor<8x8x8x8xf32> 10 | %0:5 = "tf.FusedBatchNorm"(%arg0, %arg1, %arg2, %arg3, %arg4) {T = "tfdtype$DT_FLOAT", data_format = "NHWC", epsilon = 0.001 : f32, is_training = false} : (tensor<8x8x8x8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>) -> (tensor<8x8x8x8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>) 11 | return %0#0 : tensor<8x8x8x8xf32> 12 | } 13 | 14 | // CHECK-LABEL: fusedBatchNorm_training 15 | func @fusedBatchNorm_training(%arg0: tensor<8x8x8x8xf32>, %arg1: tensor<8xf32>, %arg2: tensor<8xf32>, %arg3: tensor<8xf32>, %arg4: tensor<8xf32>) -> (tensor<8x8x8x8xf32>) { 16 | // TODO(riverriddle) Support training. 17 | // CHECK-NEXT: "tf.FusedBatchNorm" 18 | %0:5 = "tf.FusedBatchNorm"(%arg0, %arg1, %arg2, %arg3, %arg4) {T = "tfdtype$DT_FLOAT", data_format = "NHWC", epsilon = 0.001 : f32, is_training = true} : (tensor<8x8x8x8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>) -> (tensor<8x8x8x8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>, tensor<8xf32>) 19 | return %0#0 : tensor<8x8x8x8xf32> 20 | } 21 | 22 | //===----------------------------------------------------------------------===// 23 | // Bias op legalizations. 24 | //===----------------------------------------------------------------------===// 25 | 26 | // CHECK-LABEL: func @biasAdd_NHWC 27 | func @biasAdd_NHWC(%arg0: tensor<1x32x10x32xi32>, %arg1: tensor<32xi32>) -> tensor<1x32x10x32xi32> { 28 | // CHECK-NEXT: %0 = "xla_hlo.add"(%arg0, %arg1) {broadcast_dimensions = dense<3> : tensor<1xi64>} 29 | %0 = "tf.BiasAdd"(%arg0, %arg1) {T = "tfdtype$DT_FLOAT", data_format = "NHWC"} : (tensor<1x32x10x32xi32>, tensor<32xi32>) -> tensor<1x32x10x32xi32> 30 | return %0 : tensor<1x32x10x32xi32> 31 | } 32 | 33 | // CHECK-LABEL: func @biasAdd_NCHW 34 | func @biasAdd_NCHW(%arg0: tensor<1x32x10x32xi32>, %arg1: tensor<32xi32>) -> tensor<1x32x10x32xi32> { 35 | // CHECK-NEXT: %0 = "xla_hlo.add"(%arg0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>} 36 | %0 = "tf.BiasAdd"(%arg0, %arg1) {T = "tfdtype$DT_FLOAT", data_format = "NCHW"} : (tensor<1x32x10x32xi32>, tensor<32xi32>) -> tensor<1x32x10x32xi32> 37 | return %0 : tensor<1x32x10x32xi32> 38 | } 39 | 40 | // In the next two tests, the replacement fails because the bias dimension does 41 | // not have the same size as the feature dimension. 42 | 43 | // CHECK-LABEL: func @biasAdd_NHWC_invalid 44 | func @biasAdd_NHWC_invalid(%arg0: tensor<1x32x10x2xi32>, %arg1: tensor<32xi32>) -> tensor<1x32x10x2xi32> { 45 | // CHECK-NOT: xla_hlo.add 46 | %0 = "tf.BiasAdd"(%arg0, %arg1) {T = "tfdtype$DT_FLOAT", data_format = "NHWC"} : (tensor<1x32x10x2xi32>, tensor<32xi32>) -> tensor<1x32x10x2xi32> 47 | return %0 : tensor<1x32x10x2xi32> 48 | } 49 | 50 | // CHECK-LABEL: func @biasAdd_NCHW_invalid 51 | func @biasAdd_NCHW_invalid(%arg0: tensor<1x10x10x32xi32>, %arg1: tensor<32xi32>) -> tensor<1x10x10x32xi32> { 52 | // CHECK-NOT: xla_hlo.add 53 | %0 = "tf.BiasAdd"(%arg0, %arg1) {T = "tfdtype$DT_FLOAT", data_format = "NCHW"} : (tensor<1x10x10x32xi32>, tensor<32xi32>) -> tensor<1x10x10x32xi32> 54 | return %0 : tensor<1x10x10x32xi32> 55 | } 56 | 57 | //===----------------------------------------------------------------------===// 58 | // Binary op legalizations. 59 | //===----------------------------------------------------------------------===// 60 | 61 | // CHECK-LABEL: func @add 62 | func @add(%arg0: tensor<2xi32>) -> tensor<2xi32> { 63 | // CHECK-NEXT: %0 = xla_hlo.add %arg0, %arg0 : tensor<2xi32> 64 | // CHECK-NEXT: return %0 : tensor<2xi32> 65 | %0 = "tf.Add"(%arg0, %arg0) : (tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32> 66 | return %0: tensor<2xi32> 67 | } 68 | 69 | // CHECK-LABEL: func @broadcast_add 70 | func @broadcast_add(%arg0: tensor<1xi32>, %arg1: tensor<1x2xi32>) -> tensor<1x2xi32> { 71 | // CHECK-NEXT: "xla_hlo.add"(%arg0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>} 72 | %0 = "tf.Add"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xi32>) -> tensor<1x2xi32> 73 | return %0: tensor<1x2xi32> 74 | } 75 | 76 | // CHECK-LABEL: func @broadcast_multi_dim_add 77 | func @broadcast_multi_dim_add(%arg0: tensor<4x1x1xi32>, %arg1: tensor<4x4x4x4xi32>) -> tensor<4x4x4x4xi32> { 78 | // CHECK-NEXT: "xla_hlo.add"(%arg0, %arg1) {broadcast_dimensions = dense<[1, 2, 3]> : tensor<3xi64>} 79 | %0 = "tf.Add"(%arg0, %arg1) : (tensor<4x1x1xi32>, tensor<4x4x4x4xi32>) -> tensor<4x4x4x4xi32> 80 | return %0: tensor<4x4x4x4xi32> 81 | } 82 | 83 | // CHECK-LABEL: func @div 84 | func @div(%arg0: tensor<2xi32>) -> tensor<2xi32> { 85 | // CHECK-NEXT: %0 = xla_hlo.div %arg0, %arg0 : tensor<2xi32> 86 | // CHECK-NEXT: return %0 : tensor<2xi32> 87 | %0 = "tf.Div"(%arg0, %arg0) : (tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32> 88 | return %0: tensor<2xi32> 89 | } 90 | 91 | // CHECK-LABEL: func @broadcast_div 92 | func @broadcast_div(%arg0: tensor<1xi32>, %arg1: tensor<1x2xi32>) -> tensor<1x2xi32> { 93 | // CHECK-NEXT: "xla_hlo.div"(%arg0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>} 94 | %0 = "tf.Div"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xi32>) -> tensor<1x2xi32> 95 | return %0: tensor<1x2xi32> 96 | } 97 | 98 | // CHECK-LABEL: func @mul 99 | func @mul(%arg0: tensor<2xi32>) -> tensor<2xi32> { 100 | // CHECK-NEXT: %0 = xla_hlo.mul %arg0, %arg0 : tensor<2xi32> 101 | // CHECK-NEXT: return %0 : tensor<2xi32> 102 | %0 = "tf.Mul"(%arg0, %arg0) : (tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32> 103 | return %0: tensor<2xi32> 104 | } 105 | 106 | // CHECK-LABEL: func @broadcast_mul 107 | func @broadcast_mul(%arg0: tensor<1xi32>, %arg1: tensor<1x2xi32>) -> tensor<1x2xi32> { 108 | // CHECK-NEXT: "xla_hlo.mul"(%arg0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>} 109 | %0 = "tf.Mul"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xi32>) -> tensor<1x2xi32> 110 | return %0: tensor<1x2xi32> 111 | } 112 | 113 | // CHECK-LABEL: func @real_div 114 | func @real_div(%arg0: tensor<2xi32>) -> tensor<2xi32> { 115 | // CHECK-NEXT: %0 = xla_hlo.div %arg0, %arg0 : tensor<2xi32> 116 | %0 = "tf.RealDiv"(%arg0, %arg0) : (tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32> 117 | return %0: tensor<2xi32> 118 | } 119 | 120 | // CHECK-LABEL: func @broadcast_real_div 121 | func @broadcast_real_div(%arg0: tensor<1xi32>, %arg1: tensor<1x2xi32>) -> tensor<1x2xi32> { 122 | // CHECK-NEXT: "xla_hlo.div"(%arg0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>} 123 | %0 = "tf.RealDiv"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xi32>) -> tensor<1x2xi32> 124 | return %0: tensor<1x2xi32> 125 | } 126 | 127 | // CHECK-LABEL: func @sub 128 | func @sub(%arg0: tensor<2xi32>) -> tensor<2xi32> { 129 | // CHECK-NEXT: %0 = xla_hlo.sub %arg0, %arg0 : tensor<2xi32> 130 | // CHECK-NEXT: return %0 : tensor<2xi32> 131 | %0 = "tf.Sub"(%arg0, %arg0) : (tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32> 132 | return %0: tensor<2xi32> 133 | } 134 | 135 | // CHECK-LABEL: func @broadcast_sub 136 | func @broadcast_sub(%arg0: tensor<1xi32>, %arg1: tensor<1x2xi32>) -> tensor<1x2xi32> { 137 | // CHECK-NEXT: "xla_hlo.sub"(%arg0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>} 138 | %0 = "tf.Sub"(%arg0, %arg1) : (tensor<1xi32>, tensor<1x2xi32>) -> tensor<1x2xi32> 139 | return %0: tensor<1x2xi32> 140 | } 141 | 142 | //===----------------------------------------------------------------------===// 143 | // Identity op legalizations. 144 | //===----------------------------------------------------------------------===// 145 | 146 | // CHECK-LABEL: func @identity 147 | func @identity(%arg0: tensor<1xi32>) -> tensor<1xi32> { 148 | // CHECK-NEXT: return %arg0 : tensor<1xi32> 149 | %0 = "tf.Identity"(%arg0) : (tensor<1xi32>) -> tensor<1xi32> 150 | return %0: tensor<1xi32> 151 | } 152 | 153 | //===----------------------------------------------------------------------===// 154 | // Nullary op legalizations. 155 | //===----------------------------------------------------------------------===// 156 | 157 | // CHECK-LABEL: @const 158 | func @const() -> tensor<2xi32> { 159 | // tf.Const is legalized into xla_hlo.constant, which is folded into constant. 160 | 161 | // CHECK-NEXT: constant dense<0> : tensor<2xi32> 162 | %0 = "tf.Const"() {device = "", name = "", dtype = "tfdtype$DT_INT32", value = dense<0> : tensor<2xi32>} : () -> (tensor<2xi32>) 163 | return %0: tensor<2xi32> 164 | } 165 | 166 | //===----------------------------------------------------------------------===// 167 | // Relu op legalizations. 168 | //===----------------------------------------------------------------------===// 169 | 170 | // CHECK-LABEL: func @relu 171 | func @relu(%arg0: tensor<1xi32>) -> tensor<1xi32> { 172 | // CHECK-NEXT: %cst = constant dense<0> : tensor<1xi32> 173 | // CHECK-NEXT: %0 = xla_hlo.max %arg0, %cst : tensor<1xi32> 174 | %0 = "tf.Relu"(%arg0) : (tensor<1xi32>) -> tensor<1xi32> 175 | return %0: tensor<1xi32> 176 | } 177 | 178 | // CHECK-LABEL: func @relu6 179 | func @relu6(%arg0: tensor<1xi32>) -> tensor<1xi32> { 180 | // CHECK-NEXT: %cst = constant dense<0> : tensor<1xi32> 181 | // CHECK-NEXT: %cst_0 = constant dense<6> : tensor<1xi32> 182 | // CHECK-NEXT: %0 = "xla_hlo.clamp"(%cst, %arg0, %cst_0) : (tensor<1xi32>, tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32> 183 | %0 = "tf.Relu6"(%arg0) : (tensor<1xi32>) -> tensor<1xi32> 184 | return %0: tensor<1xi32> 185 | } 186 | 187 | //===----------------------------------------------------------------------===// 188 | // Unary op legalizations. 189 | //===----------------------------------------------------------------------===// 190 | 191 | // CHECK-LABEL: reshape 192 | func @reshape(%arg0: tensor<2xf32>, %arg1: tensor<2xi32>) -> tensor<1x1xf32> { 193 | // CHECK: %0 = "xla_hlo.reshape"(%arg0) : (tensor<2xf32>) -> tensor<1x1xf32> 194 | %0 = "tf.Reshape"(%arg0, %arg1) : (tensor<2xf32>, tensor<2xi32>) -> tensor<1x1xf32> 195 | return %0 : tensor<1x1xf32> 196 | } 197 | 198 | // CHECK-LABEL: reshape_dynamic 199 | func @reshape_dynamic(%arg0: tensor<*xf32>, %arg1: tensor<2xi32>) -> tensor { 200 | // CHECK: %0 = "tf.Reshape"(%arg0, %arg1) : (tensor<*xf32>, tensor<2xi32>) -> tensor 201 | %0 = "tf.Reshape"(%arg0, %arg1) : (tensor<*xf32>, tensor<2xi32>) -> tensor 202 | return %0 : tensor 203 | } 204 | 205 | // CHECK-LABEL: squeeze 206 | func @squeeze(%arg0: tensor<1x1x10xf32>) -> tensor<1x10xf32> { 207 | // CHECK-NEXT: %0 = "xla_hlo.reshape"(%arg0) : (tensor<1x1x10xf32>) -> tensor<1x10xf32> 208 | %0 = "tf.Squeeze"(%arg0) : (tensor<1x1x10xf32>) -> tensor<1x10xf32> 209 | return %0 : tensor<1x10xf32> 210 | } 211 | 212 | // CHECK-LABEL: squeeze_dynamic 213 | func @squeeze_dynamic(%arg0: tensor) -> tensor<*xf32> { 214 | // CHECK-NEXT: %0 = "tf.Squeeze"(%arg0) : (tensor) -> tensor<*xf32> 215 | %0 = "tf.Squeeze"(%arg0) : (tensor) -> tensor<*xf32> 216 | return %0 : tensor<*xf32> 217 | } 218 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/tests/legalize-to-std.mlir: -------------------------------------------------------------------------------- 1 | // RUN: tf-opt -xla-legalize-to-std %s -o - | FileCheck %s 2 | 3 | // CHECK-LABEL: func @binary_ops_float(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32> { 4 | func @binary_ops_float(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32> { 5 | // CHECK-NEXT: %0 = addf %arg0, %arg1 : tensor<4xf32> 6 | %0 = "xla_hlo.add"(%arg0, %arg1) {name = "add.3"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> 7 | 8 | // CHECK-NEXT: %1 = mulf %0, %arg1 : tensor<4xf32> 9 | %1 = "xla_hlo.mul"(%0, %arg1) {name = "mul.4"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> 10 | 11 | // CHECK-NEXT: %2 = subf %1, %arg1 : tensor<4xf32> 12 | %2 = "xla_hlo.sub"(%1, %arg1) {name = "sub.5"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> 13 | 14 | // CHECK-NEXT: %3 = divf %2, %arg1 : tensor<4xf32> 15 | %3 = "xla_hlo.div"(%2, %arg1) {name = "div.6"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> 16 | 17 | // CHECK-NEXT: return %3 : tensor<4xf32> 18 | return %3 : tensor<4xf32> 19 | } 20 | 21 | // CHECK-LABEL: func @binary_ops_int(%arg0: tensor<4xi32>, %arg1: tensor<4xi32>) -> tensor<4xi32> { 22 | func @binary_ops_int(%arg0: tensor<4xi32>, %arg1: tensor<4xi32>) -> tensor<4xi32> { 23 | // CHECK-NEXT: %0 = addi %arg0, %arg1 : tensor<4xi32> 24 | %0 = "xla_hlo.add"(%arg0, %arg1) {name = "add.3"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi32> 25 | 26 | // CHECK-NEXT: %1 = muli %0, %arg1 : tensor<4xi32> 27 | %1 = "xla_hlo.mul"(%0, %arg1) {name = "mul.4"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi32> 28 | 29 | // CHECK-NEXT: %2 = subi %1, %arg1 : tensor<4xi32> 30 | %2 = "xla_hlo.sub"(%1, %arg1) {name = "sub.5"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi32> 31 | 32 | // CHECK-NEXT: %3 = divis %2, %arg1 : tensor<4xi32> 33 | %3 = "xla_hlo.div"(%2, %arg1) {name = "div.6"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi32> 34 | 35 | // CHECK-NEXT: return %3 : tensor<4xi32> 36 | return %3 : tensor<4xi32> 37 | } 38 | 39 | // Broadcasting is not currently supported. 40 | // TODO(suderman):Future pass should take all broadcasted binary ops and convert 41 | // them to separate broadcast and binary op. 42 | // CHECK-LABEL: func @binary_ops_broadcast(%arg0: tensor<4x4xf32>, %arg1: tensor<4xf32>) -> tensor<4x4xf32> { 43 | func @binary_ops_broadcast(%arg0: tensor<4x4xf32>, %arg1: tensor<4xf32>) -> tensor<4x4xf32> { 44 | // CHECK-NEXT: %0 = "xla_hlo.add"(%arg0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>, name = "add.3"} : (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 45 | %0 = "xla_hlo.add"(%arg0, %arg1) { 46 | name = "add.3", broadcast_dimensions = dense<1> : tensor<1xi64>} : 47 | (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 48 | 49 | // CHECK-NEXT: %1 = "xla_hlo.mul"(%0, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>, name = "mul.4"} : (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 50 | %1 = "xla_hlo.mul"(%0, %arg1) { 51 | name = "mul.4", broadcast_dimensions = dense<1> : tensor<1xi64>} : 52 | (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 53 | 54 | // CHECK-NEXT: %2 = "xla_hlo.sub"(%1, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>, name = "sub.5"} : (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 55 | %2 = "xla_hlo.sub"(%1, %arg1) { 56 | name = "sub.5", broadcast_dimensions = dense<1> : tensor<1xi64>} : 57 | (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 58 | 59 | // CHECK-NEXT: %3 = "xla_hlo.div"(%2, %arg1) {broadcast_dimensions = dense<1> : tensor<1xi64>, name = "div.6"} : (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 60 | %3 = "xla_hlo.div"(%2, %arg1) { 61 | name = "div.6", broadcast_dimensions = dense<1> : tensor<1xi64>} : 62 | (tensor<4x4xf32>, tensor<4xf32>) -> tensor<4x4xf32> 63 | 64 | // CHECK-NEXT: return %3 : tensor<4x4xf32> 65 | return %3 : tensor<4x4xf32> 66 | } 67 | 68 | // CHECK-LABEL: func @compare_int(%arg0: tensor<4xi32>) -> (tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>) { 69 | func @compare_int(%arg0: tensor<4xi32>) -> (tensor<4xi1>,tensor<4xi1>,tensor<4xi1>,tensor<4xi1>,tensor<4xi1>,tensor<4xi1>) { 70 | // CHECK-NEXT: %0 = cmpi "eq", %arg0, %arg0 : tensor<4xi32> 71 | %0 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "EQ"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi1> 72 | // CHECK-NEXT: %1 = cmpi "ne", %arg0, %arg0 : tensor<4xi32> 73 | %1 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "NE"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi1> 74 | // CHECK-NEXT: %2 = cmpi "slt", %arg0, %arg0 : tensor<4xi32> 75 | %2 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "LT"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi1> 76 | // CHECK-NEXT: %3 = cmpi "sle", %arg0, %arg0 : tensor<4xi32> 77 | %3 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "LE"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi1> 78 | // CHECK-NEXT: %4 = cmpi "sgt", %arg0, %arg0 : tensor<4xi32> 79 | %4 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "GT"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi1> 80 | // CHECK-NEXT: %5 = cmpi "sge", %arg0, %arg0 : tensor<4xi32> 81 | %5 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "GE"} : (tensor<4xi32>, tensor<4xi32>) -> tensor<4xi1> 82 | // CHECK-NEXT: return %0, %1, %2, %3, %4, %5 : tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1> 83 | return %0, %1, %2, %3, %4, %5 : tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1> 84 | } 85 | 86 | // CHECK-LABEL: func @compare_float 87 | func @compare_float(%arg0: tensor<4xf32>) -> (tensor<4xi1>,tensor<4xi1>,tensor<4xi1>,tensor<4xi1>,tensor<4xi1>,tensor<4xi1>) { 88 | // CHECK-NEXT: %0 = cmpf "oeq", %arg0, %arg0 : tensor<4xf32> 89 | %0 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "EQ"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xi1> 90 | // CHECK-NEXT: %1 = cmpf "une", %arg0, %arg0 : tensor<4xf32> 91 | %1 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "NE"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xi1> 92 | // CHECK-NEXT: %2 = cmpf "olt", %arg0, %arg0 : tensor<4xf32> 93 | %2 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "LT"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xi1> 94 | // CHECK-NEXT: %3 = cmpf "ole", %arg0, %arg0 : tensor<4xf32> 95 | %3 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "LE"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xi1> 96 | // CHECK-NEXT: %4 = cmpf "ogt", %arg0, %arg0 : tensor<4xf32> 97 | %4 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "GT"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xi1> 98 | // CHECK-NEXT: %5 = cmpf "oge", %arg0, %arg0 : tensor<4xf32> 99 | %5 = "xla_hlo.compare"(%arg0, %arg0) {comparison_direction = "GE"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xi1> 100 | return %0, %1, %2, %3, %4, %5: tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1>, tensor<4xi1> 101 | } 102 | 103 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/transforms/legalize_control_flow.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This file implements logic for lowering XLA dialect to Standard dialect. 17 | 18 | #include "llvm/ADT/StringSwitch.h" 19 | #include "mlir/IR/Block.h" // TF:local_config_mlir 20 | #include "mlir/IR/BlockAndValueMapping.h" // TF:local_config_mlir 21 | #include "mlir/IR/Builders.h" // TF:local_config_mlir 22 | #include "mlir/IR/Function.h" // TF:local_config_mlir 23 | #include "mlir/IR/PatternMatch.h" // TF:local_config_mlir 24 | #include "mlir/Pass/Pass.h" // TF:local_config_mlir 25 | #include "mlir/Pass/PassRegistry.h" // TF:local_config_mlir 26 | #include "mlir/StandardOps/Ops.h" // TF:local_config_mlir 27 | #include "tensorflow/compiler/mlir/xla/ir/xla_ops.h" 28 | #include "tensorflow/compiler/mlir/xla/transforms/passes.h" 29 | 30 | using mlir::PassRegistration; 31 | 32 | namespace mlir { 33 | namespace XLA { 34 | namespace { 35 | struct LegalizeControlFlow : public mlir::FunctionPass { 36 | // Perform the lowering to MLIR control flow. 37 | void runOnFunction() override; 38 | }; 39 | 40 | bool LowerWhileOp(mlir::XLA::WhileOp while_op) { 41 | // Converts an xla while loop into control flow. This mostly generates the 42 | // right MLIR boilerplate for calling the body / condition functions, then 43 | // branching on their results appropriately. The operation should look similar 44 | // to below: 45 | // 46 | // 47 | // %0 = "xla_hlo.while"(%arg0) {body: @loop, cond: @cond} 48 | // 49 | auto* opInst = while_op.getOperation(); 50 | mlir::OpBuilder builder(while_op); 51 | auto loc = while_op.getLoc(); 52 | 53 | llvm::SmallVector operands; 54 | operands.reserve(while_op.getNumOperands()); 55 | for (auto operand : while_op.getOperands()) { 56 | operands.push_back(operand); 57 | } 58 | 59 | // Break the block into four sections: 60 | // orig_block - operations before the while and the branch into looping check. 61 | // tail_block - operations after the while loop completes. 62 | // cond_block - check the looping condition, then conditionally branch into 63 | // the 64 | // loop or, if condition is false, jump to the tail branch. 65 | // body_block - call the loop body, then jump back to the condition block. 66 | auto* orig_block = opInst->getBlock(); 67 | auto* tail_block = orig_block->splitBlock(opInst); 68 | 69 | auto* cond_block = builder.createBlock(tail_block); 70 | auto* body_block = builder.createBlock(tail_block); 71 | 72 | // Setup the end of the original block: 73 | // 74 | // br ^cond(%arg0) // Jumps to the condition statement. 75 | builder.setInsertionPointToEnd(orig_block); 76 | builder.create(loc, cond_block, operands); 77 | 78 | // Setup the condition block: 79 | // ^cond(%0): 80 | // %1 = call @cond(%0) : (...) -> tensor // Evaluate condition. 81 | // %2 = extract_element %1[] : tensor // Extract the condition value. 82 | // cond_br %2, ^body(%0), ^tail(%0) // Branch. 83 | builder.setInsertionPointToStart(cond_block); 84 | llvm::SmallVector cond_block_arguments; 85 | cond_block_arguments.reserve(while_op.getNumOperands()); 86 | for (auto operand : while_op.getOperands()) { 87 | cond_block->addArgument(operand->getType()); 88 | cond_block_arguments.push_back(cond_block->getArguments().back()); 89 | } 90 | 91 | auto cond_op = builder.create( 92 | loc, while_op.cond(), builder.getTensorType({}, builder.getI1Type()), 93 | cond_block_arguments); 94 | auto cond_value = 95 | builder.create(loc, cond_op.getResult(0)) 96 | .getResult(); 97 | builder.create(loc, cond_value, body_block, 98 | cond_block_arguments, tail_block, 99 | cond_block_arguments); 100 | 101 | // Create the body block: 102 | // ^body(%3: tensor): 103 | // %4 = call @body(%3) // Call the body function to evaluate. 104 | // br ^cond(%4 : tensor) // Continue to the loop condition. 105 | 106 | builder.setInsertionPointToStart(body_block); 107 | llvm::SmallVector body_block_arguments; 108 | body_block_arguments.reserve(while_op.getNumOperands()); 109 | for (auto operand : while_op.getOperands()) { 110 | body_block->addArgument(operand->getType()); 111 | body_block_arguments.push_back(body_block->getArguments().back()); 112 | } 113 | 114 | SmallVector body_result_types(while_op.getResultTypes()); 115 | auto body_op = builder.create( 116 | loc, while_op.body(), body_result_types, body_block_arguments); 117 | llvm::SmallVector body_results; 118 | body_results.reserve(body_op.getNumResults()); 119 | for (auto result : body_op.getResults()) { 120 | body_results.push_back(result); 121 | } 122 | builder.create(loc, cond_block, body_results); 123 | 124 | // Setup the tail block: 125 | // ^tail(%5): 126 | // 127 | llvm::SmallVector tail_block_arguments; 128 | tail_block_arguments.reserve(while_op.getNumOperands()); 129 | 130 | // Erase the original while loop. 131 | for (int i = 0; i < while_op.getNumOperands(); i++) { 132 | tail_block->addArgument(while_op.getOperand(i)->getType()); 133 | while_op.getResult(i)->replaceAllUsesWith(tail_block->getArgument(i)); 134 | } 135 | opInst->erase(); 136 | 137 | return false; 138 | } 139 | 140 | void LegalizeControlFlow::runOnFunction() { 141 | auto func = getFunction(); 142 | llvm::SmallVector control_flow_ops; 143 | func.walk([&](WhileOp op) { control_flow_ops.push_back(op); }); 144 | 145 | for (auto& op : control_flow_ops) { 146 | if (LowerWhileOp(op)) return signalPassFailure(); 147 | } 148 | } 149 | } // namespace 150 | } // namespace XLA 151 | } // namespace mlir 152 | 153 | mlir::FunctionPassBase* mlir::XLA::createLegalizeControlFlowPass() { 154 | return new LegalizeControlFlow(); 155 | } 156 | 157 | static PassRegistration legalize_cf_pass( 158 | "xla-legalize-control-flow", 159 | "Legalize from XLA control flow to MLIR control flow"); 160 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/transforms/legalize_tf.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This file implements logic for lowering TensorFlow dialect to XLA dialect. 17 | 18 | #include 19 | 20 | #include "mlir/IR/PatternMatch.h" // TF:local_config_mlir 21 | #include "mlir/Pass/Pass.h" // TF:local_config_mlir 22 | #include "mlir/StandardOps/Ops.h" // TF:local_config_mlir 23 | #include "tensorflow/compiler/mlir/xla/ir/xla_ops.h" 24 | #include "tensorflow/compiler/mlir/xla/transforms/passes.h" 25 | 26 | using namespace mlir; 27 | 28 | namespace { 29 | struct LegalizeTF : public FunctionPass { 30 | /// Perform the lowering to XLA dialect. 31 | void runOnFunction() override; 32 | }; 33 | } // end anonymous namespace 34 | 35 | FunctionPassBase *mlir::XLA::createLegalizeTFPass() { return new LegalizeTF(); } 36 | 37 | /// Returns if the given TF data format string is the default format. 38 | static bool isDefaultDataFormat(StringRef format) { return format == "NHWC"; } 39 | 40 | /// Returns the feature dimension for the given format and input type. 41 | static size_t getFeatureDimension(StringAttr format, 42 | RankedTensorType inputType) { 43 | return isDefaultDataFormat(format.getValue()) ? inputType.getRank() - 1 : 1; 44 | } 45 | 46 | //===----------------------------------------------------------------------===// 47 | // BatchNorm op utilities. 48 | //===----------------------------------------------------------------------===// 49 | 50 | static IntegerAttr getFeatureDimensionAttr(Builder &b, StringAttr format, 51 | Value *input) { 52 | return b.getI64IntegerAttr( 53 | getFeatureDimension(format, input->getType().cast())); 54 | } 55 | 56 | //===----------------------------------------------------------------------===// 57 | // Bias op utilities. 58 | //===----------------------------------------------------------------------===// 59 | 60 | /// Returns whether the biasAdd feature dimension is valid or not. 61 | static bool hasValidBiasFeatureDimension(StringAttr format, Value *input, 62 | Value *bias) { 63 | auto inputType = input->getType().cast(); 64 | auto biasType = bias->getType().cast(); 65 | 66 | // There must be enough biases as the feature dimension of the input tensor. 67 | size_t featureDim = getFeatureDimension(format, inputType); 68 | return biasType.getDimSize(0) == inputType.getDimSize(featureDim); 69 | } 70 | 71 | /// Return a 1D ElementsAttr for the feature dimension of a BiasAdd. 72 | static ElementsAttr getBiasFeatureDimension(Builder &b, StringAttr format, 73 | Value *input) { 74 | return b.getDenseIntElementsAttr( 75 | b.getTensorType(1, b.getIntegerType(64)), 76 | getFeatureDimension(format, input->getType().cast())); 77 | } 78 | 79 | //===----------------------------------------------------------------------===// 80 | // Binary op utilities. 81 | //===----------------------------------------------------------------------===// 82 | 83 | /// Get a constant splat for the given value type. 84 | template 85 | static ElementsAttr getSplat(Builder &b, Value *val, T constant) { 86 | auto valType = val->getType().cast(); 87 | auto valElementType = valType.getElementType(); 88 | 89 | // Handle integer elements. 90 | Attribute elementAttr; 91 | if (valElementType.isa()) 92 | elementAttr = b.getIntegerAttr(valElementType, constant); 93 | else if (valElementType.isa()) 94 | elementAttr = b.getFloatAttr(valElementType, constant); 95 | else 96 | llvm_unreachable("unhandled element type"); 97 | return DenseElementsAttr::get(valType, elementAttr); 98 | } 99 | 100 | static ElementsAttr getBroadcastDimensionsAttr(Builder &b, Value *x, Value *y) { 101 | TensorType xType = x->getType().dyn_cast(); 102 | TensorType yType = y->getType().dyn_cast(); 103 | if (xType == yType || !xType || !yType) return {}; 104 | 105 | // If the shapes have the same rank, then there is nothing to do. 106 | auto xRank = xType.getRank(), yRank = yType.getRank(); 107 | if (xRank == yRank) return {}; 108 | 109 | // Otherwise if the ranks of the inputs don't match, TensorFlow automatically 110 | // reshapes the smaller by padding with dimensions of size 1 as a prefix. In 111 | // other words to pad a 5-vector to a 3-dimensional tensor it is reshaped to 112 | // have shape [1,1,5]. XLA's automatic broadcast code is able to broadcast 113 | // from lower to higher rank, but doesn't assume you want to pad as a prefix 114 | // of the dimensions, and instead needs to be told which dimensions of the 115 | // higher rank tensor to match to the lower rank tensor. 116 | auto maxRank = std::max(xRank, yRank); 117 | auto minRank = std::min(xRank, yRank); 118 | 119 | // Match the lower rank tensor along the larger-numbered dimensions of the 120 | // higher rank tensor. 121 | SmallVector broadcastDimensions(minRank); 122 | std::iota(broadcastDimensions.begin(), broadcastDimensions.end(), 123 | maxRank - minRank); 124 | 125 | return b.getDenseIntElementsAttr( 126 | b.getTensorType({minRank}, b.getIntegerType(64)), broadcastDimensions); 127 | } 128 | 129 | namespace mlir { 130 | namespace XLA { 131 | namespace { 132 | #include "tensorflow/compiler/mlir/xla/transforms/generated_legalize_tf.inc" 133 | } // end anonymous namespace 134 | } // end namespace XLA 135 | } // end namespace mlir 136 | 137 | /// Perform the lowering to XLA dialect. 138 | void LegalizeTF::runOnFunction() { 139 | OwningRewritePatternList patterns; 140 | auto func = getFunction(); 141 | 142 | // Add the generated patterns to the list. 143 | XLA::populateWithGenerated(func.getContext(), &patterns); 144 | applyPatternsGreedily(func, std::move(patterns)); 145 | } 146 | 147 | static PassRegistration pass( 148 | "xla-legalize-tf", "Legalize from TensorFlow to the XLA dialect"); 149 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/transforms/legalize_tf_patterns.td: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This is the legalization pattern definition file for TF to XLA. 17 | 18 | include "mlir/IR/OpBase.td" 19 | include "mlir/StandardOps/Ops.td" 20 | include "tensorflow/compiler/mlir/tensorflow/ir/tf_ops.td" 21 | include "tensorflow/compiler/mlir/xla/ir/xla_ops.td" 22 | 23 | def NullElementsAttr : NativeCodeCall<"ElementsAttr()">; 24 | 25 | def HasNoUse: Constraint< 26 | CPred<"$0->use_begin() == $0->use_end()">, "has no use">; 27 | 28 | //===----------------------------------------------------------------------===// 29 | // BatchNorm op patterns. 30 | //===----------------------------------------------------------------------===// 31 | 32 | def FeatureDimension : NativeCodeCall< 33 | "getFeatureDimensionAttr($_builder, $0, $1)">; 34 | def FalseBoolAttr : AttrConstraint>; 35 | 36 | def : Pattern< 37 | (TF_FusedBatchNormOp:$root $x, $scale, $offset, $mean, $variance, $epsilon, 38 | $data_format, FalseBoolAttr:$is_training), 39 | [(XLA_BatchNormInferenceOp $x, $scale, $offset, $mean, $variance, 40 | $epsilon, (FeatureDimension $data_format, $x)), 41 | // We already guaranteed that the last four results has no use so it 42 | // does not matter what value we provide here for replacement. 43 | /*batch_mean=*/(replaceWithValue $x), 44 | /*batch_variance=*/(replaceWithValue $x), 45 | /*reserve_space_1=*/(replaceWithValue $x), 46 | /*reserve_space_2=*/(replaceWithValue $x)], 47 | [(HasNoUse $root__1), (HasNoUse $root__2), 48 | (HasNoUse $root__3), (HasNoUse $root__4)]>; 49 | 50 | //===----------------------------------------------------------------------===// 51 | // Bias op patterns. 52 | //===----------------------------------------------------------------------===// 53 | def Is1DShapeTensor 54 | : Type() && " 55 | "$_self.cast().getRank() == 1">>; 56 | def IsAtleast3DShapeTensor 57 | : Type() && " 58 | "$_self.cast().getRank() > 2">>; 59 | 60 | def BiasAddFeatureDimension : NativeCodeCall< 61 | "getBiasFeatureDimension($_builder, $0, $1)">; 62 | def ValidBiasAddFeatureDimension : Constraint< 63 | CPred<"hasValidBiasFeatureDimension($0, $1, $2)">, 64 | "valid biasAdd feature dimension">; 65 | 66 | def : Pat<(TF_BiasAddOp IsAtleast3DShapeTensor:$input, Is1DShapeTensor:$bias, 67 | TF_ConvnetDataFormatAttr:$data_format), 68 | (XLA_AddOp $input, $bias, 69 | (BiasAddFeatureDimension $data_format, $input)), 70 | [(ValidBiasAddFeatureDimension $data_format, $input, $bias)]>; 71 | 72 | //===----------------------------------------------------------------------===// 73 | // Binary op patterns. 74 | //===----------------------------------------------------------------------===// 75 | 76 | // Get the broadcast dimensions attribute from the binary operands. 77 | def BinBroadcastDimensions : NativeCodeCall< 78 | "getBroadcastDimensionsAttr($_builder, $0, $1)">; 79 | 80 | class DirectBinaryPat 81 | : Pat<(FromOp AnyTensor:$l, AnyTensor:$r), 82 | (ToOp $l, $r, (BinBroadcastDimensions $l, $r))>; 83 | 84 | foreach fromToBinPair = [[TF_AddOp, XLA_AddOp], 85 | [TF_DivOp, XLA_DivOp], 86 | [TF_MulOp, XLA_MulOp], 87 | [TF_RealDivOp, XLA_DivOp], 88 | [TF_SubOp, XLA_SubOp]] in 89 | def : DirectBinaryPat; 90 | 91 | //===----------------------------------------------------------------------===// 92 | // Identity op patterns. 93 | //===----------------------------------------------------------------------===// 94 | 95 | def : Pat<(TF_IdentityOp $op), (replaceWithValue $op)>; 96 | 97 | //===----------------------------------------------------------------------===// 98 | // Nullary op patterns. 99 | //===----------------------------------------------------------------------===// 100 | 101 | // TODO(riverriddle) Formalize a policy on converting opaque attributes. 102 | def : Pat<(TF_ConstOp:$res ElementsAttr:$value), (XLA_ConstOp $value), 103 | [(AnyStaticShapeTensor $res)]>; 104 | 105 | //===----------------------------------------------------------------------===// 106 | // Relu op patterns. 107 | //===----------------------------------------------------------------------===// 108 | 109 | class ConstantSplat : NativeCodeCall< 110 | "getSplat($_builder, $0, " # value # ")">; 111 | 112 | def : Pat<(TF_ReluOp AnyTensor:$input), 113 | (XLA_MaxOp (ConstantOp (ConstantSplat<"0"> $input)), $input, 114 | (NullElementsAttr))>; 115 | 116 | def : Pat<(TF_Relu6Op AnyTensor:$input), 117 | (XLA_ClampOp (ConstantOp (ConstantSplat<"0"> $input)), $input, 118 | (ConstantOp (ConstantSplat<"6"> $input)))>; 119 | 120 | //===----------------------------------------------------------------------===// 121 | // Unary op patterns. 122 | //===----------------------------------------------------------------------===// 123 | 124 | def : Pat<(TF_ReshapeOp:$res AnyStaticShapeTensor:$arg, $ignored), 125 | (XLA_ReshapeOp $arg), [(AnyStaticShapeTensor $res)]>; 126 | 127 | def : Pat<(TF_SqueezeOp AnyStaticShapeTensor:$arg, $ignored_dims), 128 | (XLA_ReshapeOp $arg)>; 129 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/transforms/legalize_to_standard.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This file implements logic for lowering XLA dialect to Standard dialect. 17 | 18 | #include "llvm/ADT/StringSwitch.h" 19 | #include "mlir/IR/Function.h" // TF:local_config_mlir 20 | #include "mlir/IR/PatternMatch.h" // TF:local_config_mlir 21 | #include "mlir/Pass/Pass.h" // TF:local_config_mlir 22 | #include "mlir/StandardOps/Ops.h" // TF:local_config_mlir 23 | #include "tensorflow/compiler/mlir/xla/ir/xla_ops.h" 24 | #include "tensorflow/compiler/mlir/xla/transforms/passes.h" 25 | 26 | using mlir::Builder; 27 | using mlir::FunctionPass; 28 | using mlir::FunctionPassBase; 29 | using mlir::OwningRewritePatternList; 30 | using mlir::PassRegistration; 31 | 32 | namespace mlir { 33 | namespace XLA { 34 | namespace { 35 | #include "tensorflow/compiler/mlir/xla/transforms/generated_legalize_to_standard.inc" 36 | 37 | struct CompareIConvert : public RewritePattern { 38 | explicit CompareIConvert(MLIRContext *context) 39 | : RewritePattern("xla_hlo.compare", 1, context) {} 40 | 41 | PatternMatchResult matchAndRewrite(Operation *op, 42 | PatternRewriter &rewriter) const override { 43 | auto compare_op = cast(op); 44 | 45 | auto lhs = compare_op.lhs(); 46 | auto rhs = compare_op.rhs(); 47 | auto lhs_type = lhs->getType().cast(); 48 | auto rhs_type = rhs->getType().cast(); 49 | 50 | // Broadcasting not supported by this rewrite. 51 | if (lhs_type.getShape() != rhs_type.getShape()) return matchFailure(); 52 | 53 | if (!lhs_type.getElementType().isa() || 54 | !rhs_type.getElementType().isa()) 55 | return matchFailure(); 56 | 57 | auto comparison_direction = compare_op.comparison_direction(); 58 | CmpIPredicate compare_predicate = 59 | llvm::StringSwitch(comparison_direction) 60 | .Case("EQ", CmpIPredicate::EQ) 61 | .Case("NE", CmpIPredicate::NE) 62 | .Case("LT", CmpIPredicate::SLT) 63 | .Case("LE", CmpIPredicate::SLE) 64 | .Case("GT", CmpIPredicate::SGT) 65 | .Case("GE", CmpIPredicate::SGE) 66 | .Default(CmpIPredicate::NumPredicates); 67 | 68 | if (compare_predicate == CmpIPredicate::NumPredicates) 69 | return matchFailure(); 70 | 71 | rewriter.replaceOpWithNewOp(op, compare_predicate, lhs, rhs); 72 | return matchSuccess(); 73 | } 74 | }; 75 | 76 | struct CompareFConvert : public RewritePattern { 77 | explicit CompareFConvert(MLIRContext *context) 78 | : RewritePattern("xla_hlo.compare", 1, context) {} 79 | 80 | PatternMatchResult matchAndRewrite(Operation *op, 81 | PatternRewriter &rewriter) const override { 82 | auto compare_op = cast(op); 83 | 84 | auto lhs = compare_op.lhs(); 85 | auto rhs = compare_op.rhs(); 86 | auto lhs_type = lhs->getType().cast(); 87 | auto rhs_type = rhs->getType().cast(); 88 | 89 | // Broadcasting not supported by this rewrite. 90 | if (lhs_type.getShape() != rhs_type.getShape()) return matchFailure(); 91 | 92 | if (!lhs_type.getElementType().isa() || 93 | !rhs_type.getElementType().isa()) 94 | return matchFailure(); 95 | 96 | auto comparison_direction = compare_op.comparison_direction(); 97 | CmpFPredicate compare_predicate = 98 | llvm::StringSwitch(comparison_direction) 99 | .Case("EQ", CmpFPredicate::OEQ) 100 | .Case("NE", CmpFPredicate::UNE) 101 | .Case("LT", CmpFPredicate::OLT) 102 | .Case("LE", CmpFPredicate::OLE) 103 | .Case("GT", CmpFPredicate::OGT) 104 | .Case("GE", CmpFPredicate::OGE) 105 | .Default(CmpFPredicate::NumPredicates); 106 | 107 | if (compare_predicate == CmpFPredicate::NumPredicates) 108 | return matchFailure(); 109 | 110 | rewriter.replaceOpWithNewOp(op, compare_predicate, lhs, rhs); 111 | return matchSuccess(); 112 | } 113 | }; 114 | 115 | } // end anonymous namespace 116 | } // end namespace XLA 117 | } // end namespace mlir 118 | 119 | namespace { 120 | struct LegalizeToStandard : public FunctionPass { 121 | /// Perform the lowering to Standard dialect. 122 | void runOnFunction() override; 123 | }; 124 | } // end anonymous namespace 125 | 126 | FunctionPassBase *mlir::XLA::createLegalizeToStdPass() { 127 | return new LegalizeToStandard(); 128 | } 129 | 130 | /// Perform the lowering to standard dialect. 131 | void LegalizeToStandard::runOnFunction() { 132 | OwningRewritePatternList patterns; 133 | auto func = getFunction(); 134 | 135 | mlir::XLA::populateWithGenerated(func.getContext(), &patterns); 136 | patterns.insert( 137 | &getContext()); 138 | applyPatternsGreedily(func, std::move(patterns)); 139 | } 140 | 141 | static PassRegistration legalize_pass( 142 | "xla-legalize-to-std", "Legalize from XLA dialect to standard dialect"); 143 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/mlir/xla/transforms/legalize_to_standard_patterns.td: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // This is the legalization pattern definition file for XLA to StandardOps. 17 | 18 | include "mlir/IR/OpBase.td" 19 | include "mlir/StandardOps/Ops.td" 20 | include "tensorflow/compiler/mlir/xla/ir/xla_ops.td" 21 | 22 | //===----------------------------------------------------------------------===// 23 | // Binary op patterns. 24 | //===----------------------------------------------------------------------===// 25 | 26 | def IsSameSizePred : CPred< 27 | "$0->getType().cast().getShape() " 28 | "== $1->getType().cast().getShape()">; 29 | def IsSameSizeConstraint : Constraint; 30 | 31 | def : Pat<(XLA_AddOp XLA_FpTensor:$l, XLA_FpTensor:$r, 32 | IsNullAttr:$broadcast_dimensions), 33 | (AddFOp $l, $r), 34 | [(IsSameSizeConstraint $l, $r)]>; 35 | def : Pat<(XLA_SubOp XLA_FpTensor:$l, XLA_FpTensor:$r, 36 | IsNullAttr:$broadcast_dimensions), 37 | (SubFOp $l, $r), 38 | [(IsSameSizeConstraint $l, $r)]>; 39 | def : Pat<(XLA_MulOp XLA_FpTensor:$l, XLA_FpTensor:$r, 40 | IsNullAttr:$broadcast_dimensions), 41 | (MulFOp $l, $r), 42 | [(IsSameSizeConstraint $l, $r)]>; 43 | def : Pat<(XLA_DivOp XLA_FpTensor:$l, XLA_FpTensor:$r, 44 | IsNullAttr:$broadcast_dimensions), 45 | (DivFOp $l, $r), 46 | [(IsSameSizeConstraint $l, $r)]>; 47 | 48 | def : Pat<(XLA_AddOp XLA_IntTensor:$l, XLA_IntTensor:$r, 49 | IsNullAttr:$broadcast_dimensions), 50 | (AddIOp $l, $r), 51 | [(IsSameSizeConstraint $l, $r)]>; 52 | def : Pat<(XLA_SubOp XLA_IntTensor:$l, XLA_IntTensor:$r, 53 | IsNullAttr:$broadcast_dimensions), 54 | (SubIOp $l, $r), 55 | [(IsSameSizeConstraint $l, $r)]>; 56 | def : Pat<(XLA_MulOp XLA_IntTensor:$l, XLA_IntTensor:$r, 57 | IsNullAttr:$broadcast_dimensions), 58 | (MulIOp $l, $r), 59 | [(IsSameSizeConstraint $l, $r)]>; 60 | def : Pat<(XLA_DivOp XLA_IntTensor:$l, XLA_IntTensor:$r, 61 | IsNullAttr:$broadcast_dimensions), 62 | (DivISOp $l, $r), 63 | [(IsSameSizeConstraint $l, $r)]>; 64 | 65 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/compiler/xla/service/gpu/cudnn_conv_padding_legalization.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUDNN_CONV_PADDING_LEGALIZATION_H_ 17 | #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUDNN_CONV_PADDING_LEGALIZATION_H_ 18 | 19 | #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 20 | 21 | namespace xla { 22 | namespace gpu { 23 | 24 | // An HLO pass that canonicalizes convolution instructions for GPU codegen. It 25 | // inserts Pad instructions before Convolution instructions with uncanonicalized 26 | // padding, so that they can be lowered to cuDNN convolution. 27 | class CudnnConvPaddingLegalization : public HloModulePass { 28 | public: 29 | absl::string_view name() const override { 30 | return "cudnn-conv-padding-legalization"; 31 | } 32 | 33 | StatusOr Run(HloModule* module) override; 34 | 35 | private: 36 | StatusOr RunOnComputation(HloComputation* computation); 37 | // Returns if any changes are made to the parent computation. 38 | bool CanonicalizeForwardConvolution(HloInstruction* conv); 39 | bool CanonicalizeBackwardFilterConvolution(HloInstruction* backward_conv); 40 | bool CanonicalizeBackwardInputConvolution(HloInstruction* backward_conv); 41 | }; 42 | 43 | } // namespace gpu 44 | } // namespace xla 45 | 46 | #endif // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUDNN_CONV_PADDING_LEGALIZATION_H_ 47 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/BUILD: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Go API for TensorFlow. 3 | 4 | package( 5 | default_visibility = ["//visibility:private"], 6 | ) 7 | 8 | licenses(["notice"]) # Apache 2.0 9 | 10 | exports_files(["LICENSE"]) 11 | 12 | load( 13 | "//tensorflow:tensorflow.bzl", 14 | "tf_shared_library_deps", 15 | ) 16 | 17 | sh_test( 18 | name = "test", 19 | size = "small", 20 | srcs = ["test.sh"], 21 | data = [ 22 | ":all_files", # Go sources 23 | "//tensorflow/c:headers", # C library header 24 | "//tensorflow/c/eager:headers", # Eager C library header 25 | "//tensorflow/cc/saved_model:saved_model_half_plus_two", # Testdata for LoadSavedModel 26 | ] + tf_shared_library_deps(), 27 | ) 28 | 29 | filegroup( 30 | name = "all_files", 31 | srcs = glob( 32 | ["**/*"], 33 | exclude = [ 34 | "**/METADATA", 35 | "**/OWNERS", 36 | ], 37 | ), 38 | visibility = ["//tensorflow:__subpackages__"], 39 | ) 40 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/README.md: -------------------------------------------------------------------------------- 1 | # TensorFlow in Go 2 | 3 | Construct and execute TensorFlow graphs in Go. 4 | 5 | [![GoDoc](https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go?status.svg)](https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go) 6 | 7 | > *WARNING*: The API defined in this package is not stable and can change 8 | > without notice. The same goes for the package path: 9 | > (`github.com/tensorflow/tensorflow/tensorflow/go`). 10 | 11 | ## Quickstart 12 | 13 | Refer to [Installing TensorFlow for Go](https://www.tensorflow.org/install/lang_go) 14 | 15 | ## Building the TensorFlow C library from source 16 | 17 | If the "Quickstart" instructions above do not work (perhaps the release archives 18 | are not available for your operating system or architecture, or you're using a 19 | different version of CUDA/cuDNN), then the TensorFlow C library must be built 20 | from source. 21 | 22 | ### Prerequisites 23 | 24 | - [bazel](https://www.bazel.build/versions/master/docs/install.html) 25 | - Environment to build TensorFlow from source code 26 | ([Linux or macOS](https://www.tensorflow.org/install/source)). If you don't 27 | need GPU support, then try the following: 28 | 29 | ```sh 30 | sudo apt-get install python swig python-numpy # Linux 31 | brew install swig # OS X with homebrew 32 | ``` 33 | 34 | ### Build 35 | 36 | 1. Download the source code 37 | 38 | ```sh 39 | go get -d github.com/tensorflow/tensorflow/tensorflow/go 40 | ``` 41 | 42 | 2. Build the TensorFlow C library: 43 | 44 | ```sh 45 | cd ${GOPATH}/src/github.com/tensorflow/tensorflow 46 | ./configure 47 | bazel build -c opt //tensorflow:libtensorflow.so 48 | ``` 49 | 50 | This can take a while (tens of minutes, more if also building for GPU). 51 | 52 | 3. Make `libtensorflow.so` and `libtensorflow_framework.so` available to the 53 | linker. This can be done by either: 54 | 55 | a. Copying it to a system location, e.g., 56 | 57 | ```sh 58 | sudo cp ${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow/libtensorflow.so /usr/local/lib 59 | sudo cp ${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow/libtensorflow_framework.so /usr/local/lib 60 | ``` 61 | 62 | OR 63 | 64 | b. Setting environment variables: 65 | 66 | ```sh 67 | export LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow 68 | # Linux 69 | export LD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow 70 | # OS X 71 | export DYLD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow 72 | ``` 73 | 74 | 4. Build and test: 75 | 76 | ```sh 77 | go test github.com/tensorflow/tensorflow/tensorflow/go 78 | ``` 79 | 80 | ### Generate wrapper functions for ops 81 | 82 | Go functions corresponding to TensorFlow operations are generated in `op/wrappers.go`. To regenerate them: 83 | 84 | Prerequisites: 85 | - [Protocol buffer compiler (protoc) 3.x](https://github.com/google/protobuf/releases/) 86 | - The TensorFlow repository under GOPATH 87 | 88 | ```sh 89 | go generate github.com/tensorflow/tensorflow/tensorflow/go/op 90 | ``` 91 | 92 | ## Support 93 | 94 | Use [stackoverflow](http://stackoverflow.com/questions/tagged/tensorflow) and/or 95 | [Github issues](https://github.com/tensorflow/tensorflow/issues). 96 | 97 | ## Contributions 98 | 99 | Contributions are welcome. If making any signification changes, probably best to 100 | discuss on a [Github issue](https://github.com/tensorflow/tensorflow/issues) 101 | before investing too much time. Github pull requests are used for contributions. 102 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/android.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // +build android 16 | 17 | package tensorflow 18 | 19 | // #cgo LDFLAGS: -landroid -llog -lm -lz -ldl 20 | import "C" 21 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/attrs.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | // #include 20 | // #include "tensorflow/c/c_api.h" 21 | import "C" 22 | import ( 23 | "fmt" 24 | "unsafe" 25 | ) 26 | 27 | // makeCShape converts a shape specified in C.int64_t into a Shape. 28 | func makeCShape(shape []C.int64_t) Shape { 29 | s := Shape{dims: make([]int64, len(shape))} 30 | for i, n := range shape { 31 | s.dims[i] = int64(n) 32 | } 33 | return s 34 | } 35 | 36 | // Attr returns the value of an attribute on op. It returns an error if the 37 | // attribute does not exist. 38 | func (op *Operation) Attr(name string) (interface{}, error) { 39 | cname := C.CString(name) 40 | defer C.free(unsafe.Pointer(cname)) 41 | 42 | status := newStatus() 43 | meta := C.TF_OperationGetAttrMetadata(op.c, cname, status.c) 44 | if err := status.Err(); err != nil { 45 | return nil, err 46 | } 47 | 48 | if meta.is_list == 1 { 49 | return listAttribute(op, cname, meta) 50 | } 51 | return scalarAttribute(op, cname, meta) 52 | } 53 | 54 | func listAttribute(op *Operation, cname *C.char, meta C.TF_AttrMetadata) (interface{}, error) { 55 | status := newStatus() 56 | 57 | switch meta._type { 58 | case C.TF_ATTR_STRING: 59 | if meta.list_size == 0 { 60 | return []string(nil), nil 61 | } 62 | values := make([]unsafe.Pointer, meta.list_size) 63 | lengths := make([]C.size_t, meta.list_size) 64 | // Add one element in case total_size is zero. 65 | storage := make([]C.char, meta.total_size+1) 66 | C.TF_OperationGetAttrStringList(op.c, cname, &values[0], &lengths[0], C.int(meta.list_size), unsafe.Pointer(&storage[0]), C.size_t(meta.total_size), status.c) 67 | if err := status.Err(); err != nil { 68 | return nil, err 69 | } 70 | list := make([]string, meta.list_size) 71 | for i, val := range values { 72 | length := lengths[i] 73 | list[i] = C.GoStringN((*C.char)(val), C.int(length)) 74 | } 75 | return list, nil 76 | 77 | case C.TF_ATTR_INT: 78 | if meta.list_size == 0 { 79 | return []int64(nil), nil 80 | } 81 | list := make([]C.int64_t, meta.list_size) 82 | C.TF_OperationGetAttrIntList(op.c, cname, &list[0], C.int(meta.list_size), status.c) 83 | if err := status.Err(); err != nil { 84 | return nil, err 85 | } 86 | vals := make([]int64, meta.list_size) 87 | for i, val := range list { 88 | vals[i] = int64(val) 89 | } 90 | return vals, nil 91 | 92 | case C.TF_ATTR_FLOAT: 93 | if meta.list_size == 0 { 94 | return []float32(nil), nil 95 | } 96 | list := make([]C.float, meta.list_size) 97 | C.TF_OperationGetAttrFloatList(op.c, cname, &list[0], C.int(meta.list_size), status.c) 98 | if err := status.Err(); err != nil { 99 | return nil, err 100 | } 101 | vals := make([]float32, meta.list_size) 102 | for i, val := range list { 103 | vals[i] = float32(val) 104 | } 105 | return vals, nil 106 | 107 | case C.TF_ATTR_BOOL: 108 | if meta.list_size == 0 { 109 | return []bool(nil), nil 110 | } 111 | list := make([]C.uchar, meta.list_size) 112 | C.TF_OperationGetAttrBoolList(op.c, cname, &list[0], C.int(meta.list_size), status.c) 113 | if err := status.Err(); err != nil { 114 | return nil, err 115 | } 116 | vals := make([]bool, meta.list_size) 117 | for i, val := range list { 118 | vals[i] = val == 1 119 | } 120 | return vals, nil 121 | 122 | case C.TF_ATTR_TYPE: 123 | if meta.list_size == 0 { 124 | return []DataType(nil), nil 125 | } 126 | list := make([]C.TF_DataType, meta.list_size) 127 | C.TF_OperationGetAttrTypeList(op.c, cname, &list[0], C.int(meta.list_size), status.c) 128 | if err := status.Err(); err != nil { 129 | return nil, err 130 | } 131 | vals := make([]DataType, meta.list_size) 132 | for i, val := range list { 133 | vals[i] = DataType(val) 134 | } 135 | return vals, nil 136 | 137 | case C.TF_ATTR_TENSOR: 138 | if meta.list_size == 0 { 139 | return []*Tensor(nil), nil 140 | } 141 | list := make([]*C.TF_Tensor, meta.list_size) 142 | C.TF_OperationGetAttrTensorList(op.c, cname, &list[0], C.int(meta.list_size), status.c) 143 | if err := status.Err(); err != nil { 144 | return nil, err 145 | } 146 | vals := make([]*Tensor, meta.list_size) 147 | for i, t := range list { 148 | vals[i] = newTensorFromC(t) 149 | } 150 | return vals, nil 151 | 152 | case C.TF_ATTR_SHAPE: 153 | if meta.list_size == 0 { 154 | return []Shape(nil), nil 155 | } 156 | dims := make([]*C.int64_t, meta.list_size) 157 | numDims := make([]C.int, meta.list_size) 158 | // Add one element in case total_size is zero. 159 | storage := make([]C.int64_t, meta.total_size+1) 160 | C.TF_OperationGetAttrShapeList(op.c, cname, &dims[0], &numDims[0], C.int(meta.list_size), &storage[0], C.int(meta.total_size), status.c) 161 | if err := status.Err(); err != nil { 162 | return nil, err 163 | } 164 | list := make([]Shape, meta.list_size) 165 | for i, dim := range dims { 166 | numDim := numDims[i] 167 | // If the number of dimensions is unknown, default to empty shape. 168 | if numDim < 0 { 169 | continue 170 | } 171 | // A []C.int64_t slice backed by C memory. 172 | // See: https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices 173 | // Using [1<<27] instead of [1<<30] so it works on 32-bit architecture 174 | slice := (*[1 << 27]C.int64_t)(unsafe.Pointer(dim))[:numDim:numDim] 175 | list[i] = makeCShape(slice) 176 | } 177 | return list, nil 178 | 179 | default: 180 | return nil, fmt.Errorf("list type %v not supported", meta._type) 181 | } 182 | } 183 | 184 | func scalarAttribute(op *Operation, cname *C.char, meta C.TF_AttrMetadata) (interface{}, error) { 185 | status := newStatus() 186 | 187 | switch meta._type { 188 | case C.TF_ATTR_STRING: 189 | if meta.total_size == 0 { 190 | return "", nil 191 | } 192 | v := make([]C.char, meta.total_size) 193 | C.TF_OperationGetAttrString(op.c, cname, unsafe.Pointer(&v[0]), C.size_t(meta.total_size), status.c) 194 | if err := status.Err(); err != nil { 195 | return nil, err 196 | } 197 | return C.GoStringN(&v[0], C.int(meta.total_size)), nil 198 | 199 | case C.TF_ATTR_INT: 200 | var v C.int64_t 201 | C.TF_OperationGetAttrInt(op.c, cname, &v, status.c) 202 | return int64(v), status.Err() 203 | 204 | case C.TF_ATTR_FLOAT: 205 | var v C.float 206 | C.TF_OperationGetAttrFloat(op.c, cname, &v, status.c) 207 | return float32(v), status.Err() 208 | 209 | case C.TF_ATTR_BOOL: 210 | var v C.uchar 211 | C.TF_OperationGetAttrBool(op.c, cname, &v, status.c) 212 | return v == 1, status.Err() 213 | 214 | case C.TF_ATTR_TYPE: 215 | var v C.TF_DataType 216 | C.TF_OperationGetAttrType(op.c, cname, &v, status.c) 217 | return DataType(v), status.Err() 218 | 219 | case C.TF_ATTR_TENSOR: 220 | var v *C.TF_Tensor 221 | C.TF_OperationGetAttrTensor(op.c, cname, &v, status.c) 222 | if err := status.Err(); err != nil { 223 | return nil, err 224 | } 225 | return newTensorFromC(v), nil 226 | 227 | case C.TF_ATTR_SHAPE: 228 | numDims := meta.total_size 229 | // If number of dims is unknown return empty shape to indicate that. 230 | if numDims < 0 { 231 | return Shape{}, nil 232 | } 233 | if numDims == 0 { 234 | return ScalarShape(), nil 235 | } 236 | dims := make([]C.int64_t, numDims) 237 | C.TF_OperationGetAttrShape(op.c, cname, (*C.int64_t)(unsafe.Pointer(&dims[0])), C.int(numDims), status.c) 238 | if err := status.Err(); err != nil { 239 | return nil, err 240 | } 241 | return makeCShape(dims), nil 242 | 243 | default: 244 | return nil, fmt.Errorf("type %v not supported", meta._type) 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/context.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | // #include 20 | // #include "tensorflow/c/c_api.h" 21 | // #include "tensorflow/c/eager/c_api.h" 22 | import "C" 23 | import ( 24 | "fmt" 25 | "runtime" 26 | ) 27 | 28 | // ContextOptions contains configuration information for a session 29 | type ContextOptions struct { 30 | // Config is a binary-serialized representation of the 31 | // tensorflow.ConfigProto protocol message 32 | // (https://www.tensorflow.org/code/tensorflow/core/protobuf/config.proto). 33 | Config []byte 34 | 35 | // Sets the default execution mode 36 | Async bool 37 | } 38 | 39 | // c converts the ContextOptions to the C API's TF_ContextOptions. 40 | // Caller takes ownership of returned object. 41 | func (o *ContextOptions) c() (*C.TFE_ContextOptions, error) { 42 | opt := C.TFE_NewContextOptions() 43 | if o == nil { 44 | return opt, nil 45 | } 46 | 47 | if sz := len(o.Config); sz > 0 { 48 | status := newStatus() 49 | cConfig := C.CBytes(o.Config) 50 | C.TFE_ContextOptionsSetConfig(opt, cConfig, C.size_t(sz), status.c) 51 | C.free(cConfig) 52 | if err := status.Err(); err != nil { 53 | C.TFE_DeleteContextOptions(opt) 54 | return nil, fmt.Errorf("invalid ContextOptions.Config: %v", err) 55 | } 56 | } 57 | 58 | var async uint8 59 | if o.Async { 60 | async = 1 61 | } 62 | C.TFE_ContextOptionsSetAsync(opt, C.uchar(async)) 63 | 64 | return opt, nil 65 | } 66 | 67 | // Context for executing operations eagerly. 68 | // 69 | // A Context allows operations to be executed immediately. It encapsulates 70 | // information such as the available devices, resource manager etc. It also 71 | // allows the user to configure execution using a ConfigProto, as they can 72 | // configure a Session when executing a Graph. 73 | type Context struct { 74 | c *C.TFE_Context 75 | } 76 | 77 | // NewContext creates a new context for eager execution. 78 | // options may be nil to use the default options. 79 | func NewContext(options *ContextOptions) (*Context, error) { 80 | status := newStatus() 81 | cOpt, err := options.c() 82 | if err != nil { 83 | return nil, err 84 | } 85 | defer C.TFE_DeleteContextOptions(cOpt) 86 | cContext := C.TFE_NewContext(cOpt, status.c) 87 | if err := status.Err(); err != nil { 88 | return nil, err 89 | } 90 | 91 | c := &Context{c: cContext} 92 | runtime.SetFinalizer(c, (*Context).finalizer) 93 | return c, nil 94 | } 95 | 96 | func (c *Context) finalizer() { 97 | C.TFE_DeleteContext(c.c) 98 | } 99 | 100 | // ListDevices returns the list of devices associated with a Context. 101 | func (c *Context) ListDevices() ([]Device, error) { 102 | status := newStatus() 103 | devicesList := C.TFE_ContextListDevices(c.c, status.c) 104 | if err := status.Err(); err != nil { 105 | return nil, fmt.Errorf("SessionListDevices() failed: %v", err) 106 | } 107 | defer C.TF_DeleteDeviceList(devicesList) 108 | return deviceSliceFromDeviceList(devicesList) 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package tensorflow is a Go binding to TensorFlow. 18 | // 19 | // The API is subject to change and may break at any time. 20 | // 21 | // TensorFlow (www.tensorflow.org) is an open source software library for 22 | // numerical computation using data flow graphs. This package provides 23 | // functionality to build and execute such graphs and depends on 24 | // TensorFlow being available. For installation instructions see 25 | // https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/README.md 26 | package tensorflow 27 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/lib.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | // #cgo LDFLAGS: -ltensorflow 20 | // #cgo CFLAGS: -I${SRCDIR}/../../ 21 | import "C" 22 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/operation.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | // #include 20 | // #include "tensorflow/c/c_api.h" 21 | import "C" 22 | 23 | import "unsafe" 24 | 25 | // Operation that has been added to the graph. 26 | type Operation struct { 27 | c *C.TF_Operation 28 | // A reference to the Graph to prevent it from 29 | // being GCed while the Operation is still alive. 30 | g *Graph 31 | } 32 | 33 | // Name returns the name of the operation. 34 | func (op *Operation) Name() string { 35 | return C.GoString(C.TF_OperationName(op.c)) 36 | } 37 | 38 | // Type returns the name of the operator used by this operation. 39 | func (op *Operation) Type() string { 40 | return C.GoString(C.TF_OperationOpType(op.c)) 41 | } 42 | 43 | // NumOutputs returns the number of outputs of op. 44 | func (op *Operation) NumOutputs() int { 45 | return int(C.TF_OperationNumOutputs(op.c)) 46 | } 47 | 48 | // Device returns a specification of the device on which this operation 49 | // will be executed, or the empty string if there is no such specification. 50 | func (op *Operation) Device() string { 51 | return C.GoString(C.TF_OperationDevice(op.c)) 52 | } 53 | 54 | // OutputListSize returns the size of the list of Outputs that is produced by a 55 | // named output of op. 56 | // 57 | // An Operation has multiple named outputs, each of which produces either 58 | // a single tensor or a list of tensors. This method returns the size of 59 | // the list of tensors for a specific output of the operation, identified 60 | // by its name. 61 | func (op *Operation) OutputListSize(output string) (int, error) { 62 | cname := C.CString(output) 63 | defer C.free(unsafe.Pointer(cname)) 64 | status := newStatus() 65 | n := C.TF_OperationOutputListLength(op.c, cname, status.c) 66 | return int(n), status.Err() 67 | } 68 | 69 | // Output returns the i-th output of op. 70 | func (op *Operation) Output(i int) Output { 71 | return Output{op, i} 72 | } 73 | 74 | // NumInputs returns the number of inputs of op. 75 | func (op *Operation) NumInputs() int { 76 | return int(C.TF_OperationNumInputs(op.c)) 77 | } 78 | 79 | // Output represents one of the outputs of an operation in the graph. Has a 80 | // DataType (and eventually a Shape). May be passed as an input argument to a 81 | // function for adding operations to a graph, or to a Session's Run() method to 82 | // fetch that output as a tensor. 83 | type Output struct { 84 | // Op is the Operation that produces this Output. 85 | Op *Operation 86 | 87 | // Index specifies the index of the output within the Operation. 88 | Index int 89 | } 90 | 91 | // DataType returns the type of elements in the tensor produced by p. 92 | func (p Output) DataType() DataType { 93 | return DataType(C.TF_OperationOutputType(p.c())) 94 | } 95 | 96 | // Shape returns the (possibly incomplete) shape of the tensor produced p. 97 | func (p Output) Shape() Shape { 98 | status := newStatus() 99 | port := p.c() 100 | ndims := C.TF_GraphGetTensorNumDims(p.Op.g.c, port, status.c) 101 | if err := status.Err(); err != nil { 102 | // This should not be possible since an error only occurs if 103 | // the operation does not belong to the graph. It should not 104 | // be possible to construct such an Operation object. 105 | return Shape{} 106 | } 107 | if ndims < 0 { 108 | return Shape{} 109 | } 110 | if ndims == 0 { 111 | return ScalarShape() 112 | } 113 | dims := make([]C.int64_t, ndims) 114 | C.TF_GraphGetTensorShape(p.Op.g.c, port, &dims[0], ndims, status.c) 115 | if err := status.Err(); err != nil { 116 | // Same as above, should not be possible. 117 | return Shape{} 118 | } 119 | ret := Shape{dims: make([]int64, ndims)} 120 | for i := 0; i < int(ndims); i++ { 121 | ret.dims[i] = int64(dims[i]) 122 | } 123 | return ret 124 | } 125 | 126 | func (p Output) c() C.TF_Output { 127 | if p.Op == nil { 128 | // Attempt to provide a more useful panic message than "nil 129 | // pointer dereference". 130 | panic("nil-Operation. If the Output was created with a Scope object, see Scope.Err() for details.") 131 | } 132 | return C.TF_Output{oper: p.Op.c, index: C.int(p.Index)} 133 | } 134 | 135 | func (p Output) canBeAnInput() {} 136 | 137 | // Consumers returns the inputs that consume this output. 138 | func (p Output) Consumers() []Consumer { 139 | max := int(C.TF_OperationOutputNumConsumers(p.c())) 140 | if max == 0 { 141 | return nil 142 | } 143 | inputs := make([]C.TF_Input, max) 144 | n := C.TF_OperationOutputConsumers(p.c(), (*C.TF_Input)(unsafe.Pointer(&inputs[0])), C.int(max)) 145 | inputs = inputs[:int(n)] 146 | 147 | var consumers []Consumer 148 | for _, consumer := range inputs { 149 | consumers = append(consumers, Consumer{ 150 | Index: int(consumer.index), 151 | Op: &Operation{ 152 | c: consumer.oper, 153 | g: p.Op.g, 154 | }, 155 | }) 156 | } 157 | 158 | return consumers 159 | } 160 | 161 | // Consumer identifies a specific input of an operation that consumes the output 162 | // of another operation. 163 | type Consumer struct { 164 | // Op is the Operation that is consuming the output of another operation. 165 | Op *Operation 166 | 167 | // Index is the index of the input within Op that the output of another 168 | // operation is connected to. 169 | Index int 170 | } 171 | 172 | func (p Consumer) c() C.TF_Input { 173 | if p.Op == nil { 174 | // Attempt to provide a more useful panic message than "nil 175 | // pointer dereference". 176 | panic("nil-Operation. Consumer objects should only be created by a call to Output.Consumers") 177 | } 178 | return C.TF_Input{oper: p.Op.c, index: C.int(p.Index)} 179 | } 180 | 181 | // DataType returns the type of the input. 182 | func (p Consumer) DataType() DataType { 183 | return DataType(C.TF_OperationInputType(p.c())) 184 | } 185 | 186 | // Producer returns the Output that is connected to this Consumer. 187 | func (p Consumer) Producer() Output { 188 | output := C.TF_OperationInput(p.c()) 189 | return Output{ 190 | Op: &Operation{ 191 | c: output.oper, 192 | g: p.Op.g, 193 | }, 194 | Index: int(output.index), 195 | } 196 | } 197 | 198 | // Input is the interface for specifying inputs to an operation being added to 199 | // a Graph. 200 | // 201 | // Operations can have multiple inputs, each of which could be either a tensor 202 | // produced by another operation (an Output object), or a list of tensors 203 | // produced by other operations (an OutputList). Thus, this interface is 204 | // implemented by both Output and OutputList. 205 | // 206 | // See OpSpec.Input for more information. 207 | type Input interface { 208 | // Unexported to preclude implementations outside this package. 209 | canBeAnInput() 210 | } 211 | 212 | // OutputList represents a list of Outputs that can be provided as input to 213 | // another operation. 214 | type OutputList []Output 215 | 216 | func (l OutputList) canBeAnInput() {} 217 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/saved_model.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | import ( 20 | "runtime" 21 | "unsafe" 22 | ) 23 | 24 | // #include 25 | // #include "tensorflow/c/c_api.h" 26 | import "C" 27 | 28 | // SavedModel represents the contents of loaded SavedModel. 29 | // TODO(jhseu): Add and document metagraphdef when we pregenerate protobufs. 30 | type SavedModel struct { 31 | Session *Session 32 | Graph *Graph 33 | } 34 | 35 | // LoadSavedModel creates a new SavedModel from a model previously 36 | // exported to a directory on disk. 37 | // 38 | // Exported models contain a set of graphs and, optionally, variable values. 39 | // Tags in the model identify a single graph. LoadSavedModel initializes a 40 | // session with the identified graph and with variables initialized to from the 41 | // checkpoints on disk. 42 | // 43 | // The tensorflow package currently does not have the ability to export a model 44 | // to a directory from Go. This function thus currently targets loading models 45 | // exported in other languages, such as using tf.saved_model.builder in Python. 46 | // See: 47 | // https://www.tensorflow.org/code/tensorflow/python/saved_model/ 48 | func LoadSavedModel(exportDir string, tags []string, options *SessionOptions) (*SavedModel, error) { 49 | status := newStatus() 50 | cOpt, doneOpt, err := options.c() 51 | defer doneOpt() 52 | if err != nil { 53 | return nil, err 54 | } 55 | cExportDir := C.CString(exportDir) 56 | cTags := make([]*C.char, len(tags)) 57 | for i := range tags { 58 | cTags[i] = C.CString(tags[i]) 59 | } 60 | graph := NewGraph() 61 | // TODO(jhseu): Add support for run_options and meta_graph_def. 62 | cSess := C.TF_LoadSessionFromSavedModel(cOpt, nil, cExportDir, (**C.char)(unsafe.Pointer(&cTags[0])), C.int(len(cTags)), graph.c, nil, status.c) 63 | for i := range cTags { 64 | C.free(unsafe.Pointer(cTags[i])) 65 | } 66 | C.free(unsafe.Pointer(cExportDir)) 67 | 68 | if err := status.Err(); err != nil { 69 | return nil, err 70 | } 71 | s := &Session{c: cSess} 72 | runtime.SetFinalizer(s, func(s *Session) { s.Close() }) 73 | return &SavedModel{Session: s, Graph: graph}, nil 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/shape.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | import ( 20 | "fmt" 21 | "strings" 22 | ) 23 | 24 | // Shape represents the (possibly partially known) shape of a tensor that will 25 | // be produced by an operation. 26 | // 27 | // The zero-value of a Shape represents a shape with an unknown number of 28 | // dimensions. 29 | type Shape struct { 30 | dims []int64 31 | } 32 | 33 | // ScalarShape returns a Shape representing a scalar. 34 | func ScalarShape() Shape { 35 | return Shape{dims: make([]int64, 0)} 36 | } 37 | 38 | // MakeShape returns a Shape with the provided size of each dimension. 39 | // 40 | // A value of -1 implies that the size of the corresponding dimension is not 41 | // known. 42 | func MakeShape(shape ...int64) Shape { 43 | cpy := make([]int64, len(shape)) 44 | copy(cpy, shape) 45 | return Shape{dims: cpy} 46 | } 47 | 48 | // NumDimensions returns the number of dimensions represented by s, or -1 if 49 | // unknown. 50 | func (s Shape) NumDimensions() int { 51 | if s.dims == nil { 52 | return -1 53 | } 54 | return len(s.dims) 55 | } 56 | 57 | // Size returns the size of the dim-th dimension of the shape, or -1 if it 58 | // is unknown. 59 | // 60 | // REQUIRES: 0 <= dim < s.NumDimensions() 61 | func (s Shape) Size(dim int) int64 { 62 | if dim < 0 || dim >= s.NumDimensions() { 63 | return -1 64 | } 65 | return s.dims[dim] 66 | } 67 | 68 | // IsFullySpecified returns true iff the size of all the dimensions of s are 69 | // known. 70 | func (s Shape) IsFullySpecified() bool { 71 | if s.dims == nil { 72 | return false 73 | } 74 | for _, size := range s.dims { 75 | if size <= 1 { 76 | return false 77 | } 78 | } 79 | return true 80 | } 81 | 82 | // ToSlice returns the (possibly partially known) shape represented by s as a 83 | // slice, or an error if the number of dimensions is not known. 84 | func (s Shape) ToSlice() ([]int64, error) { 85 | if s.dims == nil { 86 | return nil, fmt.Errorf("cannot create a slice for a Shape with an unknown number of dimensions") 87 | } 88 | cpy := make([]int64, len(s.dims)) 89 | copy(cpy, s.dims) 90 | return cpy, nil 91 | } 92 | 93 | func (s Shape) String() string { 94 | if s.dims == nil { 95 | return "?" 96 | } 97 | ret := fmt.Sprint(s.dims) 98 | for _, size := range s.dims { 99 | if size < 0 { 100 | ret = strings.Replace(ret, fmt.Sprint(size), "?", 1) 101 | } 102 | } 103 | return strings.Replace(ret, " ", ", ", -1) 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/status.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | // #include "tensorflow/c/c_api.h" 20 | import "C" 21 | 22 | import "runtime" 23 | 24 | type code C.TF_Code 25 | 26 | // status holds error information returned by TensorFlow. We convert all 27 | // TF statuses to Go errors. 28 | type status struct { 29 | c *C.TF_Status 30 | } 31 | 32 | func newStatus() *status { 33 | s := &status{C.TF_NewStatus()} 34 | runtime.SetFinalizer(s, (*status).finalizer) 35 | return s 36 | } 37 | 38 | func (s *status) finalizer() { 39 | C.TF_DeleteStatus(s.c) 40 | } 41 | 42 | func (s *status) Code() code { 43 | return code(C.TF_GetCode(s.c)) 44 | } 45 | 46 | func (s *status) String() string { 47 | return C.GoString(C.TF_Message(s.c)) 48 | } 49 | 50 | // Err converts the status to a Go error and returns nil if the status is OK. 51 | func (s *status) Err() error { 52 | if s == nil || s.Code() == C.TF_OK { 53 | return nil 54 | } 55 | return (*statusError)(s) 56 | } 57 | 58 | // statusError is distinct from status because it fulfills the error interface. 59 | // status itself may have a TF_OK code and is not always considered an error. 60 | // 61 | // TODO(jhseu): Make public, rename to Error, and provide a way for users to 62 | // check status codes. 63 | type statusError status 64 | 65 | func (s *statusError) Error() string { 66 | return (*status)(s).String() 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/tensor_handle.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | // #include 20 | // #include "tensorflow/c/c_api.h" 21 | // #include "tensorflow/c/eager/c_api.h" 22 | import "C" 23 | import ( 24 | "runtime" 25 | "unsafe" 26 | ) 27 | 28 | // TensorHandle is a handle to a tensor on a device. 29 | // 30 | // A Tensor referenced by a TensorHandle may be on any device, whereas a Tensor 31 | // always resides in the host CPU's memory. 32 | // 33 | // A Tensor referenced by a TensorHandle may not have been computed yet. For 34 | // example, a TensorHandle might reference the output of an operation that has 35 | // not finished executing. Because of this, various methods, such as Shape() may 36 | // block until the tensor has been instantiated. 37 | // 38 | // This allows multiple operations to be performed on tensors on a device 39 | // (e.g. a GPU) without sending these values back to the host CPU in between 40 | // every operation. 41 | type TensorHandle struct { 42 | c *C.TFE_TensorHandle 43 | } 44 | 45 | // NewTensorHandle creates a new tensor handle from a tensor. 46 | func NewTensorHandle(t *Tensor) (*TensorHandle, error) { 47 | status := newStatus() 48 | cHandle := C.TFE_NewTensorHandle(t.c, status.c) 49 | if err := status.Err(); err != nil { 50 | return nil, err 51 | } 52 | 53 | th := &TensorHandle{c: cHandle} 54 | runtime.SetFinalizer(th, (*TensorHandle).finalizer) 55 | return th, nil 56 | } 57 | 58 | func (th *TensorHandle) finalizer() { 59 | C.TFE_DeleteTensorHandle(th.c) 60 | } 61 | 62 | // newTensorHandleFromC takes ownership of c and returns the owning TensorHandle. 63 | func newTensorHandleFromC(c *C.TFE_TensorHandle) *TensorHandle { 64 | th := &TensorHandle{c: c} 65 | runtime.SetFinalizer(th, (*TensorHandle).finalizer) 66 | return th 67 | } 68 | 69 | // DataType returns the TensorHandle's datatype. 70 | func (th *TensorHandle) DataType() DataType { 71 | return DataType(C.TFE_TensorHandleDataType(th.c)) 72 | } 73 | 74 | // Shape returns the shape of the Tensor referenced by th. 75 | func (th *TensorHandle) Shape() ([]int64, error) { 76 | n, err := th.numDims() 77 | if err != nil { 78 | return nil, err 79 | } 80 | r := make([]int64, n) 81 | for i := 0; i < n; i++ { 82 | if r[i], err = th.dim(i); err != nil { 83 | return nil, err 84 | } 85 | } 86 | return r, nil 87 | } 88 | 89 | // numDims returns the number of dimensions of the TensorHandle. It blocks 90 | // until the operation that produces the handle has completed. 91 | func (th *TensorHandle) numDims() (int, error) { 92 | status := newStatus() 93 | n := int(C.TFE_TensorHandleNumDims(th.c, status.c)) 94 | return n, status.Err() 95 | } 96 | 97 | // dim returns the size of the index'th dimension of the TensorHandle. It 98 | // blocks until the operation that produces the handle has completed. 99 | func (th *TensorHandle) dim(index int) (int64, error) { 100 | status := newStatus() 101 | n := int64(C.TFE_TensorHandleDim(th.c, C.int(index), status.c)) 102 | if err := status.Err(); err != nil { 103 | return 0, err 104 | } 105 | return n, nil 106 | } 107 | 108 | // DeviceName returns the name of the device of the operation that produced the 109 | // TensorHandle. If the handle was produced by a copy, it returns the 110 | // destination device of the copy. Note that returned device name is not always 111 | // the device holding the tensor handle's memory. If you want the latter, use 112 | // BackingDeviceName. This function will block till the operation that produces 113 | // th has completed. 114 | func (th *TensorHandle) DeviceName() (string, error) { 115 | status := newStatus() 116 | name := C.TFE_TensorHandleDeviceName(th.c, status.c) 117 | if err := status.Err(); err != nil { 118 | return "", err 119 | } 120 | return C.GoString(name), nil 121 | } 122 | 123 | // BackingDeviceName returns the name of the device in whose memory the tensor 124 | // handle resides. This function will block till the operation that produces 125 | // `h` has completed. 126 | // 127 | // WARNING: The implementation currently returns the same as DeviceName(). 128 | // After TensoFlow 1.13's C library is released, this implementation will 129 | // be updated to return what the documentation says! 130 | func (th *TensorHandle) BackingDeviceName() (string, error) { 131 | // TODO(ashankar): Restore after TensorFlow 1.13 is released. 132 | // See https://github.com/tensorflow/tensorflow/issues/23257#issuecomment-433751410 133 | return th.DeviceName() 134 | /* 135 | status := newStatus() 136 | name := C.TFE_TensorHandleBackingDeviceName(th.c, status.c) 137 | if err := status.Err(); err != nil { 138 | return "", err 139 | } 140 | return C.GoString(name), nil 141 | */ 142 | } 143 | 144 | // ToTensor returns the Tensor referenced by th. It may block if this tensor is 145 | // not yet computed. 146 | func (th *TensorHandle) ToTensor() (*Tensor, error) { 147 | status := newStatus() 148 | cTensor := C.TFE_TensorHandleResolve(th.c, status.c) 149 | if err := status.Err(); err != nil { 150 | return nil, err 151 | } 152 | return newTensorFromC(cTensor), nil 153 | } 154 | 155 | // CopyToDevice creates a new TensorHandle with the same contents as this 156 | // TensorHandle but placed in the memory of the device 'deviceName'. If source 157 | // and destination are the same device, then this creates a new handle that 158 | // shares the underlying buffer. Otherwise, it currently requires at least one 159 | // of the source or destination devices to be CPU (i.e., for the source or 160 | // destination tensor to be placed in host memory). 161 | func (th *TensorHandle) CopyToDevice(c *Context, deviceName string) (*TensorHandle, error) { 162 | status := newStatus() 163 | n := C.CString(deviceName) 164 | newTh := C.TFE_TensorHandleCopyToDevice(th.c, c.c, n, status.c) 165 | C.free(unsafe.Pointer(n)) 166 | if err := status.Err(); err != nil { 167 | return nil, err 168 | } 169 | return newTensorHandleFromC(newTh), nil 170 | } 171 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | # TensorFlow uses 'bazel' for builds and tests. 18 | # The TensorFlow Go API aims to be usable with the 'go' tool 19 | # (using 'go get' etc.) and thus without bazel. 20 | # 21 | # This script acts as a brige between bazel and go so that: 22 | # bazel test :test 23 | # succeeds iff 24 | # go test github.com/tensorflow/tensorflow/tensorflow/go 25 | # succeeds. 26 | 27 | set -ex 28 | 29 | # Find the 'go' tool 30 | if [[ ! -x "go" && -z $(which go) ]] 31 | then 32 | if [[ -x "/usr/local/go/bin/go" ]] 33 | then 34 | export PATH="${PATH}:/usr/local/go/bin" 35 | else 36 | echo "Could not find the 'go' tool in PATH or /usr/local/go" 37 | exit 1 38 | fi 39 | fi 40 | 41 | # Setup a GOPATH that includes just the TensorFlow Go API. 42 | export GOPATH="${TEST_TMPDIR}/go" 43 | export GOCACHE="${TEST_TMPDIR}/cache" 44 | mkdir -p "${GOPATH}/src/github.com/tensorflow" 45 | ln -s -f "${PWD}" "${GOPATH}/src/github.com/tensorflow/tensorflow" 46 | 47 | # Ensure that the TensorFlow C library is accessible to the 48 | # linker at build and run time. 49 | export LIBRARY_PATH="${PWD}/tensorflow" 50 | OS=$(uname -s) 51 | if [[ "${OS}" = "Linux" ]] 52 | then 53 | if [[ -z "${LD_LIBRARY_PATH}" ]] 54 | then 55 | export LD_LIBRARY_PATH="${PWD}/tensorflow" 56 | else 57 | export LD_LIBRARY_PATH="${PWD}/tensorflow:${LD_LIBRARY_PATH}" 58 | fi 59 | elif [[ "${OS}" = "Darwin" ]] 60 | then 61 | if [[ -z "${DYLD_LIBRARY_PATH}" ]] 62 | then 63 | export DYLD_LIBRARY_PATH="${PWD}/tensorflow" 64 | else 65 | export DYLD_LIBRARY_PATH="${PWD}/tensorflow:${DYLD_LIBRARY_PATH}" 66 | fi 67 | else 68 | echo "Only support Linux/Darwin, System $OS is not supported" 69 | exit 1 70 | fi 71 | 72 | # Document the Go version and run tests 73 | echo "Go version: $(go version)" 74 | go test \ 75 | github.com/tensorflow/tensorflow/tensorflow/go \ 76 | github.com/tensorflow/tensorflow/tensorflow/go/op 77 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/tensorflow/go/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package tensorflow 18 | 19 | // #include 20 | // #include "tensorflow/c/c_api.h" 21 | import "C" 22 | 23 | // Version returns a string describing the version of the underlying TensorFlow 24 | // runtime. 25 | func Version() string { return C.GoString(C.TF_Version()) } 26 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/examples/eager/spinn/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2017, 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/fft2d/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright(C) 1997,2001 Takuya OOURA (email: ooura@kurims.kyoto-u.ac.jp). 2 | You may use, copy, modify this code for any purpose and 3 | without fee. You may distribute this ORIGINAL package. 4 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/gpus/crosstool/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 The TensorFlow Authors. All rights reserved. 2 | 3 | Apache License 4 | Version 2.0, January 2004 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | END OF TERMS AND CONDITIONS 179 | 180 | APPENDIX: How to apply the Apache License to your work. 181 | 182 | To apply the Apache License to your work, attach the following 183 | boilerplate notice, with the fields enclosed by brackets "[]" 184 | replaced with your own identifying information. (Don't include 185 | the brackets!) The text should be enclosed in the appropriate 186 | comment syntax for the file format. We also recommend that a 187 | file or class name and description of purpose be included on the 188 | same "printed page" as the copyright notice for easier 189 | identification within third-party archives. 190 | 191 | Copyright 2015, The TensorFlow Authors. 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. 204 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/gpus/cuda/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 The TensorFlow Authors. All rights reserved. 2 | 3 | Apache License 4 | Version 2.0, January 2004 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | END OF TERMS AND CONDITIONS 179 | 180 | APPENDIX: How to apply the Apache License to your work. 181 | 182 | To apply the Apache License to your work, attach the following 183 | boilerplate notice, with the fields enclosed by brackets "[]" 184 | replaced with your own identifying information. (Don't include 185 | the brackets!) The text should be enclosed in the appropriate 186 | comment syntax for the file format. We also recommend that a 187 | file or class name and description of purpose be included on the 188 | same "printed page" as the copyright notice for easier 189 | identification within third-party archives. 190 | 191 | Copyright 2015, The TensorFlow Authors. 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. 204 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/mkl/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/mkl_dnn/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/mlir/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | Copyright 2019 The MLIR Authors. 2 | 3 | Apache License 4 | Version 2.0, January 2004 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | END OF TERMS AND CONDITIONS 179 | 180 | APPENDIX: How to apply the Apache License to your work. 181 | 182 | To apply the Apache License to your work, attach the following 183 | boilerplate notice, with the fields enclosed by brackets "[]" 184 | replaced with your own identifying information. (Don't include 185 | the brackets!) The text should be enclosed in the appropriate 186 | comment syntax for the file format. We also recommend that a 187 | file or class name and description of purpose be included on the 188 | same "printed page" as the copyright notice for easier 189 | identification within third-party archives. 190 | 191 | Copyright [yyyy] [name of copyright owner] 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. 204 | 205 | 206 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/nccl/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2015-2018, NVIDIA CORPORATION. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of NVIDIA CORPORATION, Lawrence Berkeley National 13 | Laboratory, the U.S. Department of Energy, nor the names of their 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 25 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | The U.S. Department of Energy funded the development of this software 30 | under subcontract 7078610 with Lawrence Berkeley National Laboratory. 31 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/ngraph/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/tensorrt/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 The TensorFlow Authors. All rights reserved. 2 | 3 | Apache License 4 | Version 2.0, January 2004 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | END OF TERMS AND CONDITIONS 179 | 180 | APPENDIX: How to apply the Apache License to your work. 181 | 182 | To apply the Apache License to your work, attach the following 183 | boilerplate notice, with the fields enclosed by brackets "[]" 184 | replaced with your own identifying information. (Don't include 185 | the brackets!) The text should be enclosed in the appropriate 186 | comment syntax for the file format. We also recommend that a 187 | file or class name and description of purpose be included on the 188 | same "printed page" as the copyright notice for easier 189 | identification within third-party archives. 190 | 191 | Copyright 2018, The TensorFlow Authors. 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. 204 | -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/toolchains/preconfig/centos6/tensorrt5/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwgberlin/go-speak/3fdec6861bc4b360008a0c29b4761a7469f3836f/vendor/github.com/tensorflow/tensorflow/third_party/toolchains/preconfig/centos6/tensorrt5/LICENSE -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwgberlin/go-speak/3fdec6861bc4b360008a0c29b4761a7469f3836f/vendor/github.com/tensorflow/tensorflow/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/LICENSE -------------------------------------------------------------------------------- /vendor/github.com/tensorflow/tensorflow/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwgberlin/go-speak/3fdec6861bc4b360008a0c29b4761a7469f3836f/vendor/github.com/tensorflow/tensorflow/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/LICENSE --------------------------------------------------------------------------------