Open main menu

CDOT Wiki β

Changes

DPS915 C U D A B O Y S

1,731 bytes added, 14:32, 3 November 2015
Assignment 2
== Assignment 2 ==
 
==== Description ====
Removing the old CPU bottleneck:
for (int i = 0; i < bufferSize; i++){
// going over every byte in the file
switch (mode) {
case 0: // inversion
buffer[i] = ~buffer[i];
break;
case 1: // cycle
buffer [i] = cycle (buffer [i]);
break;
case 2: // RC4
buffer [i] = buffer [i] ^ rc4_output();
break;
}
}
 
And replacing it with
...
if (mode == 0)
getInversionBuffer << < dGrid, dBlock >> >(d_a, bufferSize, d_output);
if (mode == 1)
getCycleBuffer << < dGrid, dBlock >> >(d_a, bufferSize, d_output);
if (mode == 2)
getRC4Buffer << < dGrid, dBlock >> >(d_a, bufferSize, d_output);
...
 
Converting <code>cycle</code> and <code>rc4_output</code> functions to device functions:
/**
* Description: Device function cycle
**/
__device__ char cycle(char value) {
int leftMask = 170;
int rightMask = 85;
int iLeft = value & leftMask;
int iRight = value & rightMask;
iLeft = iLeft >> 1;
iRight = iRight << 1;
return iLeft | iRight;
}
 
/**
* Description: Device function RC4
**/
__device__ unsigned char rc4_output() {
unsigned char temp;
unsigned char S[0x100]; // dec 256
unsigned int i, j;
i = (i + 1) & 0xFF;
j = (j + S[i]) & 0xFF;
temp = S[i];
S[i] = S[j];
S[j] = temp;
return S[(S[i] + S[j]) & 0xFF];
}
 
==== Profiling ====
 
'''RC4 Cipher - 283 MB mp3 File'''
 
'''RC4 Cipher - 636 MB iso File'''
'''RC4 Cipher - 789 MB iso File'''
 
== Assignment 3 ==