Skip to content

Commit

Permalink
Create separate files for blur kernel and the error handling macro to…
Browse files Browse the repository at this point in the history
… make the main function more readable
  • Loading branch information
cosminc98 committed Jun 2, 2024
1 parent e15f41d commit 1b238ff
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions notebooks/compiling-with-external-libraries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -354,7 +376,7 @@
"kaggle": {
"accelerator": "nvidiaTeslaT4",
"dataSources": [],
"dockerImageVersionId": 30699,
"dockerImageVersionId": 30716,
"isGpuEnabled": true,
"isInternetEnabled": true,
"language": "python",
Expand Down

0 comments on commit 1b238ff

Please sign in to comment.