Skip to content

[CODEGEN][OPENCL] Sampler definition should be at outermost scope#12951

Merged
masahi merged 1 commit intoapache:mainfrom
srkreddy1238:sampler
Oct 5, 2022
Merged

[CODEGEN][OPENCL] Sampler definition should be at outermost scope#12951
masahi merged 1 commit intoapache:mainfrom
srkreddy1238:sampler

Conversation

@srkreddy1238
Copy link
Contributor

Not all OpenCL compiers happy with inline sampler definition.

Specification: "The image read functions take a sampler argument. The sampler can be passed as an argument to the kernel using clSetKernelArg, or can be declared in the outermost scope of kernel functions, or it can be a constant variable of type sampler_t declared in the program source."

Not all OpenCL compiers happy with inline sample definitions.

Specification: "The image read functions take a sampler argument. The sampler can be passed as an
argument to the kernel using clSetKernelArg, or can be declared in the outermost scope of
kernel functions, or it can be a constant variable of type sampler_t declared in the program source."
Copy link
Contributor

@echuraev echuraev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thaks! In general LGTM. One minor question.

for (Var arg : f->params) {
auto ptr_type = arg->type_annotation.as<PointerTypeNode>();
if (ptr_type && runtime::IsTextureStorage(std::string(ptr_type->storage_scope))) {
this->stream << " const sampler_t image_sampler = "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Will we create this variable before function body in global scope?
If yes, then why we need this indent before const sampler_t ...?
I suppose it should be something like that:

const sampler_t image_sampler = "CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n";
__kernel void kernel_name(..) {
    // ...
}

Am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the first line of function body.

__kernel void kernel_name(..) {
const sampler_t image_sampler = "CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
// ...
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for the clarification! LGTM.

@echuraev
Copy link
Contributor

cc: @masahi

@masahi masahi merged commit a997c23 into apache:main Oct 5, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
…ache#12951)

Not all OpenCL compiers happy with inline sample definitions.

Specification: "The image read functions take a sampler argument. The sampler can be passed as an
argument to the kernel using clSetKernelArg, or can be declared in the outermost scope of
kernel functions, or it can be a constant variable of type sampler_t declared in the program source."
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

Successfully merging this pull request may close these issues.

3 participants