Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of packages(dot)md from manual docs #23

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Manual/09 Parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ package.add(nest, args=(A, B, C), parameters={P0:32, P1:32, P2:32, P3:2.0}, base
In the above scenario, the shape of the nest is parameterized by (`P0`, `P1`, `P2`) and its iteration logic includes the parameter `P3`. The nest is used twice with different settings of these parameters to create two separate functions in the package.

## Parameterized schedules and plans
As mentioned before, parameters can be used in schedules and plans. For example, we can add the following code snippet to the above logic:
As mentioned before, parameters can be used in schedules and plans. For example, we can add the following code snippet to the above code:
```python
P4, P5 = acc.create_parameters(2)

Expand Down
18 changes: 9 additions & 9 deletions docs/Manual/10 Packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@
[//]: # (Version: v1.2.1)

# Section 10: Building Packages
The `Package` class in Accera represents a collection of Accera-generated functions. Whenever a package is built, it creates a stand-alone function library that other pieces of software can use. Currently, Accera supports two package formats: HAT and MLIR.
The `Package` class represents a collection of Accera-generated functions. Whenever a package is built, it creates a stand-alone function library that other pieces of software can use. Currently, Accera supports two package formats: HAT and MLIR.

## HAT package format
[HAT](https://github.com/microsoft/hat) "Header Annotated with TOML" is a format for packaging compiled libraries in the C programming language. HAT implies that a standard C header is styled with useful metadata in the TOML markup language.
[HAT](https://github.com/microsoft/hat) "Header Annotated with TOML" is a format for packaging compiled libraries in the C programming language. HAT implies that a standard C header is styled with useful metadata in the TOML markup language.

Consider that `nest` holds a loop-nest logic. To build a HAT package containing a function with this logic for Windows Operation System, we need to write the following lines of code:
Consider a nest that holds some loop-nest logic. To build a HAT package containing a function with this logic for Windows operating system, we write the following lines of code:
Arslan-e-Mustafa marked this conversation as resolved.
Show resolved Hide resolved
```python
package = acc.Package()
package.add(nest, base_name="func1")
package.build(format=acc.Package.Format.HAT_DYNAMIC, name="myPackage", platform=acc.Package.Platform.WINDOWS)
package.build(format=acc.Package.Format.HAT_DYNAMIC, name="myPackage", platform=acc.Packag+-e.Platform.WINDOWS)
```

The result has two files: `MyPackage.hat` and `MyPackage.lib`. The output directory defaults to current working directory. Though we can change the output directory with this:
The result will be two files: `myPackage.hat` and `myPackage.dll`. The output directory defaults to current working directory. We can change the output directory with `output_dir` set to a relative or absolute path:

```python
package.build(format=acc.Package.Format.HAT_DYNAMIC, name="myPackage", platform=acc.Package.Platform.WINDOWS, output_dir="hat_packages")
```

## MLIR package format
MLIR format is primarily used for debugging purposes and for following the multiple lowering MLIR stages, from Accera DSL, all the way to runnable code.
MLIR format is primarily used for debugging the multiple stages of MLIR lowering, from the Accera DSL all the way to runnable code.
```python
package.build(format=acc.Package.Format.MLIR, name="myPackage")
```

## Function names in packages
We can specify the base name of a function when it is added to a package. The full function name is the base name followed by an automatically generated unique identifier. For example, if the base name is "myFunc" then the function name could be "myFunc_8f24bef5". If no base name is defined, the automatically-generated unique identifier becomes the function name.

The unique identifier ensures that no two functions share the same name. However, invoking the function from the client code becomes cumbersome because the function name could change each time the Accera package is updated and rebuilt. Therefore, the HAT file includes the client code to call the function without the unique identifier. Concretely, if the function signature in C is:
The unique identifier ensures that no two functions share the same name. However, invoking the function from the client code becomes cumbersome because the function name changes each time the Accera package is updated and rebuilt. Therefore, the HAT file includes the client code to call the function without the unique identifier. Concretely, if the function signature in C is:
```
void myFunc_8f24bef5(const float* A, float* B);
```
then the HAT file also contains the line:
```
void (*myFunc)(const float* A, float* B) = myFunc_8f24bef5;
```
The above code makes the abbreviated name `myFunc` an alias of the full function name `myFunc_8f24bef5`. If multiple functions share the same base name, one of them randomly gets the alias.
The above code makes the abbreviated name `myFunc` an alias of the full function name `myFunc_8f24bef5`. If multiple functions share the same base name, the first function in the HAT file gets the alias.

## Debug mode
A package can be built with` mode=acc.Package.Mode.DEBUG`. Doing so creates a special version of each function that validates its own correctness every time the function is called. From the outside, a debugging package looks identical to a standard package. However, each of its functions actually contains two different implementations: the RoboCode implementation (with all of the fancy scheduling and planning) and the trivial default implementation (without any scheduling or planning). When called, the function runs both implementations and asserts that their outputs are within the predefined tolerance. If the outputs don't match, the function prints error messages to `stderr`.
A package can be built with` mode=acc.Package.Mode.DEBUG`. Doing so creates a special version of each function that validates its own correctness every time the function is called. From the outside, a debugging package looks identical to a standard package. However, each of its functions actually contains two different implementations: the Accera implementation (with all of the fancy scheduling and planning) and the trivial default implementation (without any scheduling or planning). When called, the function runs both implementations and asserts that their outputs are within the predefined tolerance. If the outputs don't match, the function prints error messages to `stderr`.
```python
package.build(format=acc.Package.Format.HAT_DYNAMIC, name="myPackage", mode=acc.Package.Mode.DEBUG, tolerance=1.0e-6)
```
Expand Down