Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

vec type conversion error in device code #73

Closed
wdx04 opened this issue Dec 12, 2017 · 2 comments
Closed

vec type conversion error in device code #73

wdx04 opened this issue Dec 12, 2017 · 2 comments
Assignees
Labels

Comments

@wdx04
Copy link

wdx04 commented Dec 12, 2017

Hi,

I created a template function to read from an accessor with id range check(when id is out of range, return a default-constructed value instead):

template<typename AccessorT>
inline typename AccessorT::value_type guarded_read(AccessorT& acc, const sycl::id<2>& id)
{
	auto range = acc.get_range();
	return (id[0] < range[0] && id[1] < range[1]) ? acc[id] : typename AccessorT::value_type();
}

This function works when AccessorT::value_type is a scalar type but when AccessorT::value_type is a vec type such as cl::sycl::cl_uchar16, compiler errors occurred:

1>  C:/Develop/TestSYCL/TestSYCL.cpp:36:9: error: no viable conversion from returned value of type 'unsigned char __attribute__((ext_vector_type(16)))' (vector of 16 'unsigned char' values) to function return type 'const cl::sycl::vec<unsigned char, 16>'
1>          return (id[0] < range[0] && id[1] < range[1]) ? acc[id] : typename AccessorT::value_type();
1>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>  C:/Program Files/Codeplay/ComputeCpp/include\SYCL/vec.h:9461:3: note: candidate constructor not viable: no known conversion from 'unsigned char __attribute__((ext_vector_type(16)))' (vector of 16 'unsigned char' values) to 'const vec<unsigned char, 16> &' for 1st argument
1>    vec(const vec<dataT, kElems> &rhs) {
1>    ^
1>  C:/Program Files/Codeplay/ComputeCpp/include\SYCL/vec.h:9437:3: note: candidate template ignored: could not match 'swizzled_vec<unsigned char, kElemsRhs, kIndexRhsN...>' against 'unsigned char __attribute__((ext_vector_type(16)))' (vector of 16 'unsigned char' values)
1>    vec(const swizzled_vec<dataT, kElemsRhs, kIndexRhsN...> &rhs) {

I'm using ComputeCpp 0.5.0 with Visual Studio 2015.

Update: the following variations of the function do compile without errors:

template<typename AccessorT>
inline typename AccessorT::value_type guarded_read(AccessorT& acc, const sycl::id<2>& id)
{
	auto range = acc.get_range();
	if (id[0] < range[0] && id[1] < range[1])
		return acc[id];
	else
		return typename AccessorT::value_type();
}
template<typename AccessorT>
inline typename AccessorT::value_type guarded_read(AccessorT& acc, const sycl::id<2>& id)
{
	auto range = acc.get_range();
	return (id[0] < range[0] && id[1] < range[1]) ? typename AccessorT::value_type(acc[id]) : typename AccessorT::value_type();
}
@DuncanMcBain DuncanMcBain self-assigned this Dec 12, 2017
@DuncanMcBain
Copy link
Member

Hi @wdx04, thanks very much for your bug report, it's very clear. I've managed to reproduce this, vectors are a rather complicated part of our implementation so occasionally problems like this will pop up. What I'm going to do is that on Monday, I'll make a bug internally for this, then we can start working on it. I don't think the fix will be finished next week, which means this might remain as it is for a little while. Is that a problem for you? I suppose that, since you have the two other versions that do work, you might be OK. One thing I've discovered is that it appears only to happen for the device compiler, the host can compile it just fine. Hopefully that can help us narrow down what the problem is.

Thanks again,
Duncan.

@DuncanMcBain
Copy link
Member

I believe this was fixed in a previous ComputeCpp release. Please make a new issue if it doesn't.

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

No branches or pull requests

2 participants