CMSIS-DSP  
CMSIS DSP Software Library
 
Loading...
Searching...
No Matches
dsppp_example/Dsppp/main.cpp
#include "RTE_Components.h"
#include CMSIS_device_header
#include <cstdio>
#include <cstdlib>
#include "allocators.hpp"
#include <dsppp/matrix.hpp>
#include "init_data.hpp"
using namespace arm_cmsis_dsp;
void test1() {
constexpr int NB = 64;
// By default, the Vector class template uses the macro TMP_ALLOC to select
// the memory allocator. The macro is defined in the cproject file and uses
// the pool_allocator stateless template. It can be changed to the
// stat_allocator to get the sizes that needs to be used for the memory pools.
init_vectors(NB,a.ptr(),b.ptr(),c.ptr());
// Fusion loop : The addition and multiplication are fused into a single
// vectorized loop by the library
Vector<float32_t, NB> d = a + b * c;
std::cout << "Result = " << d;
}
void test2() {
constexpr int NB = 64;
constexpr std::size_t ARENA_SIZE = 1024; // 1MB for the arena
void *arena_ptr = aligned_malloc(
ARENA_SIZE, 64); // Allocate 1MB for the arena with 64-byte alignment
create_arena(arena_ptr, ARENA_SIZE);
// Use the arena allocator.
// WARNING : Temporary allocations still uses the TMP_ALLOC allocator.
// If it is different from the arena_allocator, temporaries will be copied
// (instead of moved) to the vectors using arena_allocator.
// Dyamically sized vectors using the arena allocator
ArenaVector a(NB);
ArenaVector b(NB);
ArenaVector c(NB);
init_vectors(NB,a.ptr(),b.ptr(),c.ptr());
// Fusion loop : The addition and multiplication are fused into a single
// vectorized loop by the library
ArenaVector d = a + b * c;
std::cout << "Result = " << d;
std::size_t offset = get_arena_offset();
std::cout << "Arena offset after computation: " << offset << "\r\n";
reset_arena();
free(arena_ptr);
}
int main() {
setvbuf(stdout, NULL, _IONBF, 0);
printf("CMSIS-DSPP C++ examples\n");
// Stat allocztor can be enabled in the cproject.
// The stat_allocator keeps track of memory usage and can be used to print
// memory allocation statistics. Those statistics can be used to optimize memory
// pool sizes and improve memory usage efficiency.
#if defined(STAT_ALLOCATOR)
reset_current_stats();
#endif
std::cout << "Test 1" << std::endl;
test1();
#if defined(STAT_ALLOCATOR)
print_map("Memory allocation statistics");
check_current_stats();
#endif
std::cout << "Test 2" << std::endl;
test2();
error:
exit(0);
}