On Sun, Jan 29, 2012 at 12:53 PM, recrusader <span dir="ltr">&lt;<a href="mailto:recrusader@gmail.com">recrusader@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear PETSc developers,<br>
<br>
With your help, I can successfully PETSc-deve with enabling GPU and<br>
complex number.<br>
However, when I compiled the codes, I met some errors. I also tried to<br>
use simple codes to realize the same function. However, the errors<br>
disappear. One example is as follows:<br>
<br>
for the function &quot;VecScale_SeqCUSP&quot;<br>
&quot;#undef __FUNCT__<br>
#define __FUNCT__ &quot;VecScale_SeqCUSP&quot;<br>
PetscErrorCode VecScale_SeqCUSP(Vec xin, PetscScalar alpha)<br>
{<br>
  CUSPARRAY      *xarray;<br>
  PetscErrorCode ierr;<br>
<br>
  PetscFunctionBegin;<br>
  if (alpha == 0.0) {<br>
    ierr = VecSet_SeqCUSP(xin,alpha);CHKERRQ(ierr);<br>
  } else if (alpha != 1.0) {<br>
    ierr = VecCUSPGetArrayReadWrite(xin,&amp;xarray);CHKERRQ(ierr);<br>
    try {<br>
      cusp::blas::scal(*xarray,alpha);<br>
    } catch(char* ex) {<br>
      SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,&quot;CUSP error: %s&quot;, ex);<br>
    }<br>
    ierr = VecCUSPRestoreArrayReadWrite(xin,&amp;xarray);CHKERRQ(ierr);<br>
  }<br>
  ierr = WaitForGPU();CHKERRCUSP(ierr);<br>
  ierr = PetscLogFlops(xin-&gt;map-&gt;n);CHKERRQ(ierr);<br>
  PetscFunctionReturn(0);<br>
} &quot;<br>
<br>
When I compiled PETSc-dev, I met the following errors:<br>
&quot; /opt/apps/cuda/4.0/cuda/include/cusp/detail/blas.inl(134): warning:<br>
calling a __host__ function from a __host__ __device__ function is not<br>
allowed<br>
          detected during:<br>
            instantiation of &quot;void<br>
cusp::blas::detail::SCAL&lt;T&gt;::operator()(T2 &amp;) [with<br>
T=std::complex&lt;double&gt;, T2=PetscScalar]&quot;<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/device/cuda/for_each.inl(72): here<br>
            instantiation of &quot;void<br>
thrust::detail::device::cuda::for_each_n_closure&lt;RandomAccessIterator,<br>
Size, UnaryFunction&gt;::operator()() [with<br>
RandomAccessIterator=thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
Size=long, UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/device/cuda/detail/launch_closure.inl(51):<br>
here<br>
            instantiation of &quot;void<br>
thrust::detail::device::cuda::detail::launch_closure_by_value(NullaryFunction)<br>
[with NullaryFunction=thrust::detail::device::cuda::for_each_n_closure&lt;thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
long, cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/device/cuda/detail/launch_closure.inl(71):<br>
here<br>
            instantiation of &quot;size_t<br>
thrust::detail::device::cuda::detail::closure_launcher_base&lt;NullaryFunction,<br>
launch_by_value&gt;::block_size_with_maximal_occupancy(size_t) [with<br>
NullaryFunction=thrust::detail::device::cuda::for_each_n_closure&lt;thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
long, cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;&gt;,<br>
launch_by_value=true]&quot;<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/device/cuda/detail/launch_closure.inl(136):<br>
here<br>
            instantiation of &quot;thrust::pair&lt;size_t, size_t&gt;<br>
thrust::detail::device::cuda::detail::closure_launcher&lt;NullaryFunction&gt;::configuration_with_maximal_occupancy(Size)<br>
[with NullaryFunction=thrust::detail::device::cuda::for_each_n_closure&lt;thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
long, cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;&gt;, Size=long]&quot;<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/device/cuda/detail/launch_closure.inl(145):<br>
here<br>
            [ 6 instantiation contexts not shown ]<br>
            instantiation of &quot;InputIterator<br>
thrust::detail::dispatch::for_each(InputIterator, InputIterator,<br>
UnaryFunction, thrust::device_space_tag) [with<br>
InputIterator=thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/for_each.inl(51): here<br>
            instantiation of &quot;InputIterator<br>
thrust::detail::for_each(InputIterator, InputIterator, UnaryFunction)<br>
[with InputIterator=thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/for_each.inl(67): here<br>
            instantiation of &quot;void thrust::for_each(InputIterator,<br>
InputIterator, UnaryFunction) [with<br>
InputIterator=thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
(367): here<br>
            instantiation of &quot;void<br>
cusp::blas::detail::scal(ForwardIterator, ForwardIterator, ScalarType)<br>
[with ForwardIterator=thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;PetscScalar&gt;&gt;,<br>
ScalarType=std::complex&lt;double&gt;]&quot;<br>
(748): here<br>
            instantiation of &quot;void cusp::blas::scal(Array &amp;,<br>
ScalarType) [with Array=cusp::array1d&lt;PetscScalar,<br>
cusp::device_memory&gt;, ScalarType=std::complex&lt;double&gt;]&quot;<br>
<a href="http://veccusp.cu" target="_blank">veccusp.cu</a>(1185): here<br>
<br>
/opt/apps/cuda/4.0/cuda/include/thrust/detail/device/cuda/detail/launch_closure.inl(51):<br>
error: a value of type &quot;int&quot; cannot be assigned to an entity of type<br>
&quot;_ZNSt7complexIdE9_ComplexTE&quot;<br>
<br>
&quot;<br>
However, I further realize simiar codes as<br>
&quot;<br>
#include &lt;thrust/version.h&gt;<br>
#include &lt;cusp/version.h&gt;<br>
#include &lt;iostream&gt;<br>
#include &lt;cusp/blas.h&gt;<br>
#include &lt;cusp/array1d.h&gt;<br>
#include &lt;complex&gt;<br>
<br>
int main(void)<br>
{<br>
    cusp::array1d&lt;std::complex&lt;double&gt;, cusp::host_memory&gt; *x;<br>
<br>
    x=new cusp::array1d&lt;std::complex&lt;double&gt;, cusp::host_memory&gt;(2,0.0);<br>
<br>
    std::complex&lt;double&gt; alpha(1,2.0);<br>
    cusp::blas::scal(*x,alpha);<br>
<br>
    return 0;<br>
}<br>
&quot;<br>
<br>
When I complied it using  &quot;nvcc <a href="http://gputest.cu" target="_blank">gputest.cu</a> -o gputest&quot;, I only meet<br>
warning information as follows:<br>
&quot;<br>
/opt/apps/cuda/4.0/cuda/bin/../include/cusp/detail/blas.inl(134):<br>
warning: calling a __host__ function from a __host__ __device__<br>
function is not allowed<br>
          detected during:<br>
            instantiation of &quot;void<br>
cusp::blas::detail::SCAL&lt;T&gt;::operator()(T2 &amp;) [with<br>
T=std::complex&lt;double&gt;, T2=std::complex&lt;double&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/bin/../include/thrust/detail/host/for_each.inl(37): here<br>
            instantiation of &quot;InputIterator<br>
thrust::detail::host::for_each(InputIterator, InputIterator,<br>
UnaryFunction) [with<br>
InputIterator=thrust::detail::normal_iterator&lt;std::complex&lt;double&gt; *&gt;,<br>
UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/bin/../include/thrust/detail/dispatch/for_each.h(46):<br>
here<br>
            instantiation of &quot;InputIterator<br>
thrust::detail::dispatch::for_each(InputIterator, InputIterator,<br>
UnaryFunction, thrust::host_space_tag) [with<br>
InputIterator=thrust::detail::normal_iterator&lt;std::complex&lt;double&gt; *&gt;,<br>
UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/bin/../include/thrust/detail/for_each.inl(51): here<br>
            instantiation of &quot;InputIterator<br>
thrust::detail::for_each(InputIterator, InputIterator, UnaryFunction)<br>
[with InputIterator=thrust::detail::normal_iterator&lt;std::complex&lt;double&gt;<br>
*&gt;, UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
/opt/apps/cuda/4.0/cuda/bin/../include/thrust/detail/for_each.inl(67): here<br>
            instantiation of &quot;void thrust::for_each(InputIterator,<br>
InputIterator, UnaryFunction) [with<br>
InputIterator=thrust::detail::normal_iterator&lt;std::complex&lt;double&gt; *&gt;,<br>
UnaryFunction=cusp::blas::detail::SCAL&lt;std::complex&lt;double&gt;&gt;]&quot;<br>
(367): here<br>
            instantiation of &quot;void<br>
cusp::blas::detail::scal(ForwardIterator, ForwardIterator, ScalarType)<br>
[with ForwardIterator=thrust::detail::normal_iterator&lt;std::complex&lt;double&gt;<br>
*&gt;, ScalarType=std::complex&lt;double&gt;]&quot;<br>
(748): here<br>
            instantiation of &quot;void cusp::blas::scal(Array &amp;,<br>
ScalarType) [with Array=cusp::array1d&lt;std::complex&lt;double&gt;,<br>
cusp::host_memory&gt;, ScalarType=std::complex&lt;double&gt;]&quot;<br>
<a href="http://gputest.cu" target="_blank">gputest.cu</a>(25): here<br>
<br>
&quot;<br>
There are not errors like<br>
&quot;/opt/apps/cuda/4.0/cuda/include/thrust/detail/device/cuda/detail/launch_closure.inl(51):<br>
error: a value of type &quot;int&quot; cannot be assigned to an entity of type<br>
&quot;_ZNSt7complexIdE9_ComplexTE&quot; &quot;<br>
<br>
Furthermore, the warning information is also different between<br>
PETSc-dev and simple codes.<br>
<br>
Could you give me some suggestion for this errors? Thank you very much.<br></blockquote><div><br></div><div>The headers are complicated to get right. The whole point of what we did is to give a way to use GPU</div><div>simply through the existing PETSc linear algebra interface.</div>
<div><br></div><div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Best,<br>
Yujie<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>