Skip to content

Commit

Permalink
clang-format faceid_112
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Carter committed Jan 25, 2024
1 parent ae2bdd1 commit f431de8
Show file tree
Hide file tree
Showing 7 changed files with 16,453 additions and 14,576 deletions.
2,327 changes: 1,156 additions & 1,171 deletions Examples/MAX78000/CNN/faceid_112/cnn.c

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions Examples/MAX78000/CNN/faceid_112/cnn.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/**************************************************************************************************
* Copyright (C) 2019-2021 Maxim Integrated Products, Inc. All Rights Reserved.
*
* Maxim Integrated Products, Inc. Default Copyright Notice:
* https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
**************************************************************************************************/
/******************************************************************************
*
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. All Rights Reserved.
* (now owned by Analog Devices, Inc.),
* Copyright (C) 2023-2024 Analog Devices, Inc. All Rights Reserved. This software
* is proprietary to Analog Devices, Inc. and its licensors.
*
* 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.
*
******************************************************************************/

/*
* This header file was automatically @generated for the faceid_112 network from a template.
Expand Down Expand Up @@ -62,9 +76,10 @@ typedef int16_t q15_t;
#define SYS_COMPLETE LED_Off(0)

/* Run software SoftMax on unloaded data */
void softmax_q17p14_q15(const q31_t * vec_in, const uint16_t dim_vec, q15_t * p_out);
void softmax_q17p14_q15(const q31_t *vec_in, const uint16_t dim_vec, q15_t *p_out);
/* Shift the input, then calculate SoftMax */
void softmax_shift_q17p14_q15(q31_t * vec_in, const uint16_t dim_vec, uint8_t in_shift, q15_t * p_out);
void softmax_shift_q17p14_q15(q31_t *vec_in, const uint16_t dim_vec, uint8_t in_shift,
q15_t *p_out);

/* Stopwatch - holds the runtime when accelerator finishes */
extern volatile uint32_t cnn_time;
Expand Down
161 changes: 74 additions & 87 deletions Examples/MAX78000/CNN/faceid_112/main.c
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
/*******************************************************************************
* Copyright (C) 2019-2023 Maxim Integrated Products, Inc., All rights Reserved.
*
* This software is protected by copyright laws of the United States and
* of foreign countries. This material may also be protected by patent laws
* and technology transfer regulations of the United States and of foreign
* countries. This software is furnished under a license agreement and/or a
* nondisclosure agreement and may only be used or reproduced in accordance
* with the terms of those agreements. Dissemination of this information to
* any party or parties not specified in the license agreement and/or
* nondisclosure agreement is expressly prohibited.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*******************************************************************************/
/******************************************************************************
*
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. All Rights Reserved.
* (now owned by Analog Devices, Inc.),
* Copyright (C) 2023-2024 Analog Devices, Inc. All Rights Reserved. This software
* is proprietary to Analog Devices, Inc. and its licensors.
*
* 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.
*
******************************************************************************/

// faceid_112
// This file was @generated by ai8xize.py --test-dir sdk/Examples/MAX78000/CNN --prefix faceid_112 --checkpoint-file trained/ai85-fakepass-faceid_112-qat-q.pth.tar --config-file networks/ai85-faceid_112.yaml --fifo --device MAX78000 --timer 0 --display-checkpoint --verbose
Expand All @@ -48,94 +35,95 @@ volatile uint32_t cnn_time; // Stopwatch

void fail(void)
{
printf("\n*** FAIL ***\n\n");
while (1);
printf("\n*** FAIL ***\n\n");
while (1)
;
}

// Data input: HWC 3x112x112 (37632 bytes total / 12544 bytes per channel):
static const uint32_t input_0[] = SAMPLE_INPUT_0;
void load_input(void)
{
// This function loads the sample data input -- replace with actual data
// This function loads the sample data input -- replace with actual data

int i;
const uint32_t *in0 = input_0;
int i;
const uint32_t *in0 = input_0;

for (i = 0; i < 12544; i++) {
// Remove the following line if there is no risk that the source would overrun the FIFO:
while (((*((volatile uint32_t *) 0x50000004) & 1)) != 0); // Wait for FIFO 0
*((volatile uint32_t *) 0x50000008) = *in0++; // Write FIFO 0
}
for (i = 0; i < 12544; i++) {
// Remove the following line if there is no risk that the source would overrun the FIFO:
while (((*((volatile uint32_t *)0x50000004) & 1)) != 0)
; // Wait for FIFO 0
*((volatile uint32_t *)0x50000008) = *in0++; // Write FIFO 0
}
}

// Expected output of layer 17 for faceid_112 given the sample input (known-answer test)
// Delete this function for production code
static const uint32_t sample_output[] = SAMPLE_OUTPUT;
int check_output(void)
{
int i;
uint32_t mask, len;
volatile uint32_t *addr;
const uint32_t *ptr = sample_output;

while ((addr = (volatile uint32_t *) *ptr++) != 0) {
mask = *ptr++;
len = *ptr++;
for (i = 0; i < len; i++)
if ((*addr++ & mask) != *ptr++) {
printf("Data mismatch (%d/%d) at address 0x%08x: Expected 0x%08x, read 0x%08x.\n",
i + 1, len, addr - 1, *(ptr - 1), *(addr - 1) & mask);
return CNN_FAIL;
}
}

return CNN_OK;
int i;
uint32_t mask, len;
volatile uint32_t *addr;
const uint32_t *ptr = sample_output;

while ((addr = (volatile uint32_t *)*ptr++) != 0) {
mask = *ptr++;
len = *ptr++;
for (i = 0; i < len; i++)
if ((*addr++ & mask) != *ptr++) {
printf("Data mismatch (%d/%d) at address 0x%08x: Expected 0x%08x, read 0x%08x.\n",
i + 1, len, addr - 1, *(ptr - 1), *(addr - 1) & mask);
return CNN_FAIL;
}
}

return CNN_OK;
}

static int32_t ml_data32[(CNN_NUM_OUTPUTS + 3) / 4];

int main(void)
{
MXC_ICC_Enable(MXC_ICC0); // Enable cache
MXC_ICC_Enable(MXC_ICC0); // Enable cache

// Switch to 100 MHz clock
MXC_SYS_Clock_Select(MXC_SYS_CLOCK_IPO);
SystemCoreClockUpdate();
// Switch to 100 MHz clock
MXC_SYS_Clock_Select(MXC_SYS_CLOCK_IPO);
SystemCoreClockUpdate();

printf("Waiting...\n");
printf("Waiting...\n");

// DO NOT DELETE THIS LINE:
MXC_Delay(SEC(2)); // Let debugger interrupt if needed
// DO NOT DELETE THIS LINE:
MXC_Delay(SEC(2)); // Let debugger interrupt if needed

// Enable peripheral, enable CNN interrupt, turn on CNN clock
// CNN clock: APB (50 MHz) div 1
cnn_enable(MXC_S_GCR_PCLKDIV_CNNCLKSEL_PCLK, MXC_S_GCR_PCLKDIV_CNNCLKDIV_DIV1);
// Enable peripheral, enable CNN interrupt, turn on CNN clock
// CNN clock: APB (50 MHz) div 1
cnn_enable(MXC_S_GCR_PCLKDIV_CNNCLKSEL_PCLK, MXC_S_GCR_PCLKDIV_CNNCLKDIV_DIV1);

printf("\n*** CNN Inference Test faceid_112 ***\n");
printf("\n*** CNN Inference Test faceid_112 ***\n");

cnn_init(); // Bring state machine into consistent state
cnn_load_weights(); // Load kernels
cnn_load_bias();
cnn_configure(); // Configure state machine
cnn_start(); // Start CNN processing
load_input(); // Load data input via FIFO
cnn_init(); // Bring state machine into consistent state
cnn_load_weights(); // Load kernels
cnn_load_bias();
cnn_configure(); // Configure state machine
cnn_start(); // Start CNN processing
load_input(); // Load data input via FIFO

while (cnn_time == 0)
MXC_LP_EnterSleepMode(); // Wait for CNN
while (cnn_time == 0) MXC_LP_EnterSleepMode(); // Wait for CNN

if (check_output() != CNN_OK) fail();
cnn_unload((uint32_t *) ml_data32);
if (check_output() != CNN_OK)
fail();
cnn_unload((uint32_t *)ml_data32);

printf("\n*** PASS ***\n\n");
printf("\n*** PASS ***\n\n");

#ifdef CNN_INFERENCE_TIMER
printf("Approximate data loading and inference time: %u us\n\n", cnn_time);
printf("Approximate data loading and inference time: %u us\n\n", cnn_time);
#endif

cnn_disable(); // Shut down CNN clock, disable peripheral
cnn_disable(); // Shut down CNN clock, disable peripheral


return 0;
return 0;
}

/*
Expand Down Expand Up @@ -164,4 +152,3 @@ int main(void)
Weight memory: 365,408 bytes out of 442,368 bytes total (82.6%)
Bias memory: 1,296 bytes out of 2,048 bytes total (63.3%)
*/

Loading

0 comments on commit f431de8

Please sign in to comment.