Skip to content

[BUG] set_row() / assign_seq() panics if there is only 1 column #245

Closed
@sk4r

Description

@sk4r

Description

  • Details regarding the bug
    Attempting to set a row when there is only one column panics. I've reproduced consistently with arrayfire-rust 3.7 and latest master
  • Did you build ArrayFire yourself or did you use the official installers
    Installed community/arrayfire 3.7.2-1 in Arch Linux
  • Which backend is experiencing this issue? (CPU, CUDA, OpenCL)
    All
  • Do you have a workaround?
    No
  • Can the bug be reproduced reliably on your system?
    Yes
  • A clear and concise description of what you expected to happen.
    Setting a single row should succeed if there is 1 column in the array
  • Run your executable with AF_TRACE=all and AF_PRINT_ERRORS=1 environment
    variables set.
  • Screenshot or terminal output of the results from above run
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s
     Running `target/debug/af_row_set`
[unified][1599322631][022537] [ ../src/api/unified/symbol_manager.cpp:140 ] Attempting: Default System Paths
[unified][1599322631][022537] [ ../src/api/unified/symbol_manager.cpp:144 ] Found: libafcpu.so.3
[unified][1599322631][022537] [ ../src/api/unified/symbol_manager.cpp:151 ] Device Count: 1.
[unified][1599322631][022537] [ ../src/api/unified/symbol_manager.cpp:140 ] Attempting: Default System Paths
[unified][1599322631][022537] [ ../src/api/unified/symbol_manager.cpp:144 ] Found: libafopencl.so.3
[platform][1599322631][022537] [ ../src/backend/common/DependencyModule.cpp:99 ] Attempting to load: libforge.so
[platform][1599322631][022537] [ ../src/backend/common/DependencyModule.cpp:102 ] Found: libforge.so
[platform][1599322631][022537] [ ../src/backend/opencl/device_manager.cpp:218 ] Found 2 OpenCL platforms
[platform][1599322631][022537] [ ../src/backend/opencl/device_manager.cpp:229 ] Found 1 devices on platform NVIDIA CUDA
[platform][1599322631][022537] [ ../src/backend/opencl/device_manager.cpp:233 ] Found device GeForce RTX 2080 on platform NVIDIA CUDA
[platform][1599322631][022537] [ ../src/backend/opencl/device_manager.cpp:229 ] Found 0 devices on platform Clover
[platform][1599322631][022537] [ ../src/backend/opencl/device_manager.cpp:240 ] Found 1 OpenCL devices
[platform][1599322632][022537] [ ../src/backend/opencl/device_manager.cpp:335 ] Default device: 0
[unified][1599322632][022537] [ ../src/api/unified/symbol_manager.cpp:151 ] Device Count: 1.
[unified][1599322632][022537] [ ../src/api/unified/symbol_manager.cpp:140 ] Attempting: Default System Paths
[unified][1599322632][022537] [ ../src/api/unified/symbol_manager.cpp:144 ] Found: libafcuda.so.3
[unified][1599322632][022537] [ ../src/api/unified/symbol_manager.cpp:151 ] Device Count: 1.
[unified][1599322632][022537] [ ../src/api/unified/symbol_manager.cpp:206 ] AF_DEFAULT_BACKEND: cuda
[platform][1599322632][022537] [ ../src/backend/common/DependencyModule.cpp:99 ] Attempting to load: libforge.so
[platform][1599322632][022537] [ ../src/backend/common/DependencyModule.cpp:102 ] Found: libforge.so
[platform][1599322632][022537] [ ../src/backend/cuda/device_manager.cpp:427 ] CUDA Driver supports up to CUDA 11.0 ArrayFire CUDA Runtime 11.0
[platform][1599322632][022537] [ ../src/backend/cuda/device_manager.cpp:495 ] Found 1 CUDA devices
[platform][1599322632][022537] [ ../src/backend/cuda/device_manager.cpp:517 ] Found device: GeForce RTX 2080 (7.79 GB | ~10107.4 GFLOPs | 46 SMs)
[platform][1599322632][022537] [ ../src/backend/cuda/device_manager.cpp:556 ] AF_CUDA_DEFAULT_DEVICE:
[platform][1599322632][022537] [ ../src/backend/cuda/device_manager.cpp:574 ] Default device: 0(GeForce RTX 2080)
ArrayFire v3.7.2 (CUDA, 64-bit Linux, build default)
Platform: CUDA Runtime 11.0, Driver: 450.66
[0] GeForce RTX 2080, 7980 MB, CUDA Compute 7.5

[5 3 1 1]
[mem][1599322632][022537] [ ../src/backend/cuda/memory.cpp:158 ] nativeAlloc:    1 KB 0x7fa4ea000000
[mem][1599322632][022537] [ ../src/backend/cuda/memory.cpp:158 ] nativeAlloc:    1 KB 0x7fa4ea000400
[jit][1599322632][022537] [ ../src/backend/cuda/compile_module.cpp:429 ] {18389128331537752529           : loaded from /home/ak/.arrayfire/KER18389128331537752529_CU_75_AF_37.cubin for GeForce RTX 2080 }
[jit][1599322632][022537] [ ../src/backend/cuda/compile_module.cpp:429 ] {11230367656483596278           : loaded from /home/ak/.arrayfire/KER11230367656483596278_CU_75_AF_37.cubin for GeForce RTX 2080 }
    2.0000     2.0000     2.0000
    2.0000     2.0000     2.0000
    2.0000     2.0000     2.0000
    2.0000     2.0000     2.0000
    2.0000     2.0000     2.0000

[jit][1599322632][022537] [ ../src/backend/cuda/compile_module.cpp:429 ] {11856060716839361424           : loaded from /home/ak/.arrayfire/KER11856060716839361424_CU_75_AF_37.cubin for GeForce RTX 2080 }

[5 3 1 1]
[mem][1599322632][022537] [ ../src/backend/cuda/memory.cpp:158 ] nativeAlloc:    1 KB 0x7fa4ea000800
    2.0000     2.0000     2.0000
    1.0000     1.0000     1.0000
    1.0000     1.0000     1.0000
    1.0000     1.0000     1.0000
    2.0000     2.0000     2.0000


[5 2 1 1]
    2.0000     2.0000
    2.0000     2.0000
    2.0000     2.0000
    2.0000     2.0000
    2.0000     2.0000


[5 2 1 1]
    2.0000     2.0000
    1.0000     1.0000
    1.0000     1.0000
    1.0000     1.0000
    2.0000     2.0000


[5 1 1 1]
    2.0000
    2.0000
    2.0000
    2.0000
    2.0000

In function af_err af_assign_seq(void**, af_array, unsigned int, const af_seq*, af_array)
In file src/api/c/assign.cpp:184
Invalid dimension for argument 0
Expected: (outDims.ndims() >= (dim_t)ndims)
 0# 0x00007FA5283928EB in /usr/lib/libafcuda.so.3
 1# 0x000055EB81FBC09E in target/debug/af_row_set
 2# 0x000055EB81FBCD7F in target/debug/af_row_set
 3# 0x000055EB81FBCE14 in target/debug/af_row_set
 4# 0x000055EB81FBD34D in target/debug/af_row_set
 5# 0x000055EB81FD3963 in target/debug/af_row_set
 6# 0x000055EB81FBD317 in target/debug/af_row_set
 7# 0x000055EB81FBCE6A in target/debug/af_row_set
 8# __libc_start_main in /usr/lib/libc.so.6
 9# 0x000055EB81FBB17E in target/debug/af_row_set

thread 'main' panicked at 'Error message: Size is incorrect
Last error: In function af_err af_assign_seq(void**, af_array, unsigned int, const af_seq*, af_array)
In file src/api/c/assign.cpp:184
Invalid dimension for argument 0
Expected: (outDims.ndims() >= (dim_t)ndims)
 0# 0x00007FA5283928EB in /usr/lib/libafcuda.so.3
 1# 0x000055EB81FBC09E in target/debug/af_row_set
 2# 0x000055EB81FBCD7F in target/debug/af_row_set
 3# 0x000055EB81FBCE14 in target/debug/af_row_set
 4# 0x000055EB81FBD34D in target/debug/af_row_set
 5# 0x000055EB81FD3963 in target/debug/af_row_set
 6# 0x000055EB81FBD317 in target/debug/af_row_set
 7# 0x000055EB81FBCE6A in target/debug/af_row_set
 8# __libc_start_main in /usr/lib/libc.so.6
 9# 0x000055EB81FBB17E in target/debug/af_row_set
', /home/ak/.cargo/git/checkouts/arrayfire-rust-78c6296114c4c65d/39ab7a5/src/core/error.rs:37:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Reproducible Code and/or Steps

use arrayfire::*;

fn pick_backend() {
    let available = get_available_backends();
    if available.contains(&Backend::CUDA) {
        set_backend(Backend::CUDA);
    } else if available.contains(&Backend::OPENCL) {
        set_backend(Backend::OPENCL);
    } else if available.contains(&Backend::CPU) {
        set_backend(Backend::CPU);
    } else {
        panic!("unable to find a usable ArrayFire backend")
    }
    info();
}

// get the first row and set it back
fn get_and_set_row(num_columns: u64) {
    let dims = Dim4::new(&[2, num_columns, 1, 1]);
    let mut a = randu::<f32>(dims);
    print(&a);
    let r = row(&a, 0);
    print(&r);
    set_row(&mut a, &r, 0);
    print(&a);
}

// code from example at http://arrayfire.org/arrayfire-rust/arrayfire/book/indexing.html#using-seq-objects-to-index-array
fn set_with_assign_seq(num_columns: u64) {
    let mut a = constant(2.0 as f32, Dim4::new(&[5, num_columns, 1, 1]));
    let b = constant(1.0 as f32, Dim4::new(&[3, num_columns, 1, 1]));
    let seqs = &[Seq::new(1.0, 3.0, 1.0), Seq::default()];
    print(&a);
    assign_seq(&mut a, seqs, &b);
    print(&a);
}

fn main() -> std::io::Result<()> {
    pick_backend();

    // works as expected
    set_with_assign_seq(3);
    set_with_assign_seq(2);
    // panics
    set_with_assign_seq(1);

    // works as expected
    get_and_set_row(2);
    // panics
    get_and_set_row(1);

    Ok(())
}

System Information

Please provide the following information:

  1. ArrayFire version
    3.7.2
  2. Devices installed on the system
    • GeForce RTX 2080
    • AMD Ryzen 7 2700X Eight-Core Processor
  3. (optional) Output from the af::info() function if applicable.
  4. Output from the following scripts:
name, memory.total [MiB], driver_version
GeForce RTX 2080, 7979 MiB, 450.66

rocm-smi not found.

$ clinfo
Number of platforms                               2
  Platform Name                                   NVIDIA CUDA
  Platform Vendor                                 NVIDIA Corporation
  Platform Version                                OpenCL 1.2 CUDA 11.0.228
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics
  Platform Extensions function suffix             NV

  Platform Name                                   Clover
  Platform Vendor                                 Mesa
  Platform Version                                OpenCL 1.1 Mesa 20.1.6
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd
  Platform Extensions function suffix             MESA

  Platform Name                                   NVIDIA CUDA
Number of devices                                 1
  Device Name                                     GeForce RTX 2080
  Device Vendor                                   NVIDIA Corporation
  Device Vendor ID                                0x10de
  Device Version                                  OpenCL 1.2 CUDA
  Driver Version                                  450.66
  Device OpenCL C Version                         OpenCL C 1.2
  Device Type                                     GPU
  Device Topology (NV)                            PCI-E, 08:00.0
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               46
  Max clock frequency                             1800MHz
  Compute Capability (NV)                         7.5
  Device Partition                                (core)
    Max number of sub-devices                     1
    Supported partition types                     None
    Supported affinity domains                    (n/a)
  Max work item dimensions                        3
  Max work item sizes                             1024x1024x64
  Max work group size                             1024
  Preferred work group size multiple              32
  Warp size (NV)                                  32
  Preferred / native vector sizes
    char                                                 1 / 1
    short                                                1 / 1
    int                                                  1 / 1
    long                                                 1 / 1
    half                                                 0 / 0        (n/a)
    float                                                1 / 1
    double                                               1 / 1        (cl_khr_fp64)
  Half-precision Floating-point support           (n/a)
  Single-precision Floating-point support         (core)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  Yes
  Double-precision Floating-point support         (cl_khr_fp64)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
  Address bits                                    64, Little-Endian
  Global memory size                              8366784512 (7.792GiB)
  Error Correction support                        No
  Max memory allocation                           2091696128 (1.948GiB)
  Unified memory for Host and Device              No
  Integrated memory (NV)                          No
  Minimum alignment for any data type             128 bytes
  Alignment of base address                       4096 bits (512 bytes)
  Global Memory cache type                        Read/Write
  Global Memory cache size                        1507328 (1.438MiB)
  Global Memory cache line size                   128 bytes
  Image support                                   Yes
    Max number of samplers per kernel             32
    Max size for 1D images from buffer            268435456 pixels
    Max 1D or 2D image array size                 2048 images
    Max 2D image size                             32768x32768 pixels
    Max 3D image size                             16384x16384x16384 pixels
    Max number of read image args                 256
    Max number of write image args                32
  Local memory type                               Local
  Local memory size                               49152 (48KiB)
  Registers per block (NV)                        65536
  Max number of constant args                     9
  Max constant buffer size                        65536 (64KiB)
  Max size of kernel argument                     4352 (4.25KiB)
  Queue properties
    Out-of-order execution                        Yes
    Profiling                                     Yes
  Prefer user sync for interop                    No
  Profiling timer resolution                      1000ns
  Execution capabilities
    Run OpenCL kernels                            Yes
    Run native kernels                            No
    Kernel execution timeout (NV)                 Yes
  Concurrent copy and kernel execution (NV)       Yes
    Number of async copy engines                  3
  printf() buffer size                            1048576 (1024KiB)
  Built-in kernels                                (n/a)
  Device Extensions                               cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics

  Platform Name                                   Clover
Number of devices                                 0

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  No platform
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   No platform
  clCreateContext(NULL, ...) [default]            No platform
  clCreateContext(NULL, ...) [other]              Success [NV]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  Invalid device type for platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  No platform

Checklist

  • Using the latest available ArrayFire release
  • GPU drivers are up to date

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions