     // Dimensions of computing elements on the CUDA device.
     int block_dim_x = strtol(block_dim_x_string, NULL, 10);
     int block_dim_y = strtol(block_dim_y_string, NULL, 10);
-    assert((block_dim_x * block_dim_y) <= cuda_device_properties.maxThreadsPerBlock && "Error: Using more threads than permitted by maxThreadsPerBlock");
+    assert(((block_dim_x * block_dim_y) <= cuda_device_properties.maxThreadsPerBlock) && "Error: Using more threads than permitted by maxThreadsPerBlock");
+    assert((((block_dim_x * block_dim_y) % cuda_device_properties.warpSize) == 0) && "Error: Must use thread count which is a multiple of warpSize");
 
     int grid_dim_x = (int) ceil(((*src_bitmap)->width) / ((double) block_dim_x));
     int grid_dim_y = (int) ceil(((*src_bitmap)->height)/ ((double) block_dim_y));

// Pads the binary image given as input with the padding values provided as
// input. The padding value must be a binary white (0) or black (1).
void pad_binary_bitmap(Bitmap** image, uint8_t binary_padding_value, Padding padding) {
    assert(*image && "Error: Bitmap must be non-NULL");
    assert(is_binary_image(*image) && "Error: Must supply a binary image as input: only black (1) and white (0) are allowed");
    assert((binary_padding_value == BINARY_BLACK || binary_padding_value == BINARY_WHITE) && "Error: Must provide a binary value for padding");


// Unpads the image given as input by removing the amount of padding provided as
// input.
void unpad_binary_bitmap(Bitmap** image, Padding padding) {
    assert((*image != NULL) && "Error: Bitmap must be non-NULL");
    assert(is_binary_image(*image) && "Error: Must supply a binary image as input: only black (1) and white (0) are allowed");

    // allocate buffer for image data with less rows and less columns
