Skip to content

Commit

Permalink
sw: Fix warnings in compilation (#135)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Böck <[email protected]>
  • Loading branch information
colluca and zero9178 authored May 14, 2024
1 parent d7828ed commit cd53d8b
Show file tree
Hide file tree
Showing 63 changed files with 64 additions and 2,723 deletions.
50 changes: 0 additions & 50 deletions Bender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,6 @@ dependencies:
cluster_icache: { git: https://github.com/pulp-platform/cluster_icache.git, version: 0.1.0 }
idma: { git: https://github.com/pulp-platform/iDMA, version: 0.6.0 }

vendor_package:
- name: musl
target_dir: sw/math
upstream: { git: https://github.com/kraj/musl.git, rev: 7a43f6fea9081bdd53d8a11cef9e9fab0348c53d } # v1.2.4
patch_dir: sw/deps/patches/musl
include_from_upstream:
- "COPYRIGHT"
- "Makefile"
- ".gitignore"
- "README"
- "src/math/ceil.c"
- "src/math/ceilf.c"
- "src/math/ceill.c"
- "src/math/expm1.c"
- "src/math/expf.c"
- "src/math/exp2f_data.c"
- "src/math/exp2f_data.h"
- "src/math/log2.c"
- "src/math/log2_data.c"
- "src/math/log2_data.h"
- "src/math/log2f.c"
- "src/math/log2f_data.c"
- "src/math/log2f_data.h"
- "src/math/__math_divzero.c"
- "src/math/__math_invalid.c"
- "src/math/__math_invalidf.c"
- "src/math/__math_invalidl.c"
- "src/math/__math_oflow.c"
- "src/math/__math_oflowf.c"
- "src/math/__math_uflow.c"
- "src/math/__math_uflowf.c"
- "src/math/__math_xflow.c"
- "src/math/__math_xflowf.c"
- "src/math/sqrt.c"
- "src/math/sqrtf.c"
- "src/math/sqrt_data.c"
- "src/math/sqrt_data.h"
- "src/math/tanh.c"
- "src/internal/libm.h"
- "src/include/features.h"
- "include/endian.h"
- "include/math.h"
- "include/features.h"
- "include/float.h"
- "include/alltypes.h.in"
- "arch/riscv64/bits/alltypes.h.in"
- "arch/riscv64/bits/float.h"
- "tools/mkalltypes.sed"
- "arch/generic/fp_arch.h"

export_include_dirs:
- hw/reqrsp_interface/include
- hw/mem_interface/include
Expand Down
4 changes: 2 additions & 2 deletions sw/apps/atax/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def emit_header(self, **kwargs):
header = [super().emit_header()]

M, N = kwargs['M'], kwargs['N']
A = np.random.random_integers(-200, 100, size=(M, N))/100
x = np.random.random_integers(-200, 100, size=(N, 1))/100
A = np.random.randint(-200, 100, size=(M, N))/100
x = np.random.randint(-200, 100, size=(N, 1))/100
y = self.golden_model(A, x)

assert (M % 8) == 0, "M must be an integer multiple of the number of cores"
Expand Down
2 changes: 1 addition & 1 deletion sw/apps/correlation/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def emit_header(self, **kwargs):
header = [super().emit_header()]

M, N = kwargs['M'], kwargs['N']
data = np.random.random_integers(-200, 100, size=(N, M))/100
data = np.random.randint(-200, 100, size=(N, M))/100
corr = self.golden_model(data)

data = data.flatten()
Expand Down
2 changes: 1 addition & 1 deletion sw/apps/covariance/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def emit_header(self, **kwargs):
header = [super().emit_header()]

M, N = kwargs['M'], kwargs['N']
data = np.random.random_integers(-200, 100, size=(N, M))
data = np.random.randint(-200, 100, size=(N, M))
cov = self.golden_model(data)

assert (M % 8) == 0, "M must be an integer multiple of the number of cores"
Expand Down
5 changes: 4 additions & 1 deletion sw/dnn/batchnorm/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ def emit_header(**kwargs):
ofmap = ofmap.permute(0, 2, 3, 1)

n, ih, iw, ci = ifmap.shape
ifmap = data_utils.flatten(ifmap)
ofmap = data_utils.flatten(ofmap)

ifmap_uid = 'ifmap'
ofmap_uid = 'ofmap'
beta_uid = 'beta'
gamma_uid = 'gamma'
# Underscore is used to disambiguate between this and the gamma function from "math.h"
gamma_uid = 'gamma_'

layer_cfg = {
'CI': ci,
Expand Down
21 changes: 13 additions & 8 deletions sw/dnn/conv2d/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,24 @@ def emit_header(**kwargs):

conv2d_output = golden_model(inputs, filters[0],
padding=filter['padding'], stride=filter['stride'])
output_dim = conv2d_output.shape

# compute checksum row-wise
conv2d_checksum = np.sum(conv2d_output.numpy(), axis=1)

ctype = data_utils.ctype_from_precision_t(prec)

inputs = data_utils.flatten(inputs.numpy())
filters = data_utils.flatten(filters[0].numpy())
conv2d_output = data_utils.flatten(conv2d_output.numpy())

layer_cfg = {
'CO': out_channels,
'CI': in_channels,
'IH': input_dim['height'],
'IW': input_dim['width'],
'OH': conv2d_output.shape[1],
'OW': conv2d_output.shape[2],
'OH': output_dim[1],
'OW': output_dim[2],
'FH': filter['height'],
'FW': filter['width'],
'ifmap': 'conv2d_ifmap_dram',
Expand All @@ -71,18 +76,18 @@ def emit_header(**kwargs):

data_str = [emit_license()]
data_str += [format_array_declaration(ctype, 'conv2d_ifmap_dram',
inputs.numpy().shape, BURST_ALIGNMENT)]
inputs.shape, BURST_ALIGNMENT)]
data_str += [format_array_declaration(ctype, 'conv2d_weights_dram',
filters[0].numpy().shape, BURST_ALIGNMENT)]
filters.shape, BURST_ALIGNMENT)]
data_str += [format_array_declaration(ctype, 'conv2d_ofmap_dram',
conv2d_output.numpy().shape, BURST_ALIGNMENT)]
conv2d_output.shape, BURST_ALIGNMENT)]
data_str += [format_struct_definition('conv_layer', 'layer', layer_cfg)]
data_str += [format_array_definition(ctype, 'conv2d_ifmap_dram',
inputs.numpy(), BURST_ALIGNMENT)]
inputs, BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'conv2d_weights_dram',
filters[0].numpy(), BURST_ALIGNMENT)]
filters, BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'conv2d_ofmap_dram',
conv2d_output.numpy(), BURST_ALIGNMENT)]
conv2d_output, BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'conv2d_checksum',
conv2d_checksum, BURST_ALIGNMENT)]

Expand Down
12 changes: 8 additions & 4 deletions sw/dnn/conv2d/src/conv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ void bn_relu(const float *pBuffer, const uint16_t dim_x, const uint16_t dim_y,
ssr_i[0], ssr_i[1], ssr_i[2], ssr_i[3]);
snrt_ssr_repeat(SNRT_SSR_DM1, 1); // Disable repeat from conv2d

snrt_ssr_read(SNRT_SSR_DM0, SNRT_SSR_4D, &pBuffer[compute_id * 2]);
snrt_ssr_write(SNRT_SSR_DM1, SNRT_SSR_4D, &pBuffer[compute_id * 2]);
snrt_ssr_read(SNRT_SSR_DM0, SNRT_SSR_4D,
(volatile void *)&pBuffer[compute_id * 2]);
snrt_ssr_write(SNRT_SSR_DM1, SNRT_SSR_4D,
(volatile void *)&pBuffer[compute_id * 2]);

// Regular path with max unrolling is only done if dim_y
// is at least n_unroll
Expand Down Expand Up @@ -413,9 +415,11 @@ void bn_relu(const float *pBuffer, const uint16_t dim_x, const uint16_t dim_y,
uint32_t h_cleanup_index = dim_y - cleanup_unroll;

snrt_ssr_read(SNRT_SSR_DM0, SNRT_SSR_4D,
&pBuffer[h_cleanup_index * h_stride + compute_id * 2]);
(volatile void *)&pBuffer[h_cleanup_index * h_stride +
compute_id * 2]);
snrt_ssr_write(SNRT_SSR_DM1, SNRT_SSR_4D,
&pBuffer[h_cleanup_index * h_stride + compute_id * 2]);
(volatile void *)&pBuffer[h_cleanup_index * h_stride +
compute_id * 2]);

for (uint32_t co = compute_id; co < ch / 2; co += compute_num) {
volatile register v2s current_lambda = ((v2s *)lambda)[co];
Expand Down
16 changes: 10 additions & 6 deletions sw/dnn/fusedconv/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,32 +176,36 @@ def emit_header(**kwargs):
'dtype': prec
}

ifmap_padded = data_utils.flatten(ifmap_padded.numpy())
kernel = data_utils.flatten(kernel.numpy())
ofmap_before = data_utils.flatten(ofmap_before.numpy())

data_str = [emit_license()]
data_str += [format_array_declaration(ctype, 'fusedconv_pInBuffer_dram',
ifmap_padded.numpy().shape, BURST_ALIGNMENT)]
ifmap_padded.shape, BURST_ALIGNMENT)]
data_str += [format_array_declaration(ctype, 'fusedconv_pWeight_dram',
kernel.numpy().shape, BURST_ALIGNMENT)]
kernel.shape, BURST_ALIGNMENT)]
data_str += [format_array_declaration(ctype, 'fusedconv_lambda_dram',
bn_l.numpy().shape, BURST_ALIGNMENT)]
data_str += [format_array_declaration(ctype, 'fusedconv_kappa_dram',
bn_k.numpy().shape, BURST_ALIGNMENT)]
data_str += [format_array_declaration(ctype, 'fusedconv_pOutBuffer_dram',
ofmap_before.numpy().shape, BURST_ALIGNMENT)]
ofmap_before.shape, BURST_ALIGNMENT)]
data_str += [format_array_declaration(ctype, 'fusedconv_pCheckOutBuffer_dram',
ofmap.numpy().shape, BURST_ALIGNMENT)]
data_str += [format_struct_definition('kernel_fp32', 'layer', layer_cfg)]
data_str += [format_scalar_definition('uint32_t', 'dw', kwargs['depthwise'])]
data_str += [format_scalar_definition('uint32_t', 'chw_layer', kwargs['chw_layer'])]
data_str += [format_array_definition(ctype, 'fusedconv_pInBuffer_dram',
ifmap_padded.numpy(), BURST_ALIGNMENT)]
ifmap_padded, BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'fusedconv_pWeight_dram',
kernel.numpy(), BURST_ALIGNMENT)]
kernel, BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'fusedconv_lambda_dram',
bn_l.numpy(), BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'fusedconv_kappa_dram',
bn_k.numpy(), BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'fusedconv_pOutBuffer_dram',
ofmap_before.numpy(), BURST_ALIGNMENT)]
ofmap_before, BURST_ALIGNMENT)]
data_str += [format_array_definition(ctype, 'fusedconv_pCheckOutBuffer_dram',
ofmap.numpy(), BURST_ALIGNMENT)]

Expand Down
8 changes: 8 additions & 0 deletions sw/dnn/layernorm/src/layernorm.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ static inline void layernorm_layer(layernorm_layer_t l) {
l.batch_size, tile_seq_len,
l.embeddings, l.eps);
break;
default:
break;
}
break;
case FP16:
Expand All @@ -122,6 +124,8 @@ static inline void layernorm_layer(layernorm_layer_t l) {
l.batch_size, tile_seq_len,
l.embeddings, l.eps);
break;
default:
break;
}
break;
case FP8:
Expand All @@ -131,8 +135,12 @@ static inline void layernorm_layer(layernorm_layer_t l) {
l.batch_size, tile_seq_len,
l.embeddings, l.eps);
break;
default:
break;
}
break;
default:
break;
}

if (snrt_is_compute_core()) snrt_mcycle();
Expand Down
3 changes: 3 additions & 0 deletions sw/dnn/maxpool/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def emit_header(**kwargs):
n, ih, iw, ci = ifmap.shape
_, oh, ow, co = ofmap.shape

ifmap = data_utils.flatten(ifmap)
ofmap = data_utils.flatten(ofmap)

ifmap_uid = 'ifmap'
ofmap_uid = 'ofmap'

Expand Down
3 changes: 3 additions & 0 deletions sw/dnn/softmax/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def emit_header(**kwargs):
ofmap = golden_model(ifmap, reduce_dim)
ofmap = ofmap.detach().numpy()

ifmap = data_utils.flatten(ifmap)
ofmap = data_utils.flatten(ofmap)

ctype = data_utils.ctype_from_precision_t(prec)

ifmap_uid = 'ifmap'
Expand Down
1 change: 0 additions & 1 deletion sw/dnn/src/dnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef union {
} v8s;

#define M_PI 3.14159265358979323846
#define INFINITY 0x7f800000

/**
* @struct network_t_
Expand Down
1 change: 0 additions & 1 deletion sw/math/.gitignore

This file was deleted.

Loading

0 comments on commit cd53d8b

Please sign in to comment.