The compilation process takes nnet and computationrequest as inputs and outputs nnetcomputation. The computationrequest contains a representation of the output index of the request, the available input index.
Create a calculation diagram
More about Computationgraph
computationgraph maps cindexes to cindex_ids and maps cindex_ids to cindexes.
The computationgraph class is defined as follows:
struct Computationgraph { The mapping of cindex_id to CIndex. Std::vector<cindex> cindexes; For each CIndex this tells us whether it is provided as an input to the Computation. Std::vector<bool> Is_input; DEPENDENCIES[CINDEX_ID] gives you, the list of other cindex_ids. Particular cindex_id directly depends on to compute it. std::vector<std::vector<int32> > dependencies; Private Maps each cindex to an integer cindex_id:reverse mapping of "cindexes". Must be accessed via the GETCINDEXID () function. Unordered_map<cindex, Int32, Cindexhasher> cindex_to_cindex_id_; }; |
In addition to the above mappings,computationgraph also preserves the dependencies that each cindex_id needs to compute.
At the beginning of the calculation,descriptor::getdependencies () returns all the Cindex_ids, that is, each cindex_id is dependent on all other cindex_ IDS.
These dependencies are then trimmed according to the requirements of the actual calculation.
Build Computationgraph
Introduced
Computationgraphbuilder is used to build computationgraph. For one of the simplest examples, start with the output from the network request and compute its dependencies forward along the network and add it to the computationgraph until the input node is computed.
Determines whether the computationrequest contains the input nodes on which it is dependent, and if not enough, it cannot be evaluated. (At the 841 Institute Internship, after adding an output layer for an existing DNN , the script concludes that it cannot be calculated, which is dependent on this).
Basic algorithm
This algorithm is not actually used.
When building a calculation diagram, you need to use the following algorithm to determine whether each CIndex can be computed from the input provided:
- Call descriptor::getdependencies () to get all the dependencies at the output layer;
- Call iscomputable () to determine which cindexes in the input can be used for calculations and trim dependencies that do not actually participate in the calculation
- Check that the output of all requests is computable
- Pedicure off all cindex_ids that do not need to participate in the calculation
Organize your calculations into multi-step
CIndex are sorted and grouped according to the topological order, so that the same group of cindexes can be computed simultaneously.
Not to be continued
"Compiling" in the Nnet3 configuration