Skip to content

Fix build system and failures for linux#68

Merged
Iainmon merged 26 commits into
mainfrom
im-dev
Apr 30, 2025
Merged

Fix build system and failures for linux#68
Iainmon merged 26 commits into
mainfrom
im-dev

Conversation

@Iainmon
Copy link
Copy Markdown
Owner

@Iainmon Iainmon commented Apr 19, 2025

To build the image, run the following command in the root directory of the project:

$ docker build -t chai-build-env . --platform="linux/amd64" --progress=plain

To make a volume for the container, use the following command:

$ docker volume create chai-vol

This volume part might not be necessary.

To run the container, use the following command:

$ docker run -it --platform="linux/amd64" --name chai-vm --hostname chai-vm --privileged --memory 2g --cpus 2 -v chai-vol chai-build-env

Then you may run the following:

root@chai-vm:/app# cd demos/torchtest
root@chai-vm:/app/demos/torchtest# mkdir build
root@chai-vm:/app/demos/torchtest# cd build
root@chai-vm:/app/demos/torchtest/build# cmake ..
root@chai-vm:/app/demos/torchtest/build# make
root@chai-vm:/app/demos/torchtest/build# ./MyProject
Input: [1, 3, 10, 10]
Output: [1, 3, 10, 10]

Locally, you can do

$ export Torch_DIR=<ChAI-root>/libtorch
$ cd demos/torchtest
$ mkdir build
$ cd build
$ cmake -DCMAKE_PREFIX_PATH=<ChAI-root>/libtorch/share/cmake ..
$ make
$ ./MyProject
Input: [1, 3, 10, 10]
Output: [1, 3, 10, 10]

Current Status

Currently, you need to have a working installation of CMake, PyThon, and Chapel to use ChAI.

General build instructions

After cloning,

$ git clone https://github.com/chapel-lang/ChAI.git
$ cd ChAI

use CMake to build the project.

$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Release ..

This will create a build directory and run CMake to generate the necessary build files.

To test if the build environment is working, you can run the following command:

$ make MyExample && make TorchTestBridge

$ ./MyExample
Hello, world!
a: ndarray([[ 0,  1,  2],
         [ 3,  4,  5],
         [ 6,  7,  8]],
       shape = (3, 3),
       rank = 2)

b: ndarray([[ 0,  1,  2],
         [ 3,  4,  5],
         [ 6,  7,  8]],
       shape = (3, 3),
       rank = 2)

c: ndarray([[15, 18, 21],
         [42, 54, 66],
         [69, 90, 111]],
       shape = (3, 3),
       rank = 2)

$ ./TorchTestBridge
Input: [1, 3, 10, 10]
Output: [1, 3, 10, 10]

The first command will compile the MyExample program, which is a simple "Hello, world!" program that uses ChAI. The second command will compile the TorchTestBridge program, which tests the PyTorch interop functionality of ChAI.

See docker-dev-run.md for instructions on how to run the examples in a Docker container. This is useful if either of these build steps fail on your system.

You may also try

$ cd examples/vgg
$ python3 dump_weights.py
$ cd ../..
$ make vgg
$ ./vgg images/frog.jpg
VGG Example Directory: .../ChAI/examples/vgg
Loading labels from .../ChAI/examples/vgg/imagenet/LOC_synset_mapping.txt
Loaded 1000 labels.
Constructing VGG16 model.
Constructed VGG16 model.
Loading VGG16 model weights.
Loaded VGG16 model.
Read file: .../ChAI/build/images/frog.jpg with ext: jpg
imageData shape: (3, 720, 1280)
normalizedImageData shape: (3, 720, 1280)
inputImage shape: (size = 3, sizes = 3 720 1280)
For 'images/frog.jpg' the top 5 predictions are: 
  0: label=tree frog, tree-frog; confidence=27%
  1: label=tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui; confidence=8.2%
  2: label=leafhopper; confidence=4.5%
  3: label=leaf beetle, chrysomelid; confidence=1.9%
  4: label=weevil; confidence=1.5%

@Iainmon Iainmon changed the title Improving LibTorch interop Fix build system and failures for linux Apr 30, 2025
@Iainmon Iainmon merged commit b5dbff2 into main Apr 30, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant