SlideShare uma empresa Scribd logo
Multiplicação de Matrizes em CUDA Divino César SoaresPontifícia Universidade Católica de Goiás (CMP/PUC-GO)
O Problema ,[object Object]
 Gerar uma matriz resultado C com as mesmas dimensões das matrizes A e B.
 Cada elemento (i, j) da matriz C é o produto (interno) da linha i de A pela coluna j de B.
 Para cada elemento (i, j) de C:for (k=1; k<=LARGURA; k++) 	C[i][j] += (A[i][k] * B[k][j]);
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 1 	k = 1 4 1 2 3
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 1 	k = 2 4 1 2 3
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 1 	k = 3 4 1 2 3
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 1 	k = 4 4 1 2 3
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 2 	k = 1 4 1 2 3
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 2 	k = 2 4 1 2 3
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 2 	k = 3 4 1 2 3
Implementação Sequencial void multiplica(int *A[], int *B[], int *C[]) { for (int i=1; i<=LARGURA; i++) { for (int j=1; j<=LARGURA; j++) { for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } } } 1 2 3 4 ,[object Object],L = 4 	i  = 1 	j  = 2 	k = 4 4 1 2 3
Estrutura da Solução Alocar memória na GPU. Copia dados de entrada. Da CPU para a GPU. Configura execução. Número de threads e blocos. Copia resultados.  cudaMalloc((void **)&A_d, size_A); cudaMalloc((void**)&B_d, size_B); cudaMalloc((void**)&C_d, size_C); cudaMemcpy(A_d, A, size_A, cudaMemcpyHostToDevice); cudaMemcpy(B_d, B, size_B , cudaMemcpyHostToDevice); cudaMemcpy(C_d, C, size_C , cudaMemcpyHostToDevice); dim3 gride(X, Y)dim3 bloco(Z, W, K)meu_kernel<<<gride, bloco>>>(A, B, C); cudaMemcpy(C, C_d, size_C , cudaMemcpyDeviceToHost);
Primeira Abordagem
Kernel 1 dim3 gride(1, 1) dim3 bloco(4, 4, 1) dim3 gride(2, 1) dim3 bloco(4, 4, 1) dim3 gride(1, 1) dim3 bloco(30, 30, 1) Gride Gride Gride << Launcherror >>> Bloco com 600 threads Bloco 0 Bloco 0 Bloco 1
Kernel 1 dim3 gride(1, 1) dim3 bloco(LARGURA, LARGURA, 1) Gride LARGURA LARGURA Bloco 0
Kernel 1 dim3 gride(1, 1) dim3 bloco(LARGURA, LARGURA, 1) Gride __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } LARGURA LARGURA Bloco 0 Kernel 1: Multiplicação na GPU
Kernel 1 1 Instante de tempo t=0 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
Kernel 1 1 Instante de tempo t=1 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
Kernel 1 1 Instante de tempo t=2 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
Kernel 1 1 Instante de tempo t=L 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
Vantagens/Desvantagens ,[object Object],cada elemento de C é calculado em paralelo.  ,[object Object],Restrição do formato das matrizes. Elas devem ser quadradas.  Restrição da quantidade de elementos em cada matriz. Menor que 512.  Usa apenas a memória global da GPU. A memória global apresenta grande latência.  Apenas um bloco de threads, com poucas threads. Tamanho do maior bloco 22 x 22.  Os mesmos dados são buscados várias vezes da memória.  Resultado: Subutilização dos recursos da GPU.
Segunda Abordagem
Kernel 2 dim3 gride(2, 2) dim3 bloco(15, 15, 1) dim3 gride(1, 1) dim3 bloco(30, 30, 1) Gride Gride << Launcherror >>> Bloco com 600 threads Bloco 0, 0 Bloco 0, 1 Bloco 1, 0 Bloco 1, 1
Kernel 2 dim3 gride(2, 2) dim3 bloco(15, 15, 1) Gride Bloco 0, 0 Bloco 0, 1 225 threads por bloco.Total de 900 threads. Bloco 1, 0 Bloco 1, 1
Kernel 2 dim3 gride(2, 2) dim3 bloco(15, 15, 1) Gride __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } Bloco 0, 0 Bloco 0, 1 Kernel 2: Multiplicação na GPU Bloco 1, 0 Bloco 1, 1
Kernel 2 1 2 __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 2: Multiplicação na GPU 4 1 2 3
Kernel 2 1 2 __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 2: Multiplicação na GPU 4 1 2 3
Kernel 2 1 2 __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 2: Multiplicação na GPU 4 1 2 3

Mais conteúdo relacionado

Mais procurados

Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019
Unity Technologies
 
Unity's Evolving Best Practices
Unity's Evolving Best PracticesUnity's Evolving Best Practices
Unity's Evolving Best Practices
Unity Technologies
 
Idea (international data encryption algorithm)
Idea (international data encryption algorithm)Idea (international data encryption algorithm)
Idea (international data encryption algorithm)
Arofiah Hidayati
 
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsHPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
Electronic Arts / DICE
 
Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...
Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...
Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...
Colin Barré-Brisebois
 
Forward+ (EUROGRAPHICS 2012)
Forward+ (EUROGRAPHICS 2012)Forward+ (EUROGRAPHICS 2012)
Forward+ (EUROGRAPHICS 2012)
Takahiro Harada
 
Decima Engine: Visibility in Horizon Zero Dawn
Decima Engine: Visibility in Horizon Zero DawnDecima Engine: Visibility in Horizon Zero Dawn
Decima Engine: Visibility in Horizon Zero Dawn
Guerrilla
 
Pembahasan Soal Perulangan : Pola Bintang
Pembahasan Soal Perulangan : Pola BintangPembahasan Soal Perulangan : Pola Bintang
Pembahasan Soal Perulangan : Pola Bintang
Herbert Abdillah
 
Graphics Gems from CryENGINE 3 (Siggraph 2013)
Graphics Gems from CryENGINE 3 (Siggraph 2013)Graphics Gems from CryENGINE 3 (Siggraph 2013)
Graphics Gems from CryENGINE 3 (Siggraph 2013)
Tiago Sousa
 
Dissecting the Rendering of The Surge
Dissecting the Rendering of The SurgeDissecting the Rendering of The Surge
Dissecting the Rendering of The Surge
Philip Hammer
 
Best Practices for Shader Graph
Best Practices for Shader GraphBest Practices for Shader Graph
Best Practices for Shader Graph
Unity Technologies
 
8 algoritma-branch-and-bound-2
8 algoritma-branch-and-bound-28 algoritma-branch-and-bound-2
8 algoritma-branch-and-bound-2
Octo Manurung
 
Lazy java
Lazy javaLazy java
Lazy java
Mario Fusco
 
ECS (Part 1/3) - Introduction to Data-Oriented Design
ECS (Part 1/3) - Introduction to Data-Oriented DesignECS (Part 1/3) - Introduction to Data-Oriented Design
ECS (Part 1/3) - Introduction to Data-Oriented Design
Phuong Hoang Vu
 
Unity Internals: Memory and Performance
Unity Internals: Memory and PerformanceUnity Internals: Memory and Performance
Unity Internals: Memory and Performance
DevGAMM Conference
 
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
Philip Hammer
 
深入淺出C語言
深入淺出C語言深入淺出C語言
深入淺出C語言
Simen Li
 
좌충우돌 ORM 개발기 | Devon 2012
좌충우돌 ORM 개발기 | Devon 2012좌충우돌 ORM 개발기 | Devon 2012
좌충우돌 ORM 개발기 | Devon 2012Daum DNA
 
GPU - An Introduction
GPU - An IntroductionGPU - An Introduction
GPU - An Introduction
Dhan V Sagar
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
Haresh Jaiswal
 

Mais procurados (20)

Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019
 
Unity's Evolving Best Practices
Unity's Evolving Best PracticesUnity's Evolving Best Practices
Unity's Evolving Best Practices
 
Idea (international data encryption algorithm)
Idea (international data encryption algorithm)Idea (international data encryption algorithm)
Idea (international data encryption algorithm)
 
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsHPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
 
Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...
Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...
Colin Barre-Brisebois - GDC 2011 - Approximating Translucency for a Fast, Che...
 
Forward+ (EUROGRAPHICS 2012)
Forward+ (EUROGRAPHICS 2012)Forward+ (EUROGRAPHICS 2012)
Forward+ (EUROGRAPHICS 2012)
 
Decima Engine: Visibility in Horizon Zero Dawn
Decima Engine: Visibility in Horizon Zero DawnDecima Engine: Visibility in Horizon Zero Dawn
Decima Engine: Visibility in Horizon Zero Dawn
 
Pembahasan Soal Perulangan : Pola Bintang
Pembahasan Soal Perulangan : Pola BintangPembahasan Soal Perulangan : Pola Bintang
Pembahasan Soal Perulangan : Pola Bintang
 
Graphics Gems from CryENGINE 3 (Siggraph 2013)
Graphics Gems from CryENGINE 3 (Siggraph 2013)Graphics Gems from CryENGINE 3 (Siggraph 2013)
Graphics Gems from CryENGINE 3 (Siggraph 2013)
 
Dissecting the Rendering of The Surge
Dissecting the Rendering of The SurgeDissecting the Rendering of The Surge
Dissecting the Rendering of The Surge
 
Best Practices for Shader Graph
Best Practices for Shader GraphBest Practices for Shader Graph
Best Practices for Shader Graph
 
8 algoritma-branch-and-bound-2
8 algoritma-branch-and-bound-28 algoritma-branch-and-bound-2
8 algoritma-branch-and-bound-2
 
Lazy java
Lazy javaLazy java
Lazy java
 
ECS (Part 1/3) - Introduction to Data-Oriented Design
ECS (Part 1/3) - Introduction to Data-Oriented DesignECS (Part 1/3) - Introduction to Data-Oriented Design
ECS (Part 1/3) - Introduction to Data-Oriented Design
 
Unity Internals: Memory and Performance
Unity Internals: Memory and PerformanceUnity Internals: Memory and Performance
Unity Internals: Memory and Performance
 
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
 
深入淺出C語言
深入淺出C語言深入淺出C語言
深入淺出C語言
 
좌충우돌 ORM 개발기 | Devon 2012
좌충우돌 ORM 개발기 | Devon 2012좌충우돌 ORM 개발기 | Devon 2012
좌충우돌 ORM 개발기 | Devon 2012
 
GPU - An Introduction
GPU - An IntroductionGPU - An Introduction
GPU - An Introduction
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 

Destaque

Aula 09 08-2013
Aula 09 08-2013Aula 09 08-2013
Aula 09 08-2013
Ludmylla Lima Figueiredo
 
Multiplicação de matrizes
Multiplicação de matrizesMultiplicação de matrizes
Multiplicação de matrizes
Diego Lusa
 
II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...
II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...
II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...
Eduardo de Lucena Falcão
 
Multiplicação de Matrizes
Multiplicação de MatrizesMultiplicação de Matrizes
Multiplicação de Matrizes
Diego Lusa
 
Multiplicacao de matrizes
Multiplicacao de matrizesMultiplicacao de matrizes
Multiplicacao de matrizes
Glauber Cruz
 
Matriz curric. matematica e.médio 2010
Matriz curric. matematica  e.médio 2010Matriz curric. matematica  e.médio 2010
Matriz curric. matematica e.médio 2010
Creison
 
Plano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio II
Plano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio IIPlano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio II
Plano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio II
Elton Ribeiro da Cruz
 
Planejamento Matrizes e determinantes
Planejamento Matrizes e determinantesPlanejamento Matrizes e determinantes
Planejamento Matrizes e determinantes
MarcieleEuzebio
 

Destaque (8)

Aula 09 08-2013
Aula 09 08-2013Aula 09 08-2013
Aula 09 08-2013
 
Multiplicação de matrizes
Multiplicação de matrizesMultiplicação de matrizes
Multiplicação de matrizes
 
II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...
II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...
II EPI - Estudo e Avaliação do Problema de Otimização da Multiplicação de Cad...
 
Multiplicação de Matrizes
Multiplicação de MatrizesMultiplicação de Matrizes
Multiplicação de Matrizes
 
Multiplicacao de matrizes
Multiplicacao de matrizesMultiplicacao de matrizes
Multiplicacao de matrizes
 
Matriz curric. matematica e.médio 2010
Matriz curric. matematica  e.médio 2010Matriz curric. matematica  e.médio 2010
Matriz curric. matematica e.médio 2010
 
Plano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio II
Plano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio IIPlano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio II
Plano de aula: Aspectos Didático-pedagógicos da Matemática no Ensino Médio II
 
Planejamento Matrizes e determinantes
Planejamento Matrizes e determinantesPlanejamento Matrizes e determinantes
Planejamento Matrizes e determinantes
 

Semelhante a Multiplicação de matrizes em cuda

Grafos e Algoritimos - Dr. Julio Cesar de Araujo Menezes
Grafos e Algoritimos - Dr. Julio Cesar de Araujo MenezesGrafos e Algoritimos - Dr. Julio Cesar de Araujo Menezes
Grafos e Algoritimos - Dr. Julio Cesar de Araujo Menezes
Julio Menezes
 
Funções (exercícios)
Funções (exercícios)Funções (exercícios)
Funções (exercícios)
Kleber Miranda
 
4 tur11
4 tur114 tur11
Aplicação do k-NN utilizando Bitonic Sort
Aplicação do k-NN utilizando Bitonic SortAplicação do k-NN utilizando Bitonic Sort
Aplicação do k-NN utilizando Bitonic Sort
Vinicius Coelho
 
Lista 1 - Robótica (Jim & Ronie)
Lista 1 - Robótica (Jim & Ronie)Lista 1 - Robótica (Jim & Ronie)
Lista 1 - Robótica (Jim & Ronie)
Jim Naturesa
 
Gabarito funcoes
Gabarito funcoesGabarito funcoes
Gabarito funcoes
bferes
 

Semelhante a Multiplicação de matrizes em cuda (6)

Grafos e Algoritimos - Dr. Julio Cesar de Araujo Menezes
Grafos e Algoritimos - Dr. Julio Cesar de Araujo MenezesGrafos e Algoritimos - Dr. Julio Cesar de Araujo Menezes
Grafos e Algoritimos - Dr. Julio Cesar de Araujo Menezes
 
Funções (exercícios)
Funções (exercícios)Funções (exercícios)
Funções (exercícios)
 
4 tur11
4 tur114 tur11
4 tur11
 
Aplicação do k-NN utilizando Bitonic Sort
Aplicação do k-NN utilizando Bitonic SortAplicação do k-NN utilizando Bitonic Sort
Aplicação do k-NN utilizando Bitonic Sort
 
Lista 1 - Robótica (Jim & Ronie)
Lista 1 - Robótica (Jim & Ronie)Lista 1 - Robótica (Jim & Ronie)
Lista 1 - Robótica (Jim & Ronie)
 
Gabarito funcoes
Gabarito funcoesGabarito funcoes
Gabarito funcoes
 

Último

livro ciclo da agua educação infantil.pdf
livro ciclo da agua educação infantil.pdflivro ciclo da agua educação infantil.pdf
livro ciclo da agua educação infantil.pdf
cmeioctaciliabetesch
 
347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf
347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf
347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf
AntnioManuelAgdoma
 
Aula 2 - Revisando o significado de fração - Parte 2.pptx
Aula 2 - Revisando o significado de fração - Parte 2.pptxAula 2 - Revisando o significado de fração - Parte 2.pptx
Aula 2 - Revisando o significado de fração - Parte 2.pptx
LILIANPRESTESSCUDELE
 
000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf
000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf
000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf
YeniferGarcia36
 
759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf
759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf
759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf
MessiasMarianoG
 
A SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIAS
A SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIASA SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIAS
A SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIAS
HisrelBlog
 
1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.
1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.
1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.
LeticiaRochaCupaiol
 
Vogais Ilustrados para alfabetização infantil
Vogais Ilustrados para alfabetização infantilVogais Ilustrados para alfabetização infantil
Vogais Ilustrados para alfabetização infantil
mamaeieby
 
Pintura Romana .pptx
Pintura Romana                     .pptxPintura Romana                     .pptx
Pintura Romana .pptx
TomasSousa7
 
UFCD_3546_Prevenção e primeiros socorros_geriatria.pdf
UFCD_3546_Prevenção e primeiros socorros_geriatria.pdfUFCD_3546_Prevenção e primeiros socorros_geriatria.pdf
UFCD_3546_Prevenção e primeiros socorros_geriatria.pdf
Manuais Formação
 
UFCD_10949_Lojas e-commerce no-code_índice.pdf
UFCD_10949_Lojas e-commerce no-code_índice.pdfUFCD_10949_Lojas e-commerce no-code_índice.pdf
UFCD_10949_Lojas e-commerce no-code_índice.pdf
Manuais Formação
 
Reino-Vegetal plantas e demais conceitos .pptx
Reino-Vegetal plantas e demais conceitos .pptxReino-Vegetal plantas e demais conceitos .pptx
Reino-Vegetal plantas e demais conceitos .pptx
CarinaSantos916505
 
slides de Didática 2.pdf para apresentar
slides de Didática 2.pdf para apresentarslides de Didática 2.pdf para apresentar
slides de Didática 2.pdf para apresentar
JoeteCarvalho
 
GÊNERO TEXTUAL - POEMA.pptx
GÊNERO      TEXTUAL     -     POEMA.pptxGÊNERO      TEXTUAL     -     POEMA.pptx
GÊNERO TEXTUAL - POEMA.pptx
Marlene Cunhada
 
Slides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptx
Slides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptxSlides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptx
Slides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptx
LuizHenriquedeAlmeid6
 
- TEMPLATE DA PRATICA - Psicomotricidade.pptx
- TEMPLATE DA PRATICA - Psicomotricidade.pptx- TEMPLATE DA PRATICA - Psicomotricidade.pptx
- TEMPLATE DA PRATICA - Psicomotricidade.pptx
LucianaCristina58
 
OS elementos de uma boa Redação para o ENEM.pdf
OS elementos de uma boa Redação para o ENEM.pdfOS elementos de uma boa Redação para o ENEM.pdf
OS elementos de uma boa Redação para o ENEM.pdf
AmiltonAparecido1
 
AVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptx
AVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptxAVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptx
AVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptx
AntonioVieira539017
 
Estrutura Pedagógica - Laboratório de Educação a Distância.ppt
Estrutura Pedagógica - Laboratório de Educação a Distância.pptEstrutura Pedagógica - Laboratório de Educação a Distância.ppt
Estrutura Pedagógica - Laboratório de Educação a Distância.ppt
livrosjovert
 
Treinamento NR 38 - CORPO PRINCIPAL da NORMA.pptx
Treinamento NR 38 - CORPO PRINCIPAL da NORMA.pptxTreinamento NR 38 - CORPO PRINCIPAL da NORMA.pptx
Treinamento NR 38 - CORPO PRINCIPAL da NORMA.pptx
MarcosPaulo777883
 

Último (20)

livro ciclo da agua educação infantil.pdf
livro ciclo da agua educação infantil.pdflivro ciclo da agua educação infantil.pdf
livro ciclo da agua educação infantil.pdf
 
347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf
347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf
347018542-PAULINA-CHIZIANE-Balada-de-Amor-ao-Vento-pdf.pdf
 
Aula 2 - Revisando o significado de fração - Parte 2.pptx
Aula 2 - Revisando o significado de fração - Parte 2.pptxAula 2 - Revisando o significado de fração - Parte 2.pptx
Aula 2 - Revisando o significado de fração - Parte 2.pptx
 
000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf
000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf
000. Para rezar o terço - Junho - mês do Sagrado Coração de Jesús.pdf
 
759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf
759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf
759-fortaleza-resultado-definitivo-prova-objetiva-2024-05-28.pdf
 
A SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIAS
A SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIASA SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIAS
A SOCIOLOGIA E O TRABALHO: ANÁLISES E VIVÊNCIAS
 
1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.
1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.
1ª LEI DE OHN, CARACTERISTICAS IMPORTANTES.
 
Vogais Ilustrados para alfabetização infantil
Vogais Ilustrados para alfabetização infantilVogais Ilustrados para alfabetização infantil
Vogais Ilustrados para alfabetização infantil
 
Pintura Romana .pptx
Pintura Romana                     .pptxPintura Romana                     .pptx
Pintura Romana .pptx
 
UFCD_3546_Prevenção e primeiros socorros_geriatria.pdf
UFCD_3546_Prevenção e primeiros socorros_geriatria.pdfUFCD_3546_Prevenção e primeiros socorros_geriatria.pdf
UFCD_3546_Prevenção e primeiros socorros_geriatria.pdf
 
UFCD_10949_Lojas e-commerce no-code_índice.pdf
UFCD_10949_Lojas e-commerce no-code_índice.pdfUFCD_10949_Lojas e-commerce no-code_índice.pdf
UFCD_10949_Lojas e-commerce no-code_índice.pdf
 
Reino-Vegetal plantas e demais conceitos .pptx
Reino-Vegetal plantas e demais conceitos .pptxReino-Vegetal plantas e demais conceitos .pptx
Reino-Vegetal plantas e demais conceitos .pptx
 
slides de Didática 2.pdf para apresentar
slides de Didática 2.pdf para apresentarslides de Didática 2.pdf para apresentar
slides de Didática 2.pdf para apresentar
 
GÊNERO TEXTUAL - POEMA.pptx
GÊNERO      TEXTUAL     -     POEMA.pptxGÊNERO      TEXTUAL     -     POEMA.pptx
GÊNERO TEXTUAL - POEMA.pptx
 
Slides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptx
Slides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptxSlides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptx
Slides Lição 11, Central Gospel, Os Mortos Em CRISTO, 2Tr24.pptx
 
- TEMPLATE DA PRATICA - Psicomotricidade.pptx
- TEMPLATE DA PRATICA - Psicomotricidade.pptx- TEMPLATE DA PRATICA - Psicomotricidade.pptx
- TEMPLATE DA PRATICA - Psicomotricidade.pptx
 
OS elementos de uma boa Redação para o ENEM.pdf
OS elementos de uma boa Redação para o ENEM.pdfOS elementos de uma boa Redação para o ENEM.pdf
OS elementos de uma boa Redação para o ENEM.pdf
 
AVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptx
AVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptxAVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptx
AVALIAÇÃO DIAGNÓSTICA - 8º ANO 2024.pptx
 
Estrutura Pedagógica - Laboratório de Educação a Distância.ppt
Estrutura Pedagógica - Laboratório de Educação a Distância.pptEstrutura Pedagógica - Laboratório de Educação a Distância.ppt
Estrutura Pedagógica - Laboratório de Educação a Distância.ppt
 
Treinamento NR 38 - CORPO PRINCIPAL da NORMA.pptx
Treinamento NR 38 - CORPO PRINCIPAL da NORMA.pptxTreinamento NR 38 - CORPO PRINCIPAL da NORMA.pptx
Treinamento NR 38 - CORPO PRINCIPAL da NORMA.pptx
 

Multiplicação de matrizes em cuda

  • 1. Multiplicação de Matrizes em CUDA Divino César SoaresPontifícia Universidade Católica de Goiás (CMP/PUC-GO)
  • 2.
  • 3. Gerar uma matriz resultado C com as mesmas dimensões das matrizes A e B.
  • 4. Cada elemento (i, j) da matriz C é o produto (interno) da linha i de A pela coluna j de B.
  • 5. Para cada elemento (i, j) de C:for (k=1; k<=LARGURA; k++) C[i][j] += (A[i][k] * B[k][j]);
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Estrutura da Solução Alocar memória na GPU. Copia dados de entrada. Da CPU para a GPU. Configura execução. Número de threads e blocos. Copia resultados. cudaMalloc((void **)&A_d, size_A); cudaMalloc((void**)&B_d, size_B); cudaMalloc((void**)&C_d, size_C); cudaMemcpy(A_d, A, size_A, cudaMemcpyHostToDevice); cudaMemcpy(B_d, B, size_B , cudaMemcpyHostToDevice); cudaMemcpy(C_d, C, size_C , cudaMemcpyHostToDevice); dim3 gride(X, Y)dim3 bloco(Z, W, K)meu_kernel<<<gride, bloco>>>(A, B, C); cudaMemcpy(C, C_d, size_C , cudaMemcpyDeviceToHost);
  • 16. Kernel 1 dim3 gride(1, 1) dim3 bloco(4, 4, 1) dim3 gride(2, 1) dim3 bloco(4, 4, 1) dim3 gride(1, 1) dim3 bloco(30, 30, 1) Gride Gride Gride << Launcherror >>> Bloco com 600 threads Bloco 0 Bloco 0 Bloco 1
  • 17. Kernel 1 dim3 gride(1, 1) dim3 bloco(LARGURA, LARGURA, 1) Gride LARGURA LARGURA Bloco 0
  • 18. Kernel 1 dim3 gride(1, 1) dim3 bloco(LARGURA, LARGURA, 1) Gride __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } LARGURA LARGURA Bloco 0 Kernel 1: Multiplicação na GPU
  • 19. Kernel 1 1 Instante de tempo t=0 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
  • 20. Kernel 1 1 Instante de tempo t=1 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
  • 21. Kernel 1 1 Instante de tempo t=2 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
  • 22. Kernel 1 1 Instante de tempo t=L 2 __global__voidmulGpu(int *A[], int *B[], int *C[]) { int i = threadIdx.x; int j = threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 1: Multiplicação na GPU 4 1 2 3
  • 23.
  • 25. Kernel 2 dim3 gride(2, 2) dim3 bloco(15, 15, 1) dim3 gride(1, 1) dim3 bloco(30, 30, 1) Gride Gride << Launcherror >>> Bloco com 600 threads Bloco 0, 0 Bloco 0, 1 Bloco 1, 0 Bloco 1, 1
  • 26. Kernel 2 dim3 gride(2, 2) dim3 bloco(15, 15, 1) Gride Bloco 0, 0 Bloco 0, 1 225 threads por bloco.Total de 900 threads. Bloco 1, 0 Bloco 1, 1
  • 27. Kernel 2 dim3 gride(2, 2) dim3 bloco(15, 15, 1) Gride __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } Bloco 0, 0 Bloco 0, 1 Kernel 2: Multiplicação na GPU Bloco 1, 0 Bloco 1, 1
  • 28. Kernel 2 1 2 __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 2: Multiplicação na GPU 4 1 2 3
  • 29. Kernel 2 1 2 __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 2: Multiplicação na GPU 4 1 2 3
  • 30. Kernel 2 1 2 __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 2: Multiplicação na GPU 4 1 2 3
  • 31. Kernel 2 1 Instante de tempo t=L 2 __global__void mulGpu2(int *A[], int *B[], int *C[]) { int i = blockIdx.x * SUB_LARGURA + threadIdx.x; int j = blockIdx.y * SUB_LARGURA + threadIdx.y; for (int k=1; k<=LARGURA; k++) { C[i][j] += (A[i][k] * B[k][j]); } } 3 4 Kernel 2: Multiplicação na GPU 4 1 2 3
  • 32.