1 / 32

Caracterização de uma Biblioteca de Software para Sistemas Embarcados

Caracterização de uma Biblioteca de Software para Sistemas Embarcados. Júlio Carlos Balzano de Mattos julius@inf.ufrgs.br. Disciplina de Sistemas Embarcados Profs. Flavio Wagner e Luigi Carro. Programa de Pós-Graduação em Computação Instituto de Informática

Télécharger la présentation

Caracterização de uma Biblioteca de Software para Sistemas Embarcados

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Caracterização de uma Biblioteca de Software para Sistemas Embarcados Júlio Carlos Balzano de Mattos julius@inf.ufrgs.br Disciplina de Sistemas Embarcados Profs. Flavio Wagner e Luigi Carro Programa de Pós-Graduação em Computação Instituto de Informática Universidade Federal do Rio Grande do Sul Porto Alegre - RS - Brasil

  2. Introdução • Objetivos • Pesquisar formas de desenvolvimento de software embarcado que permitam ao projetista, em alto nível, associar no momento do desenvolvimento do software compromissos como área de memória, desempenho, potência, etc. • Como • Através da caracterização de uma biblioteca de software • Biblioteca de SW • Composta de um conjunto de algoritmos (utilizados em diferentes domínios de aplicação) determinar mais de uma forma de solução para o mesmo problema • Itens avaliados: tamanho de memória (programa e dados), desempenho e potência

  3. Introdução • Algoritmos selecionados • Cálculo do Seno • Algoritmos de Ordenação • Busca em Tabela • Raiz Quadrada • Ferramentas utilizadas • Sashimi • Simulador FemtoJava (CAD – Caco Aided Design)

  4. Cálculo do Seno • Estratégias • Busca em Tabela • Algortimo CORDIC • Por Tabela • Os valores do Senos são calculados previamente e armazenados em uma tabela • static int[] tabelaSenos = • { 0, /* sin 0 */ • ... • 23170, /* sin 45 = 0,7071 */ • ... • 32768 /* sin 90 = 1 */ • }; /* tabela dos senos */

  5. Cálculo do Seno • Por Tabela • Para determinar o seno de um ângulo deve apenas realizar uma busca na tabela • public static int senoTab(int grau) { • seno = tabelaSenos[grau]; • return seno; • }

  6. Cálculo do Seno • Por CORDIC • Algoritmo CORDIC (Coordinate Rotation Digital Computer) • Algoritmo iterativo simples para calcular funções trigonométricas • public static void algoritmoCordic(int grau) { • ... • while (count < 12) { • if (v >= 0) { • x = x - y0; • y = y + x0; • v = v - atansTable[indiceAtans]; indiceAtans++; • } else { • x = x + y0; • y = y - x0; • v = v + atansTable[indiceAtans]; indiceAtans++; • } • count++; • x0 = x; • x0 = x0 >> count; • y0 = y; • y0 = y0 >> count; • } • ... • }

  7. Cálculo do Seno • Resultados App Prg Mem (bytes) Data Mem (Bytes)  Instr Perfor. (Cycles) Power (CGs) Seno Cordic 206 184 28 2446 5.835.362 Seno Tab (1) 88 220 8 136 322.455 Seno Tab (0,5) 89 400 8 136 322.455 Seno Tab (0,1) 89 1840 8 136 322.455 App Power ROM Power RAM Power CPU Power TOTAL Seno Cordic 178.480 121.440 5.535.442 5.835.362 Seno Tab 8.970 9.200 304.285 322.455

  8. Cálculo do Seno • Conclusões • Cálculo por Tabela é excelente para pequenas resoluções (desempenho, potência e área de memória) • Problema: com a necessidade de aumento da resolução ocorre o aumento da tabela (maior necessidade de memória) • Cálculo pelo CORDIC: possui desempenho bem pior que o cálculo por tabela, porém com o aumento da resolução os parâmetros (desempenho, potência e área de memória) não se alteram • Bons para exploração do espaço de projeto

  9. Pesquisa em Tabela • Estratégias • Pesquisa seqüencial em tabela não ordenada • Método simples e intuitivo • Pesquisa seqüencial em tabela ordenada • Método simples e intuitivo • Pesquisa Binária • Método aplica a tabelas ordenadas que consiste na comparação do argumento de pesquisa com a chave de entrada localizada no endereço médio da tabela • Hashing • Método de cálculo de endereço

  10. Pesquisa em Tabela • Pesquisa Seqüencial em tabela não ordenada • Realiza uma busca “burra”, porém o processo de inserção é facilitado • Busca é realizada através de um laço (for): • public static int busca(int arg) { • int i, n, e; • n = tamTAB; • e = 0; • for (i=0; i<=n-1; i++) { • if (tabela[i] == arg) { • e = i; • } • } • return e; • }

  11. Pesquisa em Tabela • Pesquisa Seqüencial em tabela não ordenada • Para um novo elemento deve-se inclui-lo no final da tabela • public static int insere(int arg) { • int dev; • if (ultimoElemento < tamTAB) { • // insere • tabela[ultimoElemento] = arg; • ultimoElemento++; • dev = 0; • } • else { • // tabela cheia • dev = 1; • } • return dev; • }

  12. Pesquisa em Tabela • Pesquisa Seqüencial em tabela ordenada • Busca é realizada através de um laço (while): • public static int busca(int arg) { • int i, n, e; • n = tamTAB-1; • e = 0; • i = 0; • while ((tabela[i] < arg) && (i < n)) { • i++; • } • if (tabela[i] == arg) { • e = i; • } • return e; • }

  13. Pesquisa em Tabela • Pesquisa Seqüencial em tabela ordenada • Um novo elemento deve ser inserido na posição correta da tabela • public static int insere(int arg) { • int dev, n, i, temp, temp2; • n = tamTAB-1; • i = 0; • if (ultimoElemento < tamTAB) { • while ((tabela[i] < arg) && (i < n)) { • i++; • } • temp2 = arg; • while (i < n) { • temp = tabela[i]; • tabela[i] = temp2; • temp2 = temp; • i++; • } • tabela[i] = temp2; • ultimoElemento++; • } • ...

  14. Pesquisa em Tabela • Pesquisa Binária • Busca é relativamente simples e rápida • public static int busca(int arg) { • int i, n, e, inf, sup, med; • ... • while ((inf <= sup) && (e==0)) • { • med = (inf + sup) >> 1; // (inf + sup) DIV 2 • if (arg == tabela[med]) { • e = med; • } else { • if (arg > tabela[med]) { • inf = med + 1; • } • else { • sup = med - 1; • } • } • } • return e; • }

  15. Pesquisa em Tabela • Pesquisa Binária • A inserção é mais lenta pois deve-se inserir o elemento na posição correta e depois reordenar os demais elementos • public static int insere(int arg) { • int i, n, e, inf, sup, med; • ... • if (ultimoElemento < tamTAB) { • while ((inf <= sup) && (e==0)) { • med = (inf + sup) >> 1; // (inf + sup) DIV 2 • if (arg > tabela[med]) { • inf = med + 1; • } • else { • sup = med - 1; • } • } • ... • while (i < tamTAB-1) { • temp = tabela[i]; • tabela[i] = temp2; • temp2 = temp; • i++; • } • ...

  16. Pesquisa em Tabela • Hashing • Função de cálculo de endereço (simples): • f(C)=(C mod N)+1, onde C é a chavee N é o número de entradas da tabela • Problema: Colisões • Sem o tratamento de colisões o método é excelente ! • Tratamento de Colisões: uso de endereçamento aberto com busca linear

  17. Pesquisa em Tabela • Hashing • Busca com tratamento de colisões: maior complexidade no código e aumento na memória de dados (tabelas auxiliares: ocupado e usado) • public static int busca(int arg) { • ... • do { • if (tabUsado[endl] == 1) { • if ((tabOcupado[endl] == 1) && (tabela[endl] == arg)) { • e = endl; • } else { • if (endl == n) { • endl = 1; • } else { • endl++; • } • } • ...

  18. Pesquisa em Tabela • Hashing • Inserção com tratamento de colisões: também maior complexidade no código e maior memória de dados • public static int insere(int arg) { • ... • do { • if (tabUsado[endl] == 1) { • if (tabOcupado[endl] == 1) { • if (tabela[endl] == arg) { • e = endl; • } else { • endl++; • } • } else { • if (marca == 0) { • marca = endl; • endl++; • } • ...

  19. Pesquisa em Tabela • Resultados (32 entradas) • OBS: Valores médios de desempenho, área e potência. App Seq. 1 Seq. 2 Binary Hashing Prg. Mem. (bytes) 140 201 302 278 Instructions 24 26 28 29 Data Mem. (bytes) Search 171 168 114 248 Insert 108 240 184 254 Perfom. (cycles) Search 1.121 1.128 602 437 Insert 200 2.629 2.430 487 Power (CGs) Search 2.685.063 2.702.674 1.100.436 1.044.637 Insert 470.692 6.249.144 5.744.422 1.161.693

  20. Pesquisa em Tabela • Resultados para Hashing (32 entradas) trabalhando com Strings • Utilizando o código ASCII com compressão de chave alfanumérica agrupando de 2 em 2 bytes • Ex: BRASIL • BR 0100001001010010 • AS 0100000101010011 XOR • IL 0100100101001100 • 0100001001010010 = 1697810 • f(C)=(C mod N)+1 = (16978 mod 32)+1 = 14

  21. Pesquisa em Tabela • Resultados para Hashing (32 entradas) trabalhando com Strings App Hashing Hashing c/ String Prg. Mem. (bytes) 278 371 Instructions 29 37 Data Mem. (bytes) Search 248 272 Insert 254 272 Perfom. (cycles) Search 437 607 Insert 487 657 Power (CGs) Search 1.044.637 1.451.017 Insert 1.161.693 1.570.541

  22. Pesquisa em Tabela • Resultados (128 entradas) • OBS: Valores médios de desempenho, área e potência. App Seq. 1 Seq. 2 Binary Hashing Prg. Mem. (bytes) 140 201 302 278 Instructions 24 26 28 29 Data Mem. (bytes) Search 555 552 306 855 Insert 300 816 548 862 Perfom. (cycles) Search 3.905 3.912 770 437 Insert 200 9.937 7.657 487 Power (CGs) Search 9.397.287 9.720.722 1.882.485 992.903 Insert 470.692 23.716.169 18.151.875 1.162.748

  23. Algoritmos de Ordenação • Estratégias • Bubble Sort • Insert Sort • Select Sort • Quick Sort • Resultados Esperados • Associados com a complexidade de cada algoritmo

  24. Algoritmos de Ordenação • Bubble Sort • public static int[] sort(int[] estrut, int maxnos) { • int i,j; • int temp; • for (i=0; i<maxnos-1; i++) { • for (j=maxnos-1; j>i; j--) { • if (estrut[j]<estrut[j-1]) { • temp=estrut[j]; • estrut[j]=estrut[j-1]; • estrut[j-1]=temp; • } • } • } • return estrut; • }

  25. Algoritmos de Ordenação • Insert Sort • public static int[] sort(int[] estrut, int maxnos) { • int i,j; • int temp; • for (i=1; i<maxnos;i++) { • j=i; • while (estrut[j]<estrut[j-1] && j!=1) { • temp=estrut[j]; • estrut[j]=estrut[j-1]; • estrut[j-1]=temp; • j--; • } • } • return estrut; • }

  26. Algoritmos de Ordenação • Select Sort • public static int[] sort(int[] estrut, int maxnos) { • int i,j; • int temp, menor; • for (i=1;i<maxnos;i++) { • menor=i-1; • j=i; • while (j<maxnos) { • if (estrut[menor]>estrut[j]) { • menor=j; • } • j++; • } • temp=estrut[i-1]; • estrut[i-1]=estrut[menor]; • estrut[menor]=temp; • } • return estrut; • }

  27. Algoritmos de Ordenação • Quick Sort • public static int[] sort(int l, int r) { • ... • i = l; • j = r; • temp = (l+r) >> 1; // (l+r) DIV 2 • x = estrut[temp]; • do { • while (estrut[i] < x) { i++; } • while (x < estrut[j]) { j--;} • if (i <= j) { • y = estrut[i]; • estrut[i] = estrut[j]; • estrut[j] = y; • i++; • j--; • } • } while (i <= j); • if (l < j) { sort(l, j); } • if (i < r) { sort(i, r); } • return estrut; • }

  28. Algoritmos de Ordenação • Resultados (10 elementos) App Prg Mem (bytes) Data Mem (Bytes)  Instr Perfor. (Cycles) Power (CGs) Sort Bubble 132 278 20 6774 16.348.510 Sort Insert 129 98 20 4093 9.754.005 Sort Select 138 98 22 5335 12.929.068 Sort Quick 173 140 23 3940 9.485.919

  29. Algoritmos de Ordenação • Resultados (100 elementos) App Prg Mem (bytes) Data Mem (Bytes)  Instr Perfor. (Cycles) Power (CGs) Sort Bubble 132 20.434 20 892.347 2.096.575.205 Sort Insert 129 638 20 856.188 2.044.626.628 Sort Select 138 638 22 408.675 996.468.801 Sort Quick 173 336 23 72.186 173.527.751

  30. Raiz Quadrada • Utiliza dois Métodos propostos por Ramamoorthy • Dois métodos muito similares • O desempenho está relacionado a rapidez da convergência das funções • Resultados: App Prg Mem (bytes) Data Mem (Bytes)  Instr Perfor. (Cycles) Power (CGs) Square 1 100 82 22 5335 7.001.414 Square 2 121 82 24 5335 7.001.414

  31. Conclusões • Cálculo do Seno • Permite uma boa exploração do espaço de projeto • Pesquisa em Tabela • O melhor algoritmos dependerá muito da aplicação, mas também pode-se explorar o espaço de projeto • Algoritmos de Ordenação • Não permitem explorar o espaço de projeto (contra-exemplo) • Raiz Quadrada • Dados muitos incipientes

  32. Trabalhos Futuros • Expandir a biblioteca com outros algoritmos • Algoritmos aritméticos • Algortimos maiores (DCT, etc...) • Avaliar o impacto dos algoritmos em problemas maiores • Algortimos de Huffman • MP3 Player • etc ...

More Related