Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
#include "image.h"

__global__ void negative_kernal (unsigned char *pixel, unsigned char max_value, int n)
{
    /******************/
    /* your code here */
    /******************/

    /* calculate thread ID */
    /* calculate number of threads from grid dimension */
    /* use a while loop to process data, jumping appropriate index */
}

void process_data (image *photo)
{
    /******************/
    /* your code here */
    /******************/

    /* Note that all information can be retrieved from photo */

    /* step 1: allocate device memory */
    /* step 2: copy pixel data to device memory */
    /* step 3: invoke kernel function */
    /* step 4: copy result from device memory to host */
    /* step 5: clear device memory */
}

image *setup (int argc, char **argv)
{
    image *photo;

    if (argc < 3)
    {
        fprintf (stderr, "Usage: %s <infile> <outfile>\n\n", argv [0]);
        return NULL;
    }

    photo = read_image (argv [1]);
    if (photo == NULL)
    {
        fprintf (stderr, "Unable to read input file %s\n\n", argv [1]);
        return NULL;
    }

    return photo;
}

void cleanup (image *photo, char **argv)
{
    int rc = write_image (argv [2], photo);
    if (!rc)
    {
        fprintf (stderr, "Unable to write output file %s\n\n", argv [2]);
    }

    clear_image (photo);
}

int main (int argc, char **argv)
{
    image *photo = setup (argc, argv);
    process_data (photo);
    cleanup (photo, argv);
    return 0;
}

What I have tried:

I have tried YouTube and Chegg. Both were unsuccessful and I am still very confused.
Posted
Updated 11-Oct-21 22:48pm
Comments
Richard MacCutchan 12-Oct-21 5:55am    
"I have tried YouTube and Chegg."
A waste of time. Get some proper study guides, or your own course notes.
Dave Kreskowiak 12-Oct-21 8:56am    
You're going to have to define what you mean by "help". It seems everything we would tell you to do has already been supplied in the code snippet you posted.

Telling you exactly how to do each step would not be helping you, but doing your work for you.

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Just posting a method signature with
/******************/
/* your code here */
/******************/
isn't going to get it done for you.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Dave Kreskowiak 12-Oct-21 8:52am    
I get the feeling the code that was posted is the framework code given in the assignment by the teacher.

Kind of like that other guy with the "className" parameter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900