Top Up Prev Next Bottom Contents Index Search

16.4 Class CGGeodesic and Resource Management

When we generate assembly code, we have to allocate memory locations to implement the portholes and states of each star. For high-level language generation, we assign unique identifiers to them. It is rather easy to allocate resources for states since state requirements are visible from the star definition: type, size and name. In this section, we will focus on how to determine the buffer size for the porthole connections.

We allocate a buffer for each connection. We do not assume in the base class, however, that the buffer is owned by the source or by the destination porthole. Instead, we use methods of the CGGeodesic class. Before determining the buffer sizes, we obtain information about how many samples are accumulated on each CGGeodesic by simulating the schedule. This is for the case of synchronous dataflow (SDF) semantics with static scheduling.

The minimum buffer requirement of a connection may be determined by considering only local information about the connection:

int minNeeded() const; 
This method returns that minimum buffer size. It is a protected member of class CGGeodesic.

We do not want to allocate buffers for connections when it is unnecessary. For example, the output portholes of a Fork star can share the same resource with the Fork star's input porthole. A Gain star with unity gain is another trivial example. Therefore, we pay special attention to stars of type Fork. Without confusion, we refer to a star as a Fork star if its outputs can share the same resource with its input. In the CGStar class, we provide the following methods:

int isItFork();
void isaFork();
virtual void forkInit(CGPortHole& input, MultiCGPortHole& output);
virtual void forkInit(CGPortHole& input, CGPortHole& output);
The first is a public method of class CGStar. The rest are protected methods of class CGStar. The first method queries whether the star is a Fork star. The second method is used to declare that the star is a Fork star. If it is, we can call either one of the last two methods, based on whether the output is a MultiPortHole or not. In those methods, we shift delays from a Fork's input port to the output ports, and set the forkSrc pointer of the output ports to point to the Fork's input port. The Fork's input port keeps a list of the output ports in its forkDests member. We apply this procedure recursively in the case of cascaded Forks.

CGPortHole* forkSrc;
SequentialList forkDests;
These are protected members of class CGPortHole. The first one is set by the following public method:

void setForkSource(CGPortHole* p, int cgPortHoleFlag=TRUE); 
The first argument is the input porthole of the Fork star and the port this is being called on should be an output porthole when we call this method.

int fork() const; 
This is a public method of class CGPortHole which returns TRUE if it is an input porthole of a Fork star.

Class CGGeodesic provides two methods to return the Fork input port if it is at a Fork output port. Otherwise these methods return NULL.

CGPortHole* src(); 
const CGPortHole* src() const; 
These two methods are protected and differ from each other in their return type.

Now we will explain more of the methods of class CGGeodesic.

int forkType() const; 
This public method of class CGGeodesic indicates the type of the current CGGeodesic. If it is at a Fork input, it is F_SRC. If it is at a Fork output, it is F_DEST.

int forkDelay() const; 
This public method of class CGGeodesic returns the amount of delay from the current Geodesic up to the fork buffer that this Geodesic refers to. If it is not associated with a fork buffer, it returns 0.

We do not allocate a buffer to a CGGeodesic if it is F_DEST.

int localBufSize() const; 
int bufSize() const;
The above public methods of class CGGeodesic return the buffer size associated with this CGGeodesic. While the first method returns 0 if the CGGeodesic is at a Fork output, the second method returns the size of the fork buffer. The actual computation of the buffer size is done by applying the following method:

virtual int internalBufSize() const;
This protected method of class CGGeodesic returns 0 with an error message if the schedule has not yet been run. If this CGGeodesic is a F_SRC, the minimum size is set to the maximum buffer requirements over all fork destinations. If there are delays or if old values are used, we may want to use a larger size so that compile-time indexing is supportable. The buffer size must divide the total number of tokens produced in one execution. To avoid modulo addressing, we prefer to use the LCM value of the number of samples consumed and produced during one iteration of the schedule. Since this may be wasteful, we check the extra buffer size required for linear addressing with the wasteFactor. If the waste ratio is larger then wasteFactor, we give up on linear addressing.

virtual double wasteFactor() const;
In the CGGeodesic class, this method returns 2.0. If a derived class wants to enforce linear addressing as much as possible, it should set the return value to be large. To force the minimum buffer memory size to be used, the return value should be set to 1.0.

void initialize(); 
This public method of class CGGeodesic initializes the CGGeodesic.

Refer to class CGPortHole for more information on resource management.

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.