-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
245 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <string.h> | ||
|
||
#include "cc_basic.h" | ||
#include "cc_actfn.h" | ||
|
||
/* #include "global_fn_cfg.h" */ | ||
extern void (*_activation_relu) | ||
(void *inp, cc_int32 elems, cc_dtype dt); | ||
extern void (*_activation_relu6) | ||
(void *inp, cc_int32 elems, cc_dtype dt); | ||
extern void (*_activation_softmax) | ||
(void *inp, cc_int32 elems, cc_dtype dt); | ||
|
||
cc_tensor_t *cc_relu(cc_tensor_t *tensor, const char *name) | ||
{ | ||
cc_tensor_t *relu; | ||
if (!name || !strcmp(name, tensor->name)) | ||
relu = tensor; | ||
else | ||
relu = cc_copy_tensor(tensor, name); | ||
_activation_relu(relu->data, | ||
cc_tensor_elements(relu), *relu->dtype); | ||
return relu; | ||
} | ||
|
||
cc_tensor_t *cc_relu6(cc_tensor_t *tensor, const char *name) | ||
{ | ||
cc_tensor_t *relu; | ||
if (!name || !strcmp(name, tensor->name)) | ||
relu = tensor; | ||
else | ||
relu = cc_copy_tensor(tensor, name); | ||
_activation_relu6(relu->data, | ||
cc_tensor_elements(relu), *relu->dtype); | ||
return relu; | ||
} | ||
|
||
cc_tensor_t *cc_softmax(cc_tensor_t *tensor, const char *name) | ||
{ | ||
cc_tensor_t *softmax; | ||
if (!name || !strcmp(name, tensor->name)) | ||
softmax = tensor; | ||
else | ||
softmax = cc_copy_tensor(tensor, name); | ||
_activation_softmax(softmax->data, | ||
cc_tensor_elements(softmax), *softmax->dtype); | ||
return softmax; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef _CC_ACTFN_H_ | ||
#define _CC_ACTFN_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "cc_tensor.h" | ||
|
||
cc_tensor_t *cc_relu (cc_tensor_t *tensor, const char *name); | ||
cc_tensor_t *cc_relu6(cc_tensor_t *tensor, const char *name); | ||
|
||
cc_tensor_t *cc_softmax(cc_tensor_t *tensor, const char *name); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _CC_ACTFN_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <string.h> | ||
|
||
#include "cc_assert.h" | ||
#include "cc_basic.h" | ||
#include "cc_fmap2d.h" | ||
#include "cc_normfn.h" | ||
|
||
/* #include "global_fn_cfg.h" */ | ||
extern void (*_batch_norm)( | ||
void *inp, cc_int32 len, void *bnpara, cc_dtype dt); | ||
|
||
cc_tensor_t *cc_batch_norm2d(cc_tensor_t *inp, | ||
cc_tensor_t *para, const char *name) | ||
{ | ||
cc_tensor_t *oup; | ||
cc_int32 i, dt_size, ch_size, ch_mem_size; | ||
#ifdef ENABLE_CC_ASSERT | ||
cc_assert_zero(cc_tensor_dimension(inp) - CC_CNN2D_DIM); | ||
cc_assert_zero(*inp->dtype - *para->dtype); | ||
#endif | ||
if (!name || !strcmp(name, inp->name)) | ||
oup = inp; | ||
else | ||
oup = cc_copy_tensor(inp, name); | ||
dt_size = cc_dtype_size(*inp->dtype); | ||
ch_size = inp->shape[CC_CNN2D_SHAPE_H] * | ||
inp->shape[CC_CNN2D_SHAPE_W]; | ||
ch_mem_size = ch_size * dt_size; | ||
for (i = 0; i < inp->shape[CC_CNN2D_SHAPE_C]; ++i) { | ||
_batch_norm(inp->data + ch_mem_size * i, | ||
ch_size, para->data + CC_BN_PARAMETERS * | ||
dt_size * i, *para->dtype); | ||
} | ||
return oup; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef _CC_NORMFN_H_ | ||
#define _CC_NORMFN_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "cc_tensor.h" | ||
|
||
/* | ||
* Batch Normalization parameters offset | ||
* bnpara: | ||
* GAMMA | BETA | MEAN | VAR | EPSILON | ||
* cc_int32 shape[] = {ch, CC_BN_PARAMETERS, 1, 0} | ||
* \ \___ number of parameters(5) | ||
* \___________ number of channels | ||
* cc_tensor_t *bnpara = cc_create_tensor(shape, dt, "name"); | ||
*/ | ||
#ifndef CC_BN_OFFSET_CFG | ||
#define CC_BN_OFFSET_CFG | ||
enum cc_batch_norm_paraoff { | ||
CC_BN_OFFSET_GAMMA, | ||
CC_BN_OFFSET_BETA, | ||
CC_BN_OFFSET_MEAN, | ||
CC_BN_OFFSET_VAR, | ||
CC_BN_OFFSET_EPSILON, | ||
CC_BN_PARAMETERS | ||
}; | ||
#endif | ||
|
||
cc_tensor_t *cc_batch_norm2d(cc_tensor_t *inp, | ||
cc_tensor_t *para, const char *name); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _CC_NORMFN_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters