Create separate files for blur kernel and the error handling macro to make the main function more readable

This commit is contained in:
Cosmin Ștefan Ciocan
2024-06-02 09:13:56 +00:00
parent e15f41d213
commit 1b238ff107
@@ -187,26 +187,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hhkNS3HJlFlC",
"outputId": "bb0b3fad-f132-4a26-e247-32bf5e29c1a4"
},
"metadata": {},
"outputs": [],
"source": [
"%%cuda --compiler-args \"$COMPILER_ARGS\"\n",
"\n",
"#include <opencv2/core.hpp>\n",
"#include <opencv2/imgcodecs.hpp>\n",
"\n",
"#include <iostream>\n",
"\n",
"#define BLUR_SIZE 5\n",
"#define R 0\n",
"#define G 1\n",
"#define B 2\n",
"%%cuda_group_save -n \"error_handling.h\" -g \"shared\"\n",
"\n",
"// error checking macro\n",
"#define cudaCheckErrors(msg) \\\n",
@@ -219,7 +203,18 @@
" fprintf(stderr, \"*** FAILED - ABORTING\\n\"); \\\n",
" exit(1); \\\n",
" } \\\n",
" } while (0)\n",
" } while (0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%cuda_group_save -n \"blur_kernel.h\" -g \"shared\"\n",
"\n",
"#define BLUR_SIZE 5\n",
"\n",
"// kernel taken from https://stackoverflow.com/a/65973288\n",
"__global__ void blurKernel(\n",
@@ -249,7 +244,34 @@
" }\n",
" out[row * width * num_channel + col * num_channel + channel] = (unsigned char)(pixVal/pixels);\n",
" }\n",
"}\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hhkNS3HJlFlC",
"outputId": "bb0b3fad-f132-4a26-e247-32bf5e29c1a4"
},
"outputs": [],
"source": [
"%%cuda --compiler-args \"$COMPILER_ARGS\"\n",
"\n",
"#include <iostream>\n",
"\n",
"#include <opencv2/core.hpp>\n",
"#include <opencv2/imgcodecs.hpp>\n",
"\n",
"#include \"error_handling.h\"\n",
"#include \"blur_kernel.h\"\n",
"\n",
"#define R 0\n",
"#define G 1\n",
"#define B 2\n",
"\n",
"int main()\n",
"{\n",
@@ -354,7 +376,7 @@
"kaggle": {
"accelerator": "nvidiaTeslaT4",
"dataSources": [],
"dockerImageVersionId": 30699,
"dockerImageVersionId": 30716,
"isGpuEnabled": true,
"isInternetEnabled": true,
"language": "python",