+// Le kernel de la convolution en constant memory.
+__constant__ float TAB_KERNEL[KERNEL_SIZE][KERNEL_SIZE];
+
+// L'image source accédée comme une texture.
+texture<uchar4, 2, cudaReadModeElementType> textureImageSource;
+
+ConstantMemoryLink constantMemoryKernelLink()
+ {
+ float* ptrDevTabData;
+ size_t sizeAll = KERNEL_SIZE * KERNEL_SIZE * sizeof(float);
+ HANDLE_ERROR(cudaGetSymbolAddress((void**)&ptrDevTabData, TAB_KERNEL));
+ ConstantMemoryLink cmLink =
+ {
+ (void**)ptrDevTabData, KERNEL_SIZE * KERNEL_SIZE, sizeAll
+ };
+ return cmLink;
+ }
+
+void bindSouceAsTexture(uchar4* source, int w, int h)
+ {
+ // Propriétés de la texture (image en entrée).
+ textureImageSource.addressMode[0] = cudaAddressModeClamp;
+ textureImageSource.addressMode[1] = cudaAddressModeClamp;
+ textureImageSource.filterMode = cudaFilterModePoint;
+ textureImageSource.normalized = false;
+
+ const size_t pitch = w * sizeof(uchar4); // Taille d'une ligne.
+ cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<uchar4>();
+ HANDLE_ERROR(cudaBindTexture2D(NULL, textureImageSource, source, channelDesc, w, h, pitch));
+ }
+
+void unbindSouceAsTexture()
+ {
+ HANDLE_ERROR(cudaUnbindTexture(textureImageSource));
+ }
+