error af::replace(af::array&, af::array const&, double const&) in /opt/arrayfire/lib64/libafcuda.so.3

38 views
Skip to first unread message

Mpereke Evans

unread,
Aug 12, 2021, 9:33:01 AM8/12/21
to ArrayFire Users
ArrayFire v3.8.0 (CUDA, 64-bit Linux, build d99887a)
Platform: CUDA Runtime 11.4, Driver: 470.57.02
[0] Quadro T2000, 3912 MB, CUDA Compute 7.5

I have the following code:

gfor(seq m, all_ref_cels.dims(0)) {
af::array notZeros = !af::iszero(all_ref_cels(m, span)); // find all entries that are zeros
af::array temp_hold = all_ref_cels(m, span);

// replace all zero entries with NaN - this so as zeros dont enterfere when finding min
replace(temp_hold, notZeros, NaN);
// reorder to dimansions that make sense
all_ref_cels = reorder(temp_hold, 3, 1, 0, 2);
}
it work fine on OpenCL runtime.
However for CUDA runtime I get the following error:

rrayFire Exception (Internal error:998):
In function void cuda::Enqueuer::operator()(void*, const cuda::EnqueueArgs&, Args ...) [with Args = {cuda::Param<float>, cuda::CParam<char>, cuda::CParam<float>, float, int, int}]
In file src/backend/cuda/Kernel.hpp:31
CU Error CUDA_ERROR_INVALID_VALUE(1): invalid argument

 0# 0x00007F7C5231D604 in /opt/arrayfire/lib64/libafcuda.so.3
 1# 0x00007F7C5231DC79 in /opt/arrayfire/lib64/libafcuda.so.3
 2# af_replace_scalar in /opt/arrayfire/lib64/libafcuda.so.3
 3# af::replace(af::array&, af::array const&, double const&) in /opt/arrayfire/lib64/libafcuda.so.3
 4# OS_CFAR(af::array&, af::array&, int, int, int, int, int) in ./GMTI_Processor_opencl
 5# main in ./GMTI_Processor_opencl
 6# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 7# _start in ./GMTI_Processor_opencl

In function void af::replace(af::array&, const af::array&, const double&)
In file src/api/cpp/data.cpp:313
terminate called after throwing an instance of 'af::exception'
  what():  ArrayFire Exception (Internal error:998):
In function void cuda::Enqueuer::operator()(void*, const cuda::EnqueueArgs&, Args ...) [with Args = {cuda::Param<float>, cuda::CParam<char>, cuda::CParam<float>, float, int, int}]
In file src/backend/cuda/Kernel.hpp:31
CU Error CUDA_ERROR_INVALID_VALUE(1): invalid argument

 0# 0x00007F7C5231D604 in /opt/arrayfire/lib64/libafcuda.so.3
 1# 0x00007F7C5231DC79 in /opt/arrayfire/lib64/libafcuda.so.3
 2# af_replace_scalar in /opt/arrayfire/lib64/libafcuda.so.3
 3# af::replace(af::array&, af::array const&, double const&) in /opt/arrayfire/lib64/libafcuda.so.3
 4# OS_CFAR(af::array&, af::array&, int, int, int, int, int) in ./GMTI_Processor_opencl
 5# main in ./GMTI_Processor_opencl
 6# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 7# _start in ./GMTI_Processor_opencl

In function void af::replace(af::array&, const af::array&, const double&)
In file src/api/cpp/data.cpp:313
Aborted (core dumped)

May you please help resolve the issue?

Pradeep Garigipati

unread,
Aug 13, 2021, 1:42:13 AM8/13/21
to Mpereke Evans, ArrayFire Users
Hello Mpereke,

We have feature parity across backends so it is interesting that it works with OpenCL and doesn't on CUDA backend in your trials.

Given below is what I tried and it runs successfully on both backends. Although, I am not quite sure what your objective is with the gfor loop.

        array A = randu(5, 5, f32);

        A(span, 2) = 0.0;
        af_print(A);
        gfor(seq m, A.dims(0)) {
            array notZeros = af::iszero(A(m, span));
            array temp_hold = A(m, span);
            replace(temp_hold, notZeros, NAN);
            A = reorder(temp_hold, 3, 1, 0, 2);
        }
        af_print(A);

If you are trying to set non-zero values to NANs, then you can do that without gfor as well.

Perhaps if you can share a stand alone snippet that illustrates your target logic, I can suggest a better alternative if possible.

Regards,
Pradeep.

--
You received this message because you are subscribed to the Google Groups "ArrayFire Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arrayfire-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/arrayfire-users/ec351807-6e73-45bc-b283-d0b3865c86b7n%40googlegroups.com.


--

Mpereke Evans

unread,
Oct 19, 2021, 9:46:12 AM10/19/21
to ArrayFire Users
A workaround to this problem is to use a the "select" function instead of "replace" function. Instead of using replace function to replace the zero values with NaN, rather create an arrayfire array initialised NaN values and create a condition array that selects NaNs from the NaN initialised array when there are zero values in the other array that needs to be replaced.

// initialize all to NaNs - Replace zeros in ref_cells with NaN in this array
    af::array nan_array = constant(NaN, 1, refCells*2.0);

gfor(seq m, all_ref_cels.dims(0)) {
        af::array notZeros = !af::iszero(all_ref_cels(m, span)); // find all entries that are zeros
        af::array temp_hold = all_ref_cels(m, span);

        // Using "select" function - Runs on both CUDA and OpenCL
        af::array temp_all_ref_cels = select(notZeros, temp_hold, nan_array);

        // reorder to dimansions that make sense
        all_ref_cels = reorder(temp_all_ref_cels, 3, 1, 0, 2);
    }
_
Reply all
Reply to author
Forward
0 new messages