Introduction to Parallel Computing
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # HW3: Sobel Due: Tue, 2024/4/16 23:59 [toc] # Problem Description Slides: https://docs.google.com/presentation/d/1-81SNjKhiwSjzG9nTnSsOADAQ91BWc_gBUlh-ql9oX8/edit?usp=sharing This homework helps you understand the basic concepts in CUDA. > The sobel operator is used in image processing and computer vision, particularly within edge detection algorithms where it creates an image emphasising edges. In this homework, you are given the sequential (CPU) code of a 5x5 variant of the sobel operator, and asked to **parallelize it with CUDA**. Refer to the appendix for the information of the CPU version. <span style="color: red;">Your code should only contain a single GPU kernel function named as `sobel()`.</span> ## Input Format The input file is a PNG image with 3 color channels: RGB. ## Output Format The output file is a PNG image with 3 color channels: RGB. Your output is considered correct if at least 99.8% of the pixels are identical with the provided sequential version. Your output is considered incorrect if the dimensions of the output image is incorrect. ## Example Input ![](https://i.imgur.com/61xCJHA.jpg) ## Example Output ![](https://i.imgur.com/oNjZ6AG.jpg) ## Optimization Hint * Shared Memory * Coalesced Memory Access * Lower Precision * 2D Block & 2D threads * CUDA Best Practices * I/O optimization ## Compilation **We use NCHC container for this homework.** We use `Makefile` to build your code. The default Makefile for this homework is provided at `/tmp/dataset-nthu-ipc24/share/hw3/Makefile`. If you wish to change the compilation flags, include `Makefile` in your submission. To use Makefile to build your code, make sure `Makefile` and `hw3.cu` is in the working directory, then run `make` on the command line and it will build `hw3` for you. To remove the built files, run `make clean`. We will compile your code with the following command: ~~~ make ~~~ ## Execution Your code will be executed with a command equalviant to: ~~~ ./hw3 input.png output.png ~~~ The time limit for each test case is 30 seconds. # Report Answer the following questions, in either English or Traditional Chinese. 1. How did you parallelize the code? * Which CUDA APIs did you use? * Which functions are ported to CUDA? How did you distribute the workload to blocks and threads? * How do you implement shared memory? 2. Which optimization techniques did you apply to your code? 3. What's the difference between `cudaMalloc` and `cudaMallocManaged`? When will you pick one over another? 4. Experiment: * Measure the GPU kernel time using nsight compute (`ncu`). Show the difference with and without shared memory. In addition, measure the global memory load throughput (`gld_throughput`) and instruction per cycle (`ipc`) and explain your observation. https://docs.nvidia.com/cuda/profiler-users-guide/#nvprof https://docs.nvidia.com/nsight-compute/NsightComputeCli/#command-line-options-general * Profile your program by measuring the time spend in I/O, memory copy, CPU, and kernel. 5. Pick any image that is not in the sample test cases, run your implementation with the image, and showcase both the input and output in your report. 6. (Optional) Any suggestions or feedback for the homework are welcome. # Submission Upload these files to EEClass: * `hw3.cu` -- the source code of your implementation. * `Makefile` -- optional. Submit this file if you want to change the build command. * `report.pdf` -- your report. Please follow the naming listed above carefully. Failing to adhere to the names above will result to points deduction. Here are a few bad examples: `hw3.CU`, `HW3.cu`, `report.docx`, `report.pages` `Makefile.mak`. # Grading 1. (40%) Correctness. Propotional to the number of test cases solved. 2. (25%) Performance. - (15%) sobel GPU kernel function. - (10%) Total CPU time. for a failed test case, 75 seconds is added to your total time. 3. (35%) Report. # Appendix Please note that this spec, the sample test cases and programs might contain bugs. If you spotted one and are unsure about it, please ask on eeclass. ## Sequential (CPU) Version The reference C++ implementation is at `/tmp/dataset-nthu-ipc24/share/hw3/sobel.cc`. The refernce code follows the same input/output format as your homework, and you can start implementing your version by copying it to `hw3.cu`. ## Sample Testcases The sample test cases are located at `/tmp/dataset-nthu-ipc24/share/hw3/samples`. ## Output validation `/tmp/dataset-nthu-ipc24/share/hw3/hw3-diff` can be used to compare two images. For example, to compare your output with the answer, you may use: ~~~ /tmp/dataset-nthu-ipc24/share/hw3/hw3-diff out.png /tmp/dataset-nthu-ipc24/share/hw3/samples/c-1x.out.png ~~~ ## Judge The `hw3-judge` and `hw3-kernel-judge` command can be used to automatically judge your code against all sample test cases, it also submits your execution time to the scoreboard so you can compare your performance with others. Scoreboard: http://elsa-judge.cs.nthu.edu.tw/hw3/ http://elsa-judge.cs.nthu.edu.tw/hw3-kernel To use it, run `hw3-judge` in the directory that contains your code `hw3.cu`. It will automatically search for `Makefile` and use it to compile your code, or fallback to the TA provided `/tmp/dataset-nthu-ipc24/share/hw3/Makefile` otherwise. If code compiliation is successful, it will then run all the sample test cases, show you the results as well as update the scoreboard. > Note: `hw3-judge` and the scoreboard has nothing to do with grading. > Only the code submitted to iLMS is considered for grading purposes. Type `hw3-judge --help` to see a list of supported options. ### Judge Verdict Table | Verdict | Explaination | |--|--| | internal error | there is a bug in the judge | | time limit exceeded+ | execution time > time limit + 10 seconds | | time limit exceeded | execution time > time limit | | runtime error | your program didn't return 0 or is terminated by a signal | | no output | your program did not produce an output file | | wrong answer | your output is incorrect | | accepted | you passed the test case | ###### tags: `spec`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully