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

resources: Fixed some errors and added some extra documentation #150

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
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
19 changes: 12 additions & 7 deletions _pages/documentation/gem5-stdlib/7-using-local-data-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ resource = obtain_resource("id", clients=["data-source-json-1"])

Local resources, in the context of gem5, pertain to resources that users possess and wish to integrate into gem5 but aren't pre-existing in the gem5 resources database.

For users, This offers the flexibility to employ their own resources seamlessly within gem5, bypassing the need to create dedicated resource objects like `BinaryResource`. Instead, they can directly utilize these local resources through `obtain_resource`, streamlining the integration process.
For users, This offers the flexibility to employ their own resources seamlessly within gem5, bypassing the need to create dedicated resource objects using `BinaryResource(local_path=/path/to/binary)`. Instead, they can directly utilize these local resources through `obtain_resource()`, streamlining the integration process.

### Using Custom Resource Configuration and Local Resources

In this example, we will walk through how to set up your custom configuration and utilize your own local resources. For this illustration, we'll employ a JSON file as our resource data source.

#### Creating a Custom Resource Data Source

Let's begin by creating a local JSON object for a resource. This is a bare bones resource that will serve as an example that local resources can be used with obtain resources.
Let's begin by creating a local resource. This is a bare bones resource that will serve as an example. To use local resources with `obtain_resource()`, our bare bones resource need to have a binary file. Here we use an empty binary called `fake-binary`.

To act as this bare bones resource has a source file let us create a file named `fake-binary`. This is just an empty file.
**Note**: Make sure that Gem5 binary and `fake-binary` have same ISA target (RISCV here).

Next, let's create the JSON data source. I'll name the file `my-resources.json`. The contents should look like this:

Expand Down Expand Up @@ -144,7 +144,7 @@ Next, let's create the JSON data source. I'll name the file `my-resources.json`.
]
```

The JSON object of a resource should adhere to the [gem5 resources schema](https://resources.gem5.org/gem5-resources-schema.json).
The JSON file of a resource should adhere to the [gem5 resources schema](https://resources.gem5.org/gem5-resources-schema.json).

**Note**: While the `url` field can be a link, in this case, I'm using a local file.

Expand All @@ -166,16 +166,21 @@ Create a file named `gem5-config.json` with the following content:

#### Running gem5 with a Local Data Source

First, build gem5 with RISC-V:
First, build gem5 with RISCV:

```bash
scons build/RISCV/gem5.opt -j`nproc`
```

Next, run the `local-resource-example.py` file using our local `riscv-hello` resource:
Next, run the `local-resource-example.py` file using our local `test-binary` resource:

Using environment variable
```bash
GEM5_CONFIG=path/to/gem5-config.json ./build/RISCV/gem5.opt configs/example/gem5_library/local-resource-example.py --resource test-binary
GEM5_RESOURCE_JSON_APPEND=path/to/my-resources.json ./build/RISCV/gem5.opt configs/example/gem5_library/local-resource-example.py --resource test-binary
```
or you can overwrite the `gem5_default_config` with our own custom config:

```bash
GEM5_CONFIG=path/to/gem5-config.json ./build/RISCV/gem5.opt configs/example/gem5_library/local-resource-example.py --resource test-binary
```
This command will execute the `local-resource-example.py` script using our locally downloaded resource. This script just calls the obtain_resource function and prints the local path of the resource. This script indicates that local resources function similarly as resources on the gem5 resources database.