Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
726127ac
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
726127ac
编写于
7月 22, 2018
作者:
H
hanbuhe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fpga memory managment
上级
4be6a2c1
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
145 addition
and
0 deletion
+145
-0
src/fpga/api/fpga_api.cpp
src/fpga/api/fpga_api.cpp
+64
-0
src/fpga/api/fpga_api.h
src/fpga/api/fpga_api.h
+57
-0
src/memory/t_malloc.cpp
src/memory/t_malloc.cpp
+24
-0
未找到文件。
src/fpga/api/fpga_api.cpp
0 → 100644
浏览文件 @
726127ac
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include "fpga/api/fpga_api.h"
namespace
paddle
{
namespace
mobile
{
namespace
fpga
{
namespace
api
{
static
int
fd
=
-
1
;
static
const
char
*
device_path
=
"/dev/fpgadrv0"
;
static
inline
int
do_ioctl
(
int
req
,
void
*
arg
)
{
return
ioctl
(
req
,
arg
);
}
int
open_device
()
{
if
(
fd
==
-
1
)
{
fd
=
open
(
device_path
,
O_RDWR
);
}
return
fd
;
}
// memory management;
void
*
fpga_malloc
(
size_t
size
)
{
return
reinterpret_cast
<
(
void
*
)
>
mmap64
(
NULL
,
size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
0
);
}
void
fpga_free
(
void
*
ptr
)
{
munmap
(
ptr
,
0
);
}
void
fpga_copy
(
void
*
dest
,
const
void
*
src
,
size_t
num
)
{
memcpy
(
dest
,
src
,
num
);
}
}
// namespace api
}
// namespace fpga
}
// namespace mobile
}
// namespace paddle
src/fpga/api/fpga_api.h
0 → 100644
浏览文件 @
726127ac
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <cstddef>
#include <iostream>
#include <limits>
// memory management;
namespace
paddle
{
namespace
mobile
{
namespace
fpga
{
namespace
api
{
int
open_device
();
int
close_device
();
void
*
fpga_malloc
(
size_t
size
);
void
fpga_free
(
void
*
ptr
);
void
fpga_copy
(
void
*
dst
,
const
void
*
src
,
size_t
num
);
struct
CnnVersionArgs
{
void
*
buf
;
};
struct
QuantArgs
{
float
scale
;
};
struct
BatchNormalizationArgs
{
bool
enable
;
};
struct
ScaleArgs
{};
#define IOCTL_CNN_MAGIC 'CNN'
#define IOCTL_VERSION _IOW(IOCTL_CNN_MAGIC, 1, struct CnnVersionArgs)
#define IOCTL_GET_QUANT _IOW(IOCTL_CNN_MAGIC, 2, struct QuantArgs)
#define IOCTL_SET_QUANT _IOW(IOCTL_CNN_MAGIC, 3, struct QuantArgs)
}
// namespace api
}
// namespace fpga
}
// namespace mobile
}
// namespace paddle
src/memory/t_malloc.cpp
浏览文件 @
726127ac
...
...
@@ -16,10 +16,32 @@ limitations under the License. */
#include <cstdlib>
#include <cstring>
#ifdef PADDLE_MOBILE_FPGA
#include "fpga/api/fpga_api.h"
#endif
namespace
paddle_mobile
{
namespace
memory
{
const
int
MALLOC_ALIGN
=
64
;
#ifdef PADDLE_MOBILE_FPGA
namespace
api
=
paddle
::
mobile
::
fpga
::
api
;
void
Copy
(
void
*
dst
,
const
void
*
src
,
size_t
num
)
{
std
::
memcpy
(
dst
,
src
,
num
);
}
void
*
Alloc
(
size_t
size
)
{
return
api
::
malloc
(
size
);
}
void
Free
(
void
*
ptr
)
{
if
(
ptr
)
{
api
::
fpga_free
(
ptr
);
}
}
#else
void
Copy
(
void
*
dst
,
const
void
*
src
,
size_t
num
)
{
std
::
memcpy
(
dst
,
src
,
num
);
}
...
...
@@ -42,5 +64,7 @@ void Free(void *ptr) {
}
}
#endif
}
// namespace memory
}
// namespace paddle_mobile
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录