Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I convert the following code to managedCuda code #119

Open
williamlzw opened this issue Jun 21, 2023 · 1 comment
Open

How do I convert the following code to managedCuda code #119

williamlzw opened this issue Jun 21, 2023 · 1 comment

Comments

@williamlzw
Copy link

__global__ void image_crop(float* image_float, cudaTextureObject_t texture_object, int map_y0, int map_x0)
{
    int cropped_y = blockIdx.x;
    int cropped_x = threadIdx.x;
    int cropped_width = blockDim.x;

    float map_y = float(map_y0 + cropped_y);
    float map_x = float(map_x0 + cropped_x);

    float map_value = tex2D<float>(texture_object, map_x + 0.5, map_y + 0.5);
    image_float[cropped_y * cropped_width + cropped_x] = (map_value - 0.5) / 0.225;
}
@williamlzw williamlzw changed the title How do I convert the following code to cusharp code How do I convert the following code to managedCuda code Jun 21, 2023
@kunzmi
Copy link
Owner

kunzmi commented Jun 21, 2023

You don't convert anything, it is the same code.
The only thing that changes when porting a C++/Cuda application to ManagedCuda, is the host code that is calling your kernel as it is now written in C#, the kernel code itself remains untouched.
Using standard Nvidia Cuda toolchain (nvcc) you compile the kernels to PTX or cubin, and then you load the kernels in C# host code. Even though the samples haven't been updated for a while, you still can use them as the basics didn't evolve over time. Have a look at VectorAdd for the host code and VectorAddKernel for the kernel code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants