SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Renderscript
GDG Paris Android User Group
Mars 2013 - par Sylvain Galand
Renderscript
Objectif : Embellir Android !
Outil pour supporter la diversité

● "Write once, run anywhere"

● Quelque soit le GPU (extensions OpenGL)

● Introduction en interne en 2.x
Evolution : Calcul

● Execution optimale partout

● Important pour le calcul

● Publique depuis 3.x
Et Maintenant ?




    CALCUL
  SEULEMENT !
Dépréciation "Render" (Android 4.1)
Deprecation Notice:

Earlier versions of Renderscript included an
experimental graphics engine component.
This component is now deprecated as of
Android 4.1 [...] If you have apps that render
graphics with Renderscript, we highly
recommend you convert your code to
another Android graphics rendering option.
Pourquoi ?

● Les développeurs préfèrent OpenGL


● OpenGL plus utilisé en interne aussi
Renderscript, c'est ...
● Un outil pour les calculs

● Ne remplace ni SDK, ni NDK.

● Problématiques spécifiques
  ○ calculs
  ○ performances
Les 3 piliers de Renderscript
● Portabilité
   ○ Android 3.0+
   ○ ≈45%

● Performances
   ○ CPU (architectures, coeurs, instructions)
   ○ GPU

● Simplicité d'utilisation
   ○ Génération de "glue code"
MAIS QU'EST CE QUE C'EST ?

● C99 : le langage

● API de calcul

● Outils SDK pour la génération de code
Au coeur de RS


           APK            Appareil
            bytecode             binaire
 code.rs                           RS
           Renderscript
                           GPU



                           CPU   CPU
                           #1    #2
Code généré
                         ScriptC_script.java
      script.rs
                          /res/raw/script.bc

typedef struct Struct   ScriptField_Struct.java

Struct_t* my_struct;     .bind_my_struct(...);

                           .set_entier(int i);
     int entier;
                             .get_entier();

  void fonction();        .invoke_fonction();
Utilisation de Renderscript
Par exemple, un exemple :
● Application d'un filtre sur un Bitmap

● Calcul matriciel

● 1 milliard de $

● Améliorons les temps de calcul
filter.rs - Pragmas - 1/4


#pragma version(1)

#pragma rs java_package_name(com.
genymobile.owf)

rs_matrix3x3 filter;
filter.rs - init() - 2/4



void init() {
  rsMatrixLoadIdentity(&filter);
}
filter.rs - root() - 3/4


void root(const uchar4 *in, uchar4 *out)
{
  float3 pixel =convert_float4(in[0]).rgb;
  pixel = rsMatrixMultiply(&filter,pixel);
  pixel = clamp(pixel, 0.f, 255.f);
  out->a = in->a;
  out->rgb = convert_uchar3(pixel);
}
filter.rs - Complet - 4/4
#pragma version(1)
#pragma rs java_package_name(com.genymobile.owf)
rs_matrix3x3 filter;

void init() {
   rsMatrixLoadIdentity(&filter);
}

void root(const uchar4 *in, uchar4 *out) {
   float3 pixel = convert_float4(in[0]).rgb;
   pixel = rsMatrixMultiply(&filter, pixel);
   pixel = clamp(pixel, 0.f, 255.f);
   out->a = in->a;
   out->rgb = convert_uchar3(pixel);
}
Filter.java - Création - 1/7


// Création du script
mRS = RenderScript.create(mContext);
mScript = new ScriptC_filter(mRS,
       mContext.getResources(),
       R.raw.filter);
Filter.java - Allocations - 2/7

// Allocation de la mémoire
// contenant le bitmap
mInAllocation =
  Allocation.createFromBitmap(
    mRS,
    inputBitmap,
    Allocation.MipmapControl.MIPMAP_NONE,
    Allocation.USAGE_SCRIPT);
Filter.java - Allocations - 3/7


// Allocation de la mémoire pour
// récupérer l'image générée
mOutAllocation = Allocation.createTyped(
  mRS,
  mInAllocation.getType());
Filter.java - Paramètre - 4/7


// Mise en place des paramètres
Matrix3f sepiaMatrix =
  new Matrix3f(mMatrix);

mScript.set_filter(sepiaMatrix);
Filter.java - Appel - 5/7


// Appel du script (rsForEach)
mScript.forEach_root(
  mInAllocation,
  mOutAllocation);
Filter.java - Résultat - 6/7


// Copie du résultat dans
// le bitmap de sortie
mOutAllocation.copyTo(outputBitmap);
Filter.java - Complet - 7/7
// Création du script
mRS = RenderScript.create(mContext);
mScript = new ScriptC_filter(mRS, mContext.getResources(), R.raw.filter);

// Allocation de la mémoire contenant le bitmap
mInAllocation = Allocation.createFromBitmap(mRS, inputBitmap,
    Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);

// Allocation de la mémoire pour récupérer l'image générée
mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());

// Mise en place des paramètres
Matrix3f sepiaMatrix = new Matrix3f(mMatrix);
mScript.set_filter(sepiaMatrix);

// Appel du script (rsForEach)
mScript.forEach_root(mInAllocation, mOutAllocation);

// Copie du résultat dans le bitmap de sortie
mOutAllocation.copyTo(outputBitmap);
Démo
QRCode!
Résultats
      Appareil (matériel)                    Java   RS       Gain
Nexus S
                                           960 ms   280 ms   x 3.4
(Exynos 1 GHz Cortex A8)

Galaxy Nexus
                                           360 ms   80 ms    x 4.5
(OMAP 4460 1,2 GHz dual-core)

Samsung Galaxy S2
                                           340 ms   48 ms    x 7.0
(1.2 GHz dual-core ARM Cortex-A9)

Samsung Galaxy S3
                                           325 ms   49 ms    x 6.6
(1.4 GHz quad-core ARM Cortex-A9)

Motorola Xoom
                                           210 ms   26 ms    x 8.0
(Tegra 2: 1GHz dual-core)

Nexus 7
                                           180 ms   22 ms    x 8.2
(Tegra 3: 1.3 GHz quad-core)

Intel AZ210 - Intel Orange San Diego
                                           293 ms   59 ms    x 4.9
(Intel Atom 1.6 Ghz Z2460 with HT - x86)
RS en Bref
● Solution pour les calculs

● Intégration simplifiée & portabilitée

● à vous de jouer !
MERCI !


@sylvaingaland

http://slvn.fr/+

Code :
http://github.com/sgaland

Más contenido relacionado

Similar a Paug renderscript-mars-2013

OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...
OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...
OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...Paris Open Source Summit
 
Sizing PoC LSF & PowerAI for Engineers schools workloads
Sizing PoC LSF & PowerAI for Engineers schools workloadsSizing PoC LSF & PowerAI for Engineers schools workloads
Sizing PoC LSF & PowerAI for Engineers schools workloadsPhilippeBrogi
 
Rouabhi algiers meetup
Rouabhi algiers meetupRouabhi algiers meetup
Rouabhi algiers meetupSamir Rouabhi
 
Comment développer un serveur métier en python/C++
Comment développer un serveur métier en python/C++Comment développer un serveur métier en python/C++
Comment développer un serveur métier en python/C++cppfrug
 
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseriesBreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseriesXavier MARIN
 
Softshake 2013 - Vivre en parallèle
Softshake 2013 - Vivre en parallèleSoftshake 2013 - Vivre en parallèle
Softshake 2013 - Vivre en parallèleOCTO Technology
 
Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Henri Tremblay
 
gRPC, ECHANGES A HAUTE FREQUENCE !
gRPC, ECHANGES A HAUTE FREQUENCE !gRPC, ECHANGES A HAUTE FREQUENCE !
gRPC, ECHANGES A HAUTE FREQUENCE !Carles Sistare
 
gRPC, échange à haute fréquence!
gRPC, échange à haute fréquence!gRPC, échange à haute fréquence!
gRPC, échange à haute fréquence!David Caramelo
 
Présentation Javascript à l'ESI (Alger)
Présentation Javascript à l'ESI (Alger)Présentation Javascript à l'ESI (Alger)
Présentation Javascript à l'ESI (Alger)Dr Samir A. ROUABHI
 
Tp2: Installation d'une couche d’abstraction entre un robot physique et ros
Tp2: Installation d'une couche d’abstraction entre un robot physique et rosTp2: Installation d'une couche d’abstraction entre un robot physique et ros
Tp2: Installation d'une couche d’abstraction entre un robot physique et rosSaid Benaissa
 
Réussir une montée en charge avec MongoDB
Réussir une montée en charge avec MongoDBRéussir une montée en charge avec MongoDB
Réussir une montée en charge avec MongoDB MongoDB
 
GWT : under the hood
GWT : under the hoodGWT : under the hood
GWT : under the hoodsvuillet
 
Aspect avec AspectJ
Aspect avec AspectJAspect avec AspectJ
Aspect avec AspectJsimeon
 
Comment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguerComment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguerDamien Seguy
 
Graphics card as computation engine
Graphics card as computation engineGraphics card as computation engine
Graphics card as computation enginevalery brasseur
 
Développement d'un générateur d'intépréteur de bytecodes pour une JVM embarquée
Développement d'un générateur d'intépréteur de bytecodes pour une JVM embarquéeDéveloppement d'un générateur d'intépréteur de bytecodes pour une JVM embarquée
Développement d'un générateur d'intépréteur de bytecodes pour une JVM embarquéeMustapha Tachouct
 

Similar a Paug renderscript-mars-2013 (20)

OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...
OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...
OWF12/PAUG Conf Days Render script, sylvain galand, software engineer at geny...
 
Sizing PoC LSF & PowerAI for Engineers schools workloads
Sizing PoC LSF & PowerAI for Engineers schools workloadsSizing PoC LSF & PowerAI for Engineers schools workloads
Sizing PoC LSF & PowerAI for Engineers schools workloads
 
Rouabhi algiers meetup
Rouabhi algiers meetupRouabhi algiers meetup
Rouabhi algiers meetup
 
The Future of Javascript
The Future of JavascriptThe Future of Javascript
The Future of Javascript
 
The future of JavaScript
The future of JavaScriptThe future of JavaScript
The future of JavaScript
 
Comment développer un serveur métier en python/C++
Comment développer un serveur métier en python/C++Comment développer un serveur métier en python/C++
Comment développer un serveur métier en python/C++
 
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseriesBreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
 
Softshake 2013 - Vivre en parallèle
Softshake 2013 - Vivre en parallèleSoftshake 2013 - Vivre en parallèle
Softshake 2013 - Vivre en parallèle
 
Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013
 
gRPC, ECHANGES A HAUTE FREQUENCE !
gRPC, ECHANGES A HAUTE FREQUENCE !gRPC, ECHANGES A HAUTE FREQUENCE !
gRPC, ECHANGES A HAUTE FREQUENCE !
 
gRPC, échange à haute fréquence!
gRPC, échange à haute fréquence!gRPC, échange à haute fréquence!
gRPC, échange à haute fréquence!
 
Présentation Javascript à l'ESI (Alger)
Présentation Javascript à l'ESI (Alger)Présentation Javascript à l'ESI (Alger)
Présentation Javascript à l'ESI (Alger)
 
Tp2: Installation d'une couche d’abstraction entre un robot physique et ros
Tp2: Installation d'une couche d’abstraction entre un robot physique et rosTp2: Installation d'une couche d’abstraction entre un robot physique et ros
Tp2: Installation d'une couche d’abstraction entre un robot physique et ros
 
Ogre 3D : une introduction
Ogre 3D : une introductionOgre 3D : une introduction
Ogre 3D : une introduction
 
Réussir une montée en charge avec MongoDB
Réussir une montée en charge avec MongoDBRéussir une montée en charge avec MongoDB
Réussir une montée en charge avec MongoDB
 
GWT : under the hood
GWT : under the hoodGWT : under the hood
GWT : under the hood
 
Aspect avec AspectJ
Aspect avec AspectJAspect avec AspectJ
Aspect avec AspectJ
 
Comment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguerComment relire du code pourri sans se fatiguer
Comment relire du code pourri sans se fatiguer
 
Graphics card as computation engine
Graphics card as computation engineGraphics card as computation engine
Graphics card as computation engine
 
Développement d'un générateur d'intépréteur de bytecodes pour une JVM embarquée
Développement d'un générateur d'intépréteur de bytecodes pour une JVM embarquéeDéveloppement d'un générateur d'intépréteur de bytecodes pour une JVM embarquée
Développement d'un générateur d'intépréteur de bytecodes pour une JVM embarquée
 

Más de Paris Android User Group

Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014Paris Android User Group
 
Workshop: Amazon developer ecosystem - DroidCon Paris2014
Workshop: Amazon developer ecosystem - DroidCon Paris2014Workshop: Amazon developer ecosystem - DroidCon Paris2014
Workshop: Amazon developer ecosystem - DroidCon Paris2014Paris Android User Group
 
Extending your apps to wearables - DroidCon Paris 2014
Extending your apps to wearables -  DroidCon Paris 2014Extending your apps to wearables -  DroidCon Paris 2014
Extending your apps to wearables - DroidCon Paris 2014Paris Android User Group
 
Scaling android development - DroidCon Paris 2014
Scaling android development - DroidCon Paris 2014Scaling android development - DroidCon Paris 2014
Scaling android development - DroidCon Paris 2014Paris Android User Group
 
Ingredient of awesome app - DroidCon Paris 2014
Ingredient of awesome app - DroidCon Paris 2014Ingredient of awesome app - DroidCon Paris 2014
Ingredient of awesome app - DroidCon Paris 2014Paris Android User Group
 
Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014Paris Android User Group
 
Archos Android based connected home solution - DroidCon Paris 2014
Archos Android based connected home solution - DroidCon Paris 2014Archos Android based connected home solution - DroidCon Paris 2014
Archos Android based connected home solution - DroidCon Paris 2014Paris Android User Group
 
Porting VLC on Android - DroidCon Paris 2014
Porting VLC on Android - DroidCon Paris 2014Porting VLC on Android - DroidCon Paris 2014
Porting VLC on Android - DroidCon Paris 2014Paris Android User Group
 
Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014
Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014
Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014Paris Android User Group
 
maximize app engagement and monetization - DroidCon Paris 2014
maximize app engagement and monetization - DroidCon Paris 2014maximize app engagement and monetization - DroidCon Paris 2014
maximize app engagement and monetization - DroidCon Paris 2014Paris Android User Group
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Paris Android User Group
 
Holo material design transition - DroidCon Paris 2014
Holo material design transition - DroidCon Paris 2014Holo material design transition - DroidCon Paris 2014
Holo material design transition - DroidCon Paris 2014Paris Android User Group
 
Google glass droidcon - DroidCon Paris 2014
Google glass droidcon - DroidCon Paris 2014Google glass droidcon - DroidCon Paris 2014
Google glass droidcon - DroidCon Paris 2014Paris Android User Group
 
Embedded webserver implementation and usage - DroidCon Paris 2014
Embedded webserver implementation and usage - DroidCon Paris 2014Embedded webserver implementation and usage - DroidCon Paris 2014
Embedded webserver implementation and usage - DroidCon Paris 2014Paris Android User Group
 
Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014
Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014
Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014Paris Android User Group
 
What's new in android 4.4 - Romain Guy & Chet Haase
What's new in android 4.4 - Romain Guy & Chet HaaseWhat's new in android 4.4 - Romain Guy & Chet Haase
What's new in android 4.4 - Romain Guy & Chet HaaseParis Android User Group
 
Efficient Image Processing - Nicolas Roard
Efficient Image Processing - Nicolas RoardEfficient Image Processing - Nicolas Roard
Efficient Image Processing - Nicolas RoardParis Android User Group
 

Más de Paris Android User Group (20)

Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014
 
Workshop: Amazon developer ecosystem - DroidCon Paris2014
Workshop: Amazon developer ecosystem - DroidCon Paris2014Workshop: Amazon developer ecosystem - DroidCon Paris2014
Workshop: Amazon developer ecosystem - DroidCon Paris2014
 
Extending your apps to wearables - DroidCon Paris 2014
Extending your apps to wearables -  DroidCon Paris 2014Extending your apps to wearables -  DroidCon Paris 2014
Extending your apps to wearables - DroidCon Paris 2014
 
Scaling android development - DroidCon Paris 2014
Scaling android development - DroidCon Paris 2014Scaling android development - DroidCon Paris 2014
Scaling android development - DroidCon Paris 2014
 
Ingredient of awesome app - DroidCon Paris 2014
Ingredient of awesome app - DroidCon Paris 2014Ingredient of awesome app - DroidCon Paris 2014
Ingredient of awesome app - DroidCon Paris 2014
 
Framing the canvas - DroidCon Paris 2014
Framing the canvas - DroidCon Paris 2014Framing the canvas - DroidCon Paris 2014
Framing the canvas - DroidCon Paris 2014
 
Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014
 
Archos Android based connected home solution - DroidCon Paris 2014
Archos Android based connected home solution - DroidCon Paris 2014Archos Android based connected home solution - DroidCon Paris 2014
Archos Android based connected home solution - DroidCon Paris 2014
 
Porting VLC on Android - DroidCon Paris 2014
Porting VLC on Android - DroidCon Paris 2014Porting VLC on Android - DroidCon Paris 2014
Porting VLC on Android - DroidCon Paris 2014
 
Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014
Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014
Robotium vs Espresso: Get ready to rumble ! - DroidCon Paris 2014
 
Buildsystem.mk - DroidCon Paris 2014
Buildsystem.mk - DroidCon Paris 2014Buildsystem.mk - DroidCon Paris 2014
Buildsystem.mk - DroidCon Paris 2014
 
maximize app engagement and monetization - DroidCon Paris 2014
maximize app engagement and monetization - DroidCon Paris 2014maximize app engagement and monetization - DroidCon Paris 2014
maximize app engagement and monetization - DroidCon Paris 2014
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 
Holo material design transition - DroidCon Paris 2014
Holo material design transition - DroidCon Paris 2014Holo material design transition - DroidCon Paris 2014
Holo material design transition - DroidCon Paris 2014
 
Death to passwords - DroidCon Paris 2014
Death to passwords - DroidCon Paris 2014Death to passwords - DroidCon Paris 2014
Death to passwords - DroidCon Paris 2014
 
Google glass droidcon - DroidCon Paris 2014
Google glass droidcon - DroidCon Paris 2014Google glass droidcon - DroidCon Paris 2014
Google glass droidcon - DroidCon Paris 2014
 
Embedded webserver implementation and usage - DroidCon Paris 2014
Embedded webserver implementation and usage - DroidCon Paris 2014Embedded webserver implementation and usage - DroidCon Paris 2014
Embedded webserver implementation and usage - DroidCon Paris 2014
 
Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014
Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014
Petit design Grande humanité par Geoffrey Dorne - DroidCon Paris 2014
 
What's new in android 4.4 - Romain Guy & Chet Haase
What's new in android 4.4 - Romain Guy & Chet HaaseWhat's new in android 4.4 - Romain Guy & Chet Haase
What's new in android 4.4 - Romain Guy & Chet Haase
 
Efficient Image Processing - Nicolas Roard
Efficient Image Processing - Nicolas RoardEfficient Image Processing - Nicolas Roard
Efficient Image Processing - Nicolas Roard
 

Paug renderscript-mars-2013

  • 1. Renderscript GDG Paris Android User Group Mars 2013 - par Sylvain Galand
  • 4. Outil pour supporter la diversité ● "Write once, run anywhere" ● Quelque soit le GPU (extensions OpenGL) ● Introduction en interne en 2.x
  • 5. Evolution : Calcul ● Execution optimale partout ● Important pour le calcul ● Publique depuis 3.x
  • 6. Et Maintenant ? CALCUL SEULEMENT !
  • 7. Dépréciation "Render" (Android 4.1) Deprecation Notice: Earlier versions of Renderscript included an experimental graphics engine component. This component is now deprecated as of Android 4.1 [...] If you have apps that render graphics with Renderscript, we highly recommend you convert your code to another Android graphics rendering option.
  • 8. Pourquoi ? ● Les développeurs préfèrent OpenGL ● OpenGL plus utilisé en interne aussi
  • 9. Renderscript, c'est ... ● Un outil pour les calculs ● Ne remplace ni SDK, ni NDK. ● Problématiques spécifiques ○ calculs ○ performances
  • 10. Les 3 piliers de Renderscript ● Portabilité ○ Android 3.0+ ○ ≈45% ● Performances ○ CPU (architectures, coeurs, instructions) ○ GPU ● Simplicité d'utilisation ○ Génération de "glue code"
  • 11. MAIS QU'EST CE QUE C'EST ? ● C99 : le langage ● API de calcul ● Outils SDK pour la génération de code
  • 12. Au coeur de RS APK Appareil bytecode binaire code.rs RS Renderscript GPU CPU CPU #1 #2
  • 13. Code généré ScriptC_script.java script.rs /res/raw/script.bc typedef struct Struct ScriptField_Struct.java Struct_t* my_struct; .bind_my_struct(...); .set_entier(int i); int entier; .get_entier(); void fonction(); .invoke_fonction();
  • 15. Par exemple, un exemple : ● Application d'un filtre sur un Bitmap ● Calcul matriciel ● 1 milliard de $ ● Améliorons les temps de calcul
  • 16. filter.rs - Pragmas - 1/4 #pragma version(1) #pragma rs java_package_name(com. genymobile.owf) rs_matrix3x3 filter;
  • 17. filter.rs - init() - 2/4 void init() { rsMatrixLoadIdentity(&filter); }
  • 18. filter.rs - root() - 3/4 void root(const uchar4 *in, uchar4 *out) { float3 pixel =convert_float4(in[0]).rgb; pixel = rsMatrixMultiply(&filter,pixel); pixel = clamp(pixel, 0.f, 255.f); out->a = in->a; out->rgb = convert_uchar3(pixel); }
  • 19. filter.rs - Complet - 4/4 #pragma version(1) #pragma rs java_package_name(com.genymobile.owf) rs_matrix3x3 filter; void init() { rsMatrixLoadIdentity(&filter); } void root(const uchar4 *in, uchar4 *out) { float3 pixel = convert_float4(in[0]).rgb; pixel = rsMatrixMultiply(&filter, pixel); pixel = clamp(pixel, 0.f, 255.f); out->a = in->a; out->rgb = convert_uchar3(pixel); }
  • 20. Filter.java - Création - 1/7 // Création du script mRS = RenderScript.create(mContext); mScript = new ScriptC_filter(mRS, mContext.getResources(), R.raw.filter);
  • 21. Filter.java - Allocations - 2/7 // Allocation de la mémoire // contenant le bitmap mInAllocation = Allocation.createFromBitmap( mRS, inputBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
  • 22. Filter.java - Allocations - 3/7 // Allocation de la mémoire pour // récupérer l'image générée mOutAllocation = Allocation.createTyped( mRS, mInAllocation.getType());
  • 23. Filter.java - Paramètre - 4/7 // Mise en place des paramètres Matrix3f sepiaMatrix = new Matrix3f(mMatrix); mScript.set_filter(sepiaMatrix);
  • 24. Filter.java - Appel - 5/7 // Appel du script (rsForEach) mScript.forEach_root( mInAllocation, mOutAllocation);
  • 25. Filter.java - Résultat - 6/7 // Copie du résultat dans // le bitmap de sortie mOutAllocation.copyTo(outputBitmap);
  • 26. Filter.java - Complet - 7/7 // Création du script mRS = RenderScript.create(mContext); mScript = new ScriptC_filter(mRS, mContext.getResources(), R.raw.filter); // Allocation de la mémoire contenant le bitmap mInAllocation = Allocation.createFromBitmap(mRS, inputBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); // Allocation de la mémoire pour récupérer l'image générée mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType()); // Mise en place des paramètres Matrix3f sepiaMatrix = new Matrix3f(mMatrix); mScript.set_filter(sepiaMatrix); // Appel du script (rsForEach) mScript.forEach_root(mInAllocation, mOutAllocation); // Copie du résultat dans le bitmap de sortie mOutAllocation.copyTo(outputBitmap);
  • 27. Démo
  • 29. Résultats Appareil (matériel) Java RS Gain Nexus S 960 ms 280 ms x 3.4 (Exynos 1 GHz Cortex A8) Galaxy Nexus 360 ms 80 ms x 4.5 (OMAP 4460 1,2 GHz dual-core) Samsung Galaxy S2 340 ms 48 ms x 7.0 (1.2 GHz dual-core ARM Cortex-A9) Samsung Galaxy S3 325 ms 49 ms x 6.6 (1.4 GHz quad-core ARM Cortex-A9) Motorola Xoom 210 ms 26 ms x 8.0 (Tegra 2: 1GHz dual-core) Nexus 7 180 ms 22 ms x 8.2 (Tegra 3: 1.3 GHz quad-core) Intel AZ210 - Intel Orange San Diego 293 ms 59 ms x 4.9 (Intel Atom 1.6 Ghz Z2460 with HT - x86)
  • 30. RS en Bref ● Solution pour les calculs ● Intégration simplifiée & portabilitée ● à vous de jouer !