Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
饶先宏
hdl4se
提交
00023f01
H
hdl4se
项目概览
饶先宏
/
hdl4se
通知
12
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hdl4se
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
00023f01
编写于
7月 04, 2021
作者:
饶先宏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
202107042112
上级
8f8daf6a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
618 addition
and
35 deletion
+618
-35
examples/hdl4secnn/cnn/cnn/cnn.c
examples/hdl4secnn/cnn/cnn/cnn.c
+2
-2
examples/hdl4secnn/cnn/cnncell/CMakeLists.txt
examples/hdl4secnn/cnn/cnncell/CMakeLists.txt
+5
-3
examples/hdl4secnn/cnn/cnncell/cnncell.c
examples/hdl4secnn/cnn/cnncell/cnncell.c
+5
-21
examples/hdl4secnn/cnn/cnncell/cnncell_concat.c
examples/hdl4secnn/cnn/cnncell/cnncell_concat.c
+314
-0
examples/hdl4secnn/cnn/cnncell/cnncell_convolution.c
examples/hdl4secnn/cnn/cnncell/cnncell_convolution.c
+2
-3
examples/hdl4secnn/cnn/cnncell/cnncell_innerproduct.c
examples/hdl4secnn/cnn/cnncell/cnncell_innerproduct.c
+275
-0
examples/hdl4secnn/cnn/verilog/cnncell.v
examples/hdl4secnn/cnn/verilog/cnncell.v
+11
-2
examples/hdl4secnn/googlenet/CMakeLists.txt
examples/hdl4secnn/googlenet/CMakeLists.txt
+1
-1
examples/hdl4secnn/modeldump/modeldump.cpp
examples/hdl4secnn/modeldump/modeldump.cpp
+3
-3
未找到文件。
examples/hdl4secnn/cnn/cnn/cnn.c
浏览文件 @
00023f01
...
@@ -865,7 +865,7 @@ int node_setup(cnn_layer_node* node, FILE * pCodeFile)
...
@@ -865,7 +865,7 @@ int node_setup(cnn_layer_node* node, FILE * pCodeFile)
"
\t
hdl4se_cnn_innerproduct #(
\n
"
"
\t
hdl4se_cnn_innerproduct #(
\n
"
"
\t\t
%4d, %4d, %4d,
\t
/* 输入大小 */
\n
"
"
\t\t
%4d, %4d, %4d,
\t
/* 输入大小 */
\n
"
"
\t\t
%4d, %4d, %4d
\t
/* 输出大小 */
\n
"
"
\t\t
%4d, %4d, %4d
\t
/* 输出大小 */
\n
"
"
)
\t
\n
"
,
"
\t
)
\n
"
,
node
->
inputsize
[
0
][
1
],
node
->
inputsize
[
0
][
0
],
node
->
inputsize
[
0
][
2
],
node
->
inputsize
[
0
][
1
],
node
->
inputsize
[
0
][
0
],
node
->
inputsize
[
0
][
2
],
node
->
outputsize
[
0
][
1
],
node
->
outputsize
[
0
][
0
],
node
->
outputsize
[
0
][
2
]
node
->
outputsize
[
0
][
1
],
node
->
outputsize
[
0
][
0
],
node
->
outputsize
[
0
][
2
]
);
);
...
@@ -902,7 +902,7 @@ int node_setup(cnn_layer_node* node, FILE * pCodeFile)
...
@@ -902,7 +902,7 @@ int node_setup(cnn_layer_node* node, FILE * pCodeFile)
"
\t\t
%4d, %4d, %4d,
\t
/* 输入2大小 */
\n
"
"
\t\t
%4d, %4d, %4d,
\t
/* 输入2大小 */
\n
"
"
\t\t
%4d, %4d, %4d,
\t
/* 输入3大小 */
\n
"
"
\t\t
%4d, %4d, %4d,
\t
/* 输入3大小 */
\n
"
"
\t\t
%4d, %4d, %4d
\t
/* 输出大小 */
\n
"
"
\t\t
%4d, %4d, %4d
\t
/* 输出大小 */
\n
"
"
\t
)
\t
\n
"
,
"
\t
)
\n
"
,
node
->
inputsize
[
0
][
1
],
node
->
inputsize
[
0
][
0
],
node
->
inputsize
[
0
][
2
],
node
->
inputsize
[
0
][
1
],
node
->
inputsize
[
0
][
0
],
node
->
inputsize
[
0
][
2
],
node
->
inputsize
[
1
][
1
],
node
->
inputsize
[
1
][
0
],
node
->
inputsize
[
1
][
2
],
node
->
inputsize
[
1
][
1
],
node
->
inputsize
[
1
][
0
],
node
->
inputsize
[
1
][
2
],
node
->
inputsize
[
2
][
1
],
node
->
inputsize
[
2
][
0
],
node
->
inputsize
[
2
][
2
],
node
->
inputsize
[
2
][
1
],
node
->
inputsize
[
2
][
0
],
node
->
inputsize
[
2
][
2
],
...
...
examples/hdl4secnn/cnn/cnncell/CMakeLists.txt
浏览文件 @
00023f01
...
@@ -4,9 +4,11 @@
...
@@ -4,9 +4,11 @@
cmake_minimum_required
(
VERSION 3.8
)
cmake_minimum_required
(
VERSION 3.8
)
add_library
(
cnncell STATIC
add_library
(
cnncell STATIC
"cnncell.c"
"cnncell.c"
"cnncell_convolution.c"
"cnncell_convolution.c"
)
"cnncell_innerproduct.c"
"cnncell_concat.c"
)
include_directories
(
"../../../../../lcom/include"
)
include_directories
(
"../../../../../lcom/include"
)
include_directories
(
"../../../../hdl4secell/include"
)
include_directories
(
"../../../../hdl4secell/include"
)
...
...
examples/hdl4secnn/cnn/cnncell/cnncell.c
浏览文件 @
00023f01
...
@@ -44,32 +44,16 @@
...
@@ -44,32 +44,16 @@
static
int
cnncell_registed
=
0
;
static
int
cnncell_registed
=
0
;
/*
extern OFUNCPTR A_u_t_o_registor_hdl4se_ram1p;
extern
OFUNCPTR
A_u_t_o_registor_cnncell_convolution
;
extern OFUNCPTR A_u_t_o_registor_hdl4se_ram2p;
extern
OFUNCPTR
A_u_t_o_registor_cnncell_innerproduct
;
extern OFUNCPTR A_u_t_o_registor_hdl4se_reg;
extern OFUNCPTR A_u_t_o_registor_hdl4se_unop;
extern OFUNCPTR A_u_t_o_registor_hdl4se_binop;
extern OFUNCPTR A_u_t_o_registor_hdl4se_wire;
extern OFUNCPTR A_u_t_o_registor_hdl4se_const;
extern OFUNCPTR A_u_t_o_registor_hdl4se_module;
extern OFUNCPTR A_u_t_o_registor_hdl4se_bind2;
extern OFUNCPTR A_u_t_o_registor_hdl4se_bind3;
extern OFUNCPTR A_u_t_o_registor_hdl4se_bind4;
extern OFUNCPTR A_u_t_o_registor_hdl4se_bindN;
extern OFUNCPTR A_u_t_o_registor_hdl4se_split1;
extern OFUNCPTR A_u_t_o_registor_hdl4se_split2;
extern OFUNCPTR A_u_t_o_registor_hdl4se_split4;
extern OFUNCPTR A_u_t_o_registor_hdl4se_mux2;
extern OFUNCPTR A_u_t_o_registor_hdl4se_mux4;
extern OFUNCPTR A_u_t_o_registor_hdl4se_mux8;
extern OFUNCPTR A_u_t_o_registor_hdl4se_mux16;
*/
int
cnnInit
()
int
cnnInit
()
{
{
if
(
cnncell_registed
)
if
(
cnncell_registed
)
return
0
;
return
0
;
A_u_t_o_registor_cnncell_convolution
();
A_u_t_o_registor_cnncell_innerproduct
();
cnncell_registed
=
1
;
cnncell_registed
=
1
;
return
0
;
return
0
;
}
}
\ No newline at end of file
examples/hdl4secnn/cnn/cnncell/cnncell_concat.c
0 → 100644
浏览文件 @
00023f01
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cnncell_concat.c
修改记录:
202107042057: rxh, initial version
*/
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "object.h"
#include "dlist.h"
#include "cnncell.h"
#include "bignumber.h"
#include "hdl4secell.h"
#define HDL4SEDEBUG 0
/*
(*
HDL4SE="LCOM",
CLSID="8EC66CDF-C750-46A1-AA1F-C44308E1F001",
softmodule="hdl4se"
*)
module hdl4se_cnn_concat4
#(parameter
INW0=128, INH0=64, INC0=1,
INW1=128, INH1=64, INC1=1,
INW2=128, INH2=64, INC2=1,
INW3=128, INH3=64, INC3=1,
OUTW3=128, OUTH3=64, OUTC3=4
)
(
inputsize[0][0] = HEIGHT;
inputsize[0][1] = WIDTH;
inputsize[0][2] = C0;
inputsize[1][0] = HEIGHT;
inputsize[1][1] = WIDTH;
inputsize[1][2] = C1;
inputsize[2][0] = HEIGHT;
inputsize[2][1] = WIDTH;
inputsize[2][2] = C2;
inputsize[3][0] = HEIGHT;
inputsize[3][1] = WIDTH;
inputsize[3][2] = C3;
outputsize[0] = HEIGHT;
outputsize[1] = WIDTH;
outputsize[2] = C0 + C1 + C2 + C3;
0 input wClk,
1 input nwReset,
2 input wDataReadEnable_0,
3 output wDataRead_0,
4 input wDataReadValid_0,
5 output[31:0] bDataReadAddr_0,
6 input[31:0] bDataReadData_0,
7 output wDataReadComplete_0,
8 input wDataReadEnable_1,
9 output wDataRead_1,
10 input wDataReadValid_1,
11 output[31:0] bDataReadAddr_1,
12 input[31:0] bDataReadData_1,
13 output wDataReadComplete_1,
14 input wDataReadEnable_2,
15 output wDataRead_2,
16 input wDataReadValid_2,
17 output[31:0] bDataReadAddr_2,
18 input[31:0] bDataReadData_2,
19 output wDataReadComplete_2,
20 input wDataReadEnable_3,
21 output wDataRead_3,
22 input wDataReadValid_3,
23 output[31:0] bDataReadAddr_3,
24 input[31:0] bDataReadData_3,
25 output wDataReadComplete_3,
26 input wDataWriteEnable,
27 output wDataWrite,
28 output[31:0] bDataWriteAddr,
29 output[31:0] bDataWriteData,
30 output wDataWriteComplete
);
endmodule
*/
/* wClk不算 */
#define INPUTPORTCOUNT 14
#define PARAMCOUNT 15
typedef
struct
_sCNNCellInnerConcat
{
OBJECT_HEADER
INTERFACE_DECLARE
(
IHDL4SEUnit
)
HDL4SEUNIT_VARDECLARE
DLIST_VARDECLARE
IHDL4SEModule
**
parent
;
char
*
name
;
IBigNumber
**
inputdata
;
IHDL4SEUnit
**
input_unit
[
INPUTPORTCOUNT
];
int
input_index
[
INPUTPORTCOUNT
];
union
{
struct
{
int
input_w0
,
input_h0
,
input_c0
;
int
input_w1
,
input_h1
,
input_c1
;
int
input_w2
,
input_h2
,
input_c2
;
int
input_w3
,
input_h3
,
input_c3
;
int
output_w
,
output_h
,
output_c
;
};
int
__param
[
PARAMCOUNT
];
};
int
datavalid
;
}
sCNNCellInnerConcat
;
OBJECT_FUNCDECLARE
(
cnncell_concat
,
CLSID_CNN_CONCAT4
);
HDL4SEUNIT_FUNCDECLARE
(
cnncell_concat
,
CLSID_CNN_CONCAT4
,
sCNNCellInnerConcat
);
DLIST_FUNCIMPL
(
cnncell_concat
,
CLSID_CNN_CONCAT4
,
sCNNCellInnerConcat
);
OBJECT_FUNCIMPL
(
cnncell_concat
,
sCNNCellInnerConcat
,
CLSID_CNN_CONCAT4
);
QUERYINTERFACE_BEGIN
(
cnncell_concat
,
CLSID_CNN_CONCAT4
)
QUERYINTERFACE_ITEM
(
IID_HDL4SEUNIT
,
IHDL4SEUnit
,
sCNNCellInnerConcat
)
QUERYINTERFACE_ITEM
(
IID_DLIST
,
IDList
,
sCNNCellInnerConcat
)
QUERYINTERFACE_END
static
const
char
*
cnncell_concatModuleInfo
()
{
return
"0.3.0-20210704.2057 CNN Concat4 cell"
;
}
static
int
cnncell_concatCreate
(
const
PARAMITEM
*
pParams
,
int
paramcount
,
HOBJECT
*
pObject
)
{
sCNNCellInnerConcat
*
pobj
;
int
i
;
pobj
=
(
sCNNCellInnerConcat
*
)
malloc
(
sizeof
(
sCNNCellInnerConcat
));
if
(
pobj
==
NULL
)
return
-
1
;
*
pObject
=
0
;
HDL4SEUNIT_VARINIT
(
pobj
,
CLSID_CNN_CONCAT4
);
INTERFACE_INIT
(
IHDL4SEUnit
,
pobj
,
cnncell_concat
,
hdl4se_unit
);
DLIST_VARINIT
(
pobj
,
cnncell_concat
);
for
(
i
=
0
;
i
<
INPUTPORTCOUNT
;
i
++
)
pobj
->
input_unit
[
i
]
=
NULL
;
pobj
->
inputdata
=
bigintegerCreate
(
64
);
pobj
->
datavalid
=
0
;
pobj
->
name
=
NULL
;
pobj
->
parent
=
NULL
;
for
(
i
=
0
;
i
<
paramcount
;
i
++
)
{
if
(
pParams
[
i
].
name
==
PARAMID_HDL4SE_UNIT_NAME
)
{
if
(
pobj
->
name
!=
NULL
)
free
(
pobj
->
name
);
pobj
->
name
=
strdup
(
pParams
[
i
].
pvalue
);
}
else
if
(
pParams
[
i
].
name
==
PARAMID_HDL4SE_UNIT_PARENT
)
{
pobj
->
parent
=
(
IHDL4SEModule
**
)
pParams
[
i
].
pvalue
;
}
else
if
(
pParams
[
i
].
name
==
PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS
)
{
IBigNumber
**
temp
=
bigintegerCreate
(
32
);
if
(
temp
!=
NULL
)
{
const
char
*
nstr
;
const
char
*
lstr
;
int
j
;
lstr
=
(
const
char
*
)
pParams
[
i
].
pvalue
;
for
(
j
=
0
;
j
<
PARAMCOUNT
;
j
++
)
{
if
(
0
==
objectCall3
(
temp
,
AssignStr
,
lstr
,
&
nstr
,
0
))
{
objectCall1
(
temp
,
GetInt32
,
&
pobj
->
__param
[
j
]);
lstr
=
nstr
;
}
}
objectRelease
(
temp
);
}
}
}
/* 返回生成的对象 */
OBJECT_RETURN_GEN
(
cnncell_concat
,
pobj
,
pObject
,
CLSID_CNN_CONCAT4
);
return
EIID_OK
;
}
static
void
cnncell_concatDestroy
(
HOBJECT
object
)
{
sCNNCellInnerConcat
*
pobj
;
int
i
;
pobj
=
(
sCNNCellInnerConcat
*
)
objectThis
(
object
);
if
(
pobj
->
name
!=
NULL
)
free
(
pobj
->
name
);
for
(
i
=
0
;
i
<
INPUTPORTCOUNT
;
i
++
)
objectRelease
(
pobj
->
input_unit
[
i
]);
objectRelease
(
pobj
->
inputdata
);
memset
(
pobj
,
0
,
sizeof
(
sCNNCellInnerConcat
));
free
(
pobj
);
}
static
int
cnncell_concatValid
(
HOBJECT
object
)
{
sCNNCellInnerConcat
*
pobj
;
pobj
=
(
sCNNCellInnerConcat
*
)
objectThis
(
object
);
return
1
;
}
static
int
cnncell_concat_hdl4se_unit_GetName
(
HOBJECT
object
,
const
char
**
pname
)
{
sCNNCellInnerConcat
*
pobj
;
pobj
=
(
sCNNCellInnerConcat
*
)
objectThis
(
object
);
*
pname
=
pobj
->
name
;
return
0
;
}
static
int
cnncell_concat_hdl4se_unit_Connect
(
HOBJECT
object
,
int
index
,
HOBJECT
from
,
int
fromindex
)
{
#define CONNECTPORT(ind, innerind) \
if (index == ind) { \
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { \
objectRelease(pobj->input_unit[innerind]); \
pobj->input_unit[innerind] = unit; \
pobj->input_index[innerind] = fromindex; \
} \
}
sCNNCellInnerConcat
*
pobj
;
IHDL4SEUnit
**
unit
=
NULL
;
pobj
=
(
sCNNCellInnerConcat
*
)
objectThis
(
object
);
CONNECTPORT
(
1
,
0
);
/* nwReset */
CONNECTPORT
(
2
,
1
);
/* wDataReadEnable_0 */
CONNECTPORT
(
4
,
2
);
/* wDataReadValid_0 */
CONNECTPORT
(
6
,
3
);
/* bDataReadData_0 */
CONNECTPORT
(
8
,
4
);
/* wDataReadEnable_1 */
CONNECTPORT
(
10
,
5
);
/* wDataReadValid_1 */
CONNECTPORT
(
12
,
6
);
/* bDataReadData_1 */
CONNECTPORT
(
14
,
7
);
/* wDataReadEnable_2 */
CONNECTPORT
(
16
,
8
);
/* wDataReadValid_2 */
CONNECTPORT
(
18
,
9
);
/* bDataReadData_2 */
CONNECTPORT
(
20
,
10
);
/* wDataReadEnable_3 */
CONNECTPORT
(
22
,
11
);
/* wDataReadValid_3 */
CONNECTPORT
(
24
,
12
);
/* bDataReadData_3 */
CONNECTPORT
(
26
,
13
);
/* wDataWriteEnable */
return
0
;
}
static
int
cnncell_concat_hdl4se_unit_GetValue
(
HOBJECT
object
,
int
index
,
int
width
,
IBigNumber
**
value
)
{
int
i
;
int
outputwidth
=
0
;
sCNNCellInnerConcat
*
pobj
;
pobj
=
(
sCNNCellInnerConcat
*
)
objectThis
(
object
);
if
(
pobj
->
datavalid
==
0
)
{
pobj
->
datavalid
=
1
;
}
if
(
width
<=
0
)
{
objectCall1
(
value
,
SetUnsigned
,
1
);
objectCall1
(
value
,
SetWidth
,
outputwidth
);
}
// objectCall1(value, Assign, pobj->out_data);
return
0
;
}
static
int
cnncell_concat_hdl4se_unit_ClkTick
(
HOBJECT
object
)
{
sCNNCellInnerConcat
*
pobj
;
pobj
=
(
sCNNCellInnerConcat
*
)
objectThis
(
object
);
return
0
;
}
static
int
cnncell_concat_hdl4se_unit_Setup
(
HOBJECT
object
)
{
sCNNCellInnerConcat
*
pobj
;
pobj
=
(
sCNNCellInnerConcat
*
)
objectThis
(
object
);
pobj
->
datavalid
=
0
;
return
0
;
}
examples/hdl4secnn/cnn/cnncell/cnncell_convolution.c
浏览文件 @
00023f01
...
@@ -107,10 +107,10 @@ typedef struct _sCNNCellConvolution {
...
@@ -107,10 +107,10 @@ typedef struct _sCNNCellConvolution {
int
output_w
,
output_h
,
output_c
;
int
output_w
,
output_h
,
output_c
;
int
kw
,
kh
,
sw
,
sh
,
pw
,
ph
;
int
kw
,
kh
,
sw
,
sh
,
pw
,
ph
;
int
actfunc
;
int
actfunc
;
int
datavalid
;
};
};
int
__param
[
PARAMCOUNT
];
int
__param
[
PARAMCOUNT
];
};
};
int
datavalid
;
}
sCNNCellConvolution
;
}
sCNNCellConvolution
;
OBJECT_FUNCDECLARE
(
cnncell_convolution
,
CLSID_CNN_CONVOLUTION
);
OBJECT_FUNCDECLARE
(
cnncell_convolution
,
CLSID_CNN_CONVOLUTION
);
...
@@ -134,7 +134,6 @@ static int cnncell_convolutionCreate(const PARAMITEM* pParams, int paramcount, H
...
@@ -134,7 +134,6 @@ static int cnncell_convolutionCreate(const PARAMITEM* pParams, int paramcount, H
{
{
sCNNCellConvolution
*
pobj
;
sCNNCellConvolution
*
pobj
;
int
i
;
int
i
;
int
outputwidthvalid
;
pobj
=
(
sCNNCellConvolution
*
)
malloc
(
sizeof
(
sCNNCellConvolution
));
pobj
=
(
sCNNCellConvolution
*
)
malloc
(
sizeof
(
sCNNCellConvolution
));
if
(
pobj
==
NULL
)
if
(
pobj
==
NULL
)
return
-
1
;
return
-
1
;
...
@@ -242,7 +241,7 @@ static int cnncell_convolution_hdl4se_unit_Connect(HOBJECT object, int index, HO
...
@@ -242,7 +241,7 @@ static int cnncell_convolution_hdl4se_unit_Connect(HOBJECT object, int index, HO
static
int
cnncell_convolution_hdl4se_unit_GetValue
(
HOBJECT
object
,
int
index
,
int
width
,
IBigNumber
**
value
)
static
int
cnncell_convolution_hdl4se_unit_GetValue
(
HOBJECT
object
,
int
index
,
int
width
,
IBigNumber
**
value
)
{
{
int
i
;
int
i
;
int
outputwidth
;
int
outputwidth
=
0
;
sCNNCellConvolution
*
pobj
;
sCNNCellConvolution
*
pobj
;
pobj
=
(
sCNNCellConvolution
*
)
objectThis
(
object
);
pobj
=
(
sCNNCellConvolution
*
)
objectThis
(
object
);
if
(
pobj
->
datavalid
==
0
)
{
if
(
pobj
->
datavalid
==
0
)
{
...
...
examples/hdl4secnn/cnn/cnncell/cnncell_innerproduct.c
0 → 100644
浏览文件 @
00023f01
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cnncell_innerproduct.c
修改记录:
202107042044: rxh, initial version
*/
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "object.h"
#include "dlist.h"
#include "cnncell.h"
#include "bignumber.h"
#include "hdl4secell.h"
#define HDL4SEDEBUG 0
/*
(*
HDL4SE="LCOM",
CLSID="78B9BEC2-3DF7-4421-9274-645BFB60320B",
softmodule="hdl4se"
*)
module hdl4se_cnn_innerproduct
#(parameter
INW=1, INH=1, INC=1024
OUTW=1, OUTH=1, OUTC=1000
)
(
inputsize[0] = HEIGHT;
inputsize[1] = WIDTH;
inputsize[2] = COMPONENT;
outputsize[0] = 1;
outputsize[1] = 1;
outputsize[2] = N;
0 input wClk,
1 input nwReset,
2 output wCoeffRead,
3 input wCoeffReadValid,
4 output[31:0] bCoeffReadAddr,
5 input[31:0] bCoeffReadData,
6 input wDataReadEnable,
7 output wDataRead,
8 input wDataReadValid,
9 output[31:0] bDataReadAddr,
10 input[31:0] bDataReadData,
11 output wDataReadComplete,
12 input wDataWriteEnable,
13 output wDataWrite,
14 output[31:0] bDataWriteAddr,
15 output[31:0] bDataWriteData,
16 output wDataWriteComplete
);
endmodule
*/
/* wClk不算 */
#define INPUTPORTCOUNT 7
#define PARAMCOUNT 6
typedef
struct
_sCNNCellInnerProduct
{
OBJECT_HEADER
INTERFACE_DECLARE
(
IHDL4SEUnit
)
HDL4SEUNIT_VARDECLARE
DLIST_VARDECLARE
IHDL4SEModule
**
parent
;
char
*
name
;
IBigNumber
**
inputdata
;
IHDL4SEUnit
**
input_unit
[
INPUTPORTCOUNT
];
int
input_index
[
INPUTPORTCOUNT
];
union
{
struct
{
int
input_w
,
input_h
,
input_c
;
int
output_w
,
output_h
,
output_c
;
};
int
__param
[
PARAMCOUNT
];
};
int
datavalid
;
}
sCNNCellInnerProduct
;
OBJECT_FUNCDECLARE
(
cnncell_innerproduct
,
CLSID_CNN_INNERPRODUCT
);
HDL4SEUNIT_FUNCDECLARE
(
cnncell_innerproduct
,
CLSID_CNN_INNERPRODUCT
,
sCNNCellInnerProduct
);
DLIST_FUNCIMPL
(
cnncell_innerproduct
,
CLSID_CNN_INNERPRODUCT
,
sCNNCellInnerProduct
);
OBJECT_FUNCIMPL
(
cnncell_innerproduct
,
sCNNCellInnerProduct
,
CLSID_CNN_INNERPRODUCT
);
QUERYINTERFACE_BEGIN
(
cnncell_innerproduct
,
CLSID_CNN_INNERPRODUCT
)
QUERYINTERFACE_ITEM
(
IID_HDL4SEUNIT
,
IHDL4SEUnit
,
sCNNCellInnerProduct
)
QUERYINTERFACE_ITEM
(
IID_DLIST
,
IDList
,
sCNNCellInnerProduct
)
QUERYINTERFACE_END
static
const
char
*
cnncell_innerproductModuleInfo
()
{
return
"0.3.0-20210704.2044 CNN InnerProduct cell"
;
}
static
int
cnncell_innerproductCreate
(
const
PARAMITEM
*
pParams
,
int
paramcount
,
HOBJECT
*
pObject
)
{
sCNNCellInnerProduct
*
pobj
;
int
i
;
pobj
=
(
sCNNCellInnerProduct
*
)
malloc
(
sizeof
(
sCNNCellInnerProduct
));
if
(
pobj
==
NULL
)
return
-
1
;
*
pObject
=
0
;
HDL4SEUNIT_VARINIT
(
pobj
,
CLSID_CNN_INNERPRODUCT
);
INTERFACE_INIT
(
IHDL4SEUnit
,
pobj
,
cnncell_innerproduct
,
hdl4se_unit
);
DLIST_VARINIT
(
pobj
,
cnncell_innerproduct
);
for
(
i
=
0
;
i
<
INPUTPORTCOUNT
;
i
++
)
pobj
->
input_unit
[
i
]
=
NULL
;
pobj
->
inputdata
=
bigintegerCreate
(
64
);
pobj
->
datavalid
=
0
;
pobj
->
name
=
NULL
;
pobj
->
parent
=
NULL
;
for
(
i
=
0
;
i
<
paramcount
;
i
++
)
{
if
(
pParams
[
i
].
name
==
PARAMID_HDL4SE_UNIT_NAME
)
{
if
(
pobj
->
name
!=
NULL
)
free
(
pobj
->
name
);
pobj
->
name
=
strdup
(
pParams
[
i
].
pvalue
);
}
else
if
(
pParams
[
i
].
name
==
PARAMID_HDL4SE_UNIT_PARENT
)
{
pobj
->
parent
=
(
IHDL4SEModule
**
)
pParams
[
i
].
pvalue
;
}
else
if
(
pParams
[
i
].
name
==
PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS
)
{
IBigNumber
**
temp
=
bigintegerCreate
(
32
);
if
(
temp
!=
NULL
)
{
const
char
*
nstr
;
const
char
*
lstr
;
int
j
;
lstr
=
(
const
char
*
)
pParams
[
i
].
pvalue
;
for
(
j
=
0
;
j
<
PARAMCOUNT
;
j
++
)
{
if
(
0
==
objectCall3
(
temp
,
AssignStr
,
lstr
,
&
nstr
,
0
))
{
objectCall1
(
temp
,
GetInt32
,
&
pobj
->
__param
[
j
]);
lstr
=
nstr
;
}
}
objectRelease
(
temp
);
}
}
}
/* 返回生成的对象 */
OBJECT_RETURN_GEN
(
cnncell_innerproduct
,
pobj
,
pObject
,
CLSID_CNN_INNERPRODUCT
);
return
EIID_OK
;
}
static
void
cnncell_innerproductDestroy
(
HOBJECT
object
)
{
sCNNCellInnerProduct
*
pobj
;
int
i
;
pobj
=
(
sCNNCellInnerProduct
*
)
objectThis
(
object
);
if
(
pobj
->
name
!=
NULL
)
free
(
pobj
->
name
);
for
(
i
=
0
;
i
<
INPUTPORTCOUNT
;
i
++
)
objectRelease
(
pobj
->
input_unit
[
i
]);
objectRelease
(
pobj
->
inputdata
);
memset
(
pobj
,
0
,
sizeof
(
sCNNCellInnerProduct
));
free
(
pobj
);
}
static
int
cnncell_innerproductValid
(
HOBJECT
object
)
{
sCNNCellInnerProduct
*
pobj
;
pobj
=
(
sCNNCellInnerProduct
*
)
objectThis
(
object
);
return
1
;
}
static
int
cnncell_innerproduct_hdl4se_unit_GetName
(
HOBJECT
object
,
const
char
**
pname
)
{
sCNNCellInnerProduct
*
pobj
;
pobj
=
(
sCNNCellInnerProduct
*
)
objectThis
(
object
);
*
pname
=
pobj
->
name
;
return
0
;
}
static
int
cnncell_innerproduct_hdl4se_unit_Connect
(
HOBJECT
object
,
int
index
,
HOBJECT
from
,
int
fromindex
)
{
#define CONNECTPORT(ind, innerind) \
if (index == ind) { \
if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { \
objectRelease(pobj->input_unit[innerind]); \
pobj->input_unit[innerind] = unit; \
pobj->input_index[innerind] = fromindex; \
} \
}
sCNNCellInnerProduct
*
pobj
;
IHDL4SEUnit
**
unit
=
NULL
;
pobj
=
(
sCNNCellInnerProduct
*
)
objectThis
(
object
);
CONNECTPORT
(
1
,
0
);
/* nwReset */
CONNECTPORT
(
3
,
1
);
/* wCoeffReadValid */
CONNECTPORT
(
5
,
2
);
/* bCoeffReadData */
CONNECTPORT
(
6
,
3
);
/* wDataReadEnable */
CONNECTPORT
(
8
,
4
);
/* wDataReadValid */
CONNECTPORT
(
10
,
5
);
/* bDataReadData */
CONNECTPORT
(
12
,
6
);
/* wDataWriteEnable */
return
0
;
}
static
int
cnncell_innerproduct_hdl4se_unit_GetValue
(
HOBJECT
object
,
int
index
,
int
width
,
IBigNumber
**
value
)
{
int
i
;
int
outputwidth
=
0
;
sCNNCellInnerProduct
*
pobj
;
pobj
=
(
sCNNCellInnerProduct
*
)
objectThis
(
object
);
if
(
pobj
->
datavalid
==
0
)
{
pobj
->
datavalid
=
1
;
}
if
(
width
<=
0
)
{
objectCall1
(
value
,
SetUnsigned
,
1
);
objectCall1
(
value
,
SetWidth
,
outputwidth
);
}
// objectCall1(value, Assign, pobj->out_data);
return
0
;
}
static
int
cnncell_innerproduct_hdl4se_unit_ClkTick
(
HOBJECT
object
)
{
sCNNCellInnerProduct
*
pobj
;
pobj
=
(
sCNNCellInnerProduct
*
)
objectThis
(
object
);
return
0
;
}
static
int
cnncell_innerproduct_hdl4se_unit_Setup
(
HOBJECT
object
)
{
sCNNCellInnerProduct
*
pobj
;
pobj
=
(
sCNNCellInnerProduct
*
)
objectThis
(
object
);
pobj
->
datavalid
=
0
;
return
0
;
}
examples/hdl4secnn/cnn/verilog/cnncell.v
浏览文件 @
00023f01
...
@@ -261,7 +261,10 @@ DEFINE_GUID(<<name>>,
...
@@ -261,7 +261,10 @@ DEFINE_GUID(<<name>>,
softmodule
=
"hdl4se"
softmodule
=
"hdl4se"
*
)
*
)
module
hdl4se_cnn_innerproduct
module
hdl4se_cnn_innerproduct
#(
parameter
WIDTH
=
1024
,
HEIGHT
=
1000
,
COMPONENT
=
1
,
N
=
1
)
#(
parameter
INW
=
1
,
INH
=
1
,
INC
=
1024
OUTW
=
1
,
OUTH
=
1
,
OUTC
=
1000
)
(
(
/*
/*
inputsize[0] = HEIGHT;
inputsize[0] = HEIGHT;
...
@@ -305,7 +308,13 @@ DEFINE_GUID(<<name>>,
...
@@ -305,7 +308,13 @@ DEFINE_GUID(<<name>>,
softmodule
=
"hdl4se"
softmodule
=
"hdl4se"
*
)
*
)
module
hdl4se_cnn_concat4
module
hdl4se_cnn_concat4
#(
parameter
WIDTH
=
128
,
HEIGHT
=
64
,
C0
=
1
,
C1
=
2
,
C2
=
3
,
c3
=
4
,
N
=
1
)
#(
parameter
INW0
=
128
,
INH0
=
64
,
INC0
=
1
,
INW1
=
128
,
INH1
=
64
,
INC1
=
1
,
INW2
=
128
,
INH2
=
64
,
INC2
=
1
,
INW3
=
128
,
INH3
=
64
,
INC3
=
1
,
OUTW3
=
128
,
OUTH3
=
64
,
OUTC3
=
4
)
(
(
/*
/*
inputsize[0][0] = HEIGHT;
inputsize[0][0] = HEIGHT;
...
...
examples/hdl4secnn/googlenet/CMakeLists.txt
浏览文件 @
00023f01
...
@@ -180,5 +180,5 @@ add_executable(googlenet
...
@@ -180,5 +180,5 @@ add_executable(googlenet
)
)
include_directories
(
"../cnn/include"
)
include_directories
(
"../cnn/include"
)
target_link_libraries
(
googlenet cnn
m
)
target_link_libraries
(
googlenet cnn
)
examples/hdl4secnn/modeldump/modeldump.cpp
浏览文件 @
00023f01
...
@@ -1418,7 +1418,7 @@ static void dumpLayer(int index, FILE * pFile, const caffe::LayerParameter *pLay
...
@@ -1418,7 +1418,7 @@ static void dumpLayer(int index, FILE * pFile, const caffe::LayerParameter *pLay
if
(
d
<
bmin
)
bmin
=
d
;
if
(
d
<
bmin
)
bmin
=
d
;
}
}
}
else
{
}
else
{
bmax
=
bmin
=
blob
->
double_data
(
0
);
bmax
=
bmin
=
(
float
)
blob
->
double_data
(
0
);
for
(
j
=
0
;
j
<
blob
->
double_data_size
();
j
++
)
{
for
(
j
=
0
;
j
<
blob
->
double_data_size
();
j
++
)
{
float
d
=
(
float
)
blob
->
double_data
(
j
);
float
d
=
(
float
)
blob
->
double_data
(
j
);
if
(
d
>
bmax
)
bmax
=
d
;
if
(
d
>
bmax
)
bmax
=
d
;
...
@@ -1564,7 +1564,7 @@ static void dumpLayer(int index, FILE * pFile, const caffe::LayerParameter *pLay
...
@@ -1564,7 +1564,7 @@ static void dumpLayer(int index, FILE * pFile, const caffe::LayerParameter *pLay
fprintf
(
pFile
,
"
\t\t
.h = PARAM_0_H,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.h = PARAM_0_H,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.w = PARAM_0_W,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.w = PARAM_0_W,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.c = PARAM_0_C,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.c = PARAM_0_C,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.scale = PARAM_0_S,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.scale =
(float)
PARAM_0_S,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.dtype = CNN_DataType_INT16,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.dtype = CNN_DataType_INT16,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.data = (unsigned char *)param_0
\n\t
} ,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.data = (unsigned char *)param_0
\n\t
} ,
\n
"
);
fprintf
(
pFile
,
"
\t
.bias = {
\n
"
);
fprintf
(
pFile
,
"
\t
.bias = {
\n
"
);
...
@@ -1572,7 +1572,7 @@ static void dumpLayer(int index, FILE * pFile, const caffe::LayerParameter *pLay
...
@@ -1572,7 +1572,7 @@ static void dumpLayer(int index, FILE * pFile, const caffe::LayerParameter *pLay
fprintf
(
pFile
,
"
\t\t
.h = PARAM_1_H,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.h = PARAM_1_H,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.w = PARAM_1_W,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.w = PARAM_1_W,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.c = PARAM_1_C,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.c = PARAM_1_C,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.scale = PARAM_1_S,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.scale =
(float)
PARAM_1_S,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.dtype = CNN_DataType_INT16,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.dtype = CNN_DataType_INT16,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.data = (unsigned char *)param_1
\n\t
} ,
\n
"
);
fprintf
(
pFile
,
"
\t\t
.data = (unsigned char *)param_1
\n\t
} ,
\n
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录