---
title: "4.2 DRP-AIを使用したAI実装フロー"
description: "## 4.2 DRP-AIを使用したAI実装フロー ![image45](htt…"
url: "https://manual.amnimo.com/docs/drp-ai-dev/4-2-dev/"
updated: "2026-11-09"
category: "デベロッパーズマニュアル / 第4章　DRP-AIを使用したAI開発（amnimo Xシリーズ）"
---

# 4.2 DRP-AIを使用したAI実装フロー

## 4.2 DRP-AIを使用したAI実装フロー

![image45](https://manual.amnimo.com/wp-content/uploads/2026/11/image45.png)

\*1 PyTorch, the PyTorch logo and any related marks are trademarks of Facebook, Inc. ([https://pytorch.org/](https://pytorch.org/))

\*2 TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc. ([https://www.tensorflow.org/](https://www.tensorflow.org/))

\*3 Microsoft, Cognitive Toolkit are trademarks of the Microsoft group of companies.
 ([https://docs.microsoft.com/en-us/cognitive-toolkit/](https://docs.microsoft.com/en-us/cognitive-toolkit/))

STEP-1：モデルを用意する

STEP-2：モデルをONNXフォーマットへ変換する

STEP-3：ONNXフォーマットモデルをDRP-AIで動かせる形へ変換する

STEP-4：DRP-AIで推論実行するための処理を作成する

サンプルコードを用いてネイティブビルドを実行する手順について説明します。

#### ビルドに必要なaptパッケージのインストール

DRP-AIを使ったアプリをビルドするには、1章の「ネイティブ開発環境」の内容に加え、以下のaptパッケージをインストールしてください。

##### バージョン2系

**実行環境**: エッジゲートウェイ

```
admin@amnimo:~$ sudo apt install linux-libc-dev-extra
```

##### バージョン3系（AIエッジゲートウェイ）

**実行環境**: エッジゲートウェイ

```
admin@amnimo:~$ sudo apt install linux-libc-rzv2ma-dev
```

##### バージョン3系（センサー接続ゲートウェイ）

**実行環境**: エッジゲートウェイ

```
admin@amnimo:~$ sudo apt install linux-libc-rzv2l-dev
```

#### サンプルコード（main.c、Makefile）の作成

以下はDRP-AIのステータスを確認するためのサンプルコードです。

##### main.c

```
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <linux/drpai.h>

int main(void)
{
    int drpai_fd;
    int ret_drpai;
    drpai_status_t drpai_status;

    drpai_fd = open("/dev/drpai0", O_RDWR);
    if (drpai_fd < 0)
    {
        printf("[ERROR] DRP-AI Driver open failed: %s\n", strerror(errno));
        return -1;
    }

    ret_drpai = ioctl(drpai_fd, DRPAI_GET_STATUS, &drpai_status);
    if (ret_drpai == -1)
    {
        printf("[ERROR] DRPAI_GET_STATUS: %s\n", strerror(errno));
      close(drpai_fd);
        return -1;
    }
    printf("DRP-AI status %u\n", drpai_status.status);

    close(drpai_fd);
    return 0;
}
```

##### Makefile

```
CC = gcc
CFLAGS = -O3 -Wall
DESTDIR := /
LIBS =
OBJS = main.o
PROG = amnimo-sample-app

all: $(PROG)

$(PROG): $(OBJS)
	$(CC) $(OBJS) $(LIBS) -o $(PROG)

clean:
	rm -f *.o $(PROG)

install: $(PROG)
	install -D -s $(PROG) $(DESTDIR)/usr/sbin/$(PROG)
```

ディレクトリ構造とファイル配置を以下に示します。

**実行環境**: エッジゲートウェイ

```
admin@amnimo:~/sample$ tree
.
├── main.c
└── Makefile
```

#### ネイティブビルドの実行

**実行環境**: エッジゲートウェイ

```
admin@amnimo:~/sample$ make all
```

#### ビルド結果の実行ファイルの種別の確認

**実行環境**: エッジゲートウェイ

```
admin@amnimo:~/sample$ file amnimo-sample-app
amnimo-sample-app: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=1436db4cc909f72d8565e5f8d14a2b4be47c0515, not stripped
```

#### 実行ファイルの実行

エッジゲートウェイにログインし、実行ファイルを実行します。

**実行環境**: エッジゲートウェイ

```
admin@amnimo:~/sample$ sudo ./amnimo-sample-app
DRP-AI status 1
```
