arrayfire / arrayfire-rust

Rust wrapper for ArrayFire
BSD 3-Clause "New" or "Revised" License
813 stars 57 forks source link

Crash on exit with code 3221225477 #106

Closed kenniskoldewyn closed 7 years ago

kenniskoldewyn commented 7 years ago

I've followed the installation instructions to the letter as per https://github.com/arrayfire/arrayfire-rust when installing on Windows 10 x64: installed the x86_64-pc-windows-msvc version of Rust 1.15.1, installed the ArrayFire binaries, set up the AF_PATH and PATH environment variables, and added arrayfire = "3.4.1" to my Cargo.toml file. Unfortunately, any attempt to use ArrayFile crashes on exit with code 3221225477. For example, if my code is:

extern crate arrayfire;
use arrayfire as af;

fn main() {
    let dims = af::Dim4::new(&[3, 5, 1, 1]);
    let a = af::randu::<f32>(dims);
    af::print(&a);
}

Then executing produces the following output:

     Running `target\debug\example.exe`

[3 5 1 1]
    0.3990     0.1386     0.3932     0.1587     0.7089
    0.6720     0.7353     0.2706     0.8831     0.9434
    0.5339     0.5160     0.9455     0.0621     0.1227

error: process didn't exit successfully: `target\debug\example.exe` (exit code: 3221225477)

I'm guessing that there's something strange about my environment. For example, I used to have Visual Studio Community 2015 installed, but I got rid of it when I started trying to use ArrayFire in Rust (with Emacs as IDE, not Visual Studio). Any ideas on how to track this weirdness down? Here's the full results of cargo run -vv in case that helps any:

c:\Users\kennis\Dropbox\Programming\Projects\example>cargo run -vv
   Compiling rustc-serialize v0.3.22
   Compiling semver v0.1.20
   Compiling lazy_static v0.2.2
   Compiling num-traits v0.1.36
     Running `rustc --crate-name rustc_serialize C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\rustc-serialize-0.3.22\src\lib.rs --crate-type lib -g -C metadata=03b62901d97343ea -C extra-filename=-03b62901d97343ea --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps`
     Running `rustc --crate-name semver C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\semver-0.1.20\src\lib.rs --crate-type lib -g -C metadata=dad6bdfe0e69f878 -C extra-filename=-dad6bdfe0e69f878 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps`
     Running `rustc --crate-name lazy_static C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-0.2.2\src\lib.rs --crate-type lib -g -C metadata=13daae1d9a07c252 -C extra-filename=-13daae1d9a07c252 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps`
     Running `rustc --crate-name num_traits C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-traits-0.1.36\src\lib.rs --crate-type lib -g -C metadata=ba977ae2944b0245 -C extra-filename=-ba977ae2944b0245 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps`
   Compiling libc v0.2.20
     Running `rustc --crate-name libc C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.20\src\lib.rs --crate-type lib -g --cfg "feature=\"use_std\"" --cfg "feature=\"default\"" -C metadata=83c2bd88b43ecde3 -C extra-filename=-83c2bd88b43ecde3 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps`
   Compiling rand v0.3.15
     Running `rustc --crate-name rand C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\rand-0.3.15\src\lib.rs --crate-type lib -g -C metadata=26cfd8d095643d5f -C extra-filename=-26cfd8d095643d5f --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern libc=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\liblibc-83c2bd88b43ecde3.rlib`
warning: patterns aren't allowed in methods without bodies, #[warn(patterns_in_fns_without_body)] on by default
   --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-traits-0.1.36\src\int.rs:277:18
    |
   Compiling rustc_version v0.1.7
277     Running `rustc --crate-name rustc_version C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\rustc_version-0.1.7\src\lib.rs --crate-type lib -g -C metadata=990a3fd610d67d6c -C extra-filename=-990a3fd610d67d6c --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern semver=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libsemver-dad6bdfe0e69f878.rlib`
 |     fn pow(self, mut exp: u32) -> Self;
    |                  ^^^^^^^
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>

   Compiling num-integer v0.1.32
     Running `rustc --crate-name num_integer C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-integer-0.1.32\src\lib.rs --crate-type lib -g -C metadata=4c819e48d5fcce89 -C extra-filename=-4c819e48d5fcce89 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern num_traits=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_traits-ba977ae2944b0245.rlib`
   Compiling num-iter v0.1.32
     Running `rustc --crate-name num_iter C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-iter-0.1.32\src\lib.rs --crate-type lib -g -C metadata=a08cc27ee32e82a2 -C extra-filename=-a08cc27ee32e82a2 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern num_integer=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_integer-4c819e48d5fcce89.rlib --extern num_traits=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_traits-ba977ae2944b0245.rlib`
   Compiling num-complex v0.1.35
   Compiling arrayfire v3.4.1
   Compiling num-bigint v0.1.35
     Running `rustc --crate-name num_complex C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-complex-0.1.35\src\lib.rs --crate-type lib -g --cfg "feature=\"rustc-serialize\"" --cfg "feature=\"default\"" -C metadata=997460ed3f3b74aa -C extra-filename=-997460ed3f3b74aa --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern num_traits=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_traits-ba977ae2944b0245.rlib --extern rustc_serialize=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\librustc_serialize-03b62901d97343ea.rlib`
     Running `rustc --crate-name build_script_build C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\build.rs --crate-type bin -g -C metadata=f9b9680006fb1743 -C extra-filename=-f9b9680006fb1743 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\build\arrayfire-f9b9680006fb1743 --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern rustc_serialize=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\librustc_serialize-03b62901d97343ea.rlib --extern rustc_version=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\librustc_version-990a3fd610d67d6c.rlib`
     Running `rustc --crate-name num_bigint C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-bigint-0.1.35\src\lib.rs --crate-type lib -g --cfg "feature=\"rand\"" --cfg "feature=\"default\"" --cfg "feature=\"rustc-serialize\"" -C metadata=ab518bd16dd376c5 -C extra-filename=-ab518bd16dd376c5 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern rustc_serialize=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\librustc_serialize-03b62901d97343ea.rlib --extern num_integer=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_integer-4c819e48d5fcce89.rlib --extern num_traits=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_traits-ba977ae2944b0245.rlib --extern rand=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\librand-26cfd8d095643d5f.rlib`
     Running `c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\build\arrayfire-f9b9680006fb1743\build-script-build`
cargo:rustc-link-lib=dylib=af
cargo:rustc-link-search=native=C:\Program Files\ArrayFire\v3\lib
cargo:rustc-cfg=op_assign
   Compiling num-rational v0.1.35
     Running `rustc --crate-name num_rational C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-rational-0.1.35\src\lib.rs --crate-type lib -g --cfg "feature=\"default\"" --cfg "feature=\"num-bigint\"" --cfg "feature=\"bigint\"" --cfg "feature=\"rustc-serialize\"" -C metadata=d0b5e68d571128ad -C extra-filename=-d0b5e68d571128ad --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern num_bigint=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_bigint-ab518bd16dd376c5.rlib --extern rustc_serialize=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\librustc_serialize-03b62901d97343ea.rlib --extern num_integer=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_integer-4c819e48d5fcce89.rlib --extern num_traits=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_traits-ba977ae2944b0245.rlib`
   Compiling num v0.1.36
     Running `rustc --crate-name num C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\num-0.1.36\src\lib.rs --crate-type lib -g --cfg "feature=\"complex\"" --cfg "feature=\"default\"" --cfg "feature=\"num-rational\"" --cfg "feature=\"rustc-serialize\"" --cfg "feature=\"bigint\"" --cfg "feature=\"num-bigint\"" --cfg "feature=\"num-complex\"" --cfg "feature=\"rational\"" -C metadata=8e9b9597520b1b0d -C extra-filename=-8e9b9597520b1b0d --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern num_rational=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_rational-d0b5e68d571128ad.rlib --extern num_iter=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_iter-a08cc27ee32e82a2.rlib --extern num_bigint=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_bigint-ab518bd16dd376c5.rlib --extern num_traits=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_traits-ba977ae2944b0245.rlib --extern num_integer=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_integer-4c819e48d5fcce89.rlib --extern num_complex=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum_complex-997460ed3f3b74aa.rlib`
     Running `rustc --crate-name arrayfire C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src/lib.rs --crate-type lib -g -C metadata=1477eabfdf091f86 -C extra-filename=-1477eabfdf091f86 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern lazy_static=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\liblazy_static-13daae1d9a07c252.rlib --extern num=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libnum-8e9b9597520b1b0d.rlib --extern libc=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\liblibc-83c2bd88b43ecde3.rlib -L "native=C:\Program Files\ArrayFire\v3\lib" --cfg op_assign -l dylib=af`
warning: type alias is never used: `MutDouble`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\array.rs:11:1
   |
11 | type MutDouble  = *mut self::libc::c_double;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `MutUint`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\array.rs:12:1
   |
12 | type MutUint    = *mut self::libc::c_uint;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `VoidPtr`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\array.rs:16:1
   |
16 | type VoidPtr    = self::libc::c_ulonglong;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `MutDouble`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\arith/mod.rs:17:1
   |
17 | type MutDouble  = *mut self::libc::c_double;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `MutUint`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\arith/mod.rs:18:1
   |
18 | type MutUint    = *mut self::libc::c_uint;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `MutDouble`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\data/mod.rs:14:1
   |
14 | type MutDouble  = *mut self::libc::c_double;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `MutUint`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\data/mod.rs:15:1
   |
15 | type MutUint    = *mut self::libc::c_uint;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `AfArray`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\random/mod.rs:11:1
   |
11 | type AfArray    = self::libc::c_longlong;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: type alias is never used: `Intl`, #[warn(dead_code)] on by default
  --> C:\Users\kennis\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayfire-3.4.1\src\random/mod.rs:15:1
   |
15 | type Intl    = self::libc::c_longlong;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   Compiling example v0.1.0 (file:///C:/Users/kennis/Dropbox/Programming/Projects/example)
     Running `rustc --crate-name example src\main.rs --crate-type bin -g -C metadata=7ec7f7ef32a23851 -C extra-filename=-7ec7f7ef32a23851 --out-dir c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --emit=dep-info,link -L dependency=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps --extern arrayfire=c:\Users\kennis\Dropbox\Programming\Projects\example\target\debug\deps\libarrayfire-1477eabfdf091f86.rlib -L "native=C:\Program Files\ArrayFire\v3\lib"`
    Finished debug [unoptimized + debuginfo] target(s) in 37.31 secs
     Running `target\debug\example.exe`

[3 5 1 1]
    0.3990     0.1386     0.3932     0.1587     0.7089
    0.6720     0.7353     0.2706     0.8831     0.9434
    0.5339     0.5160     0.9455     0.0621     0.1227

error: process didn't exit successfully: `target\debug\example.exe` (exit code: 3221225477)
9prady9 commented 7 years ago

@kenniskoldewyn Can you post the output of af_info call. Since it is crashing at end of program, you can do this prior to printing the array.

kenniskoldewyn commented 7 years ago

Interestingly, when I tried to add the call to af::info() at the end of my existing example program, the crash happened before info produced any output (which could be a buffering issue, I suppose). So I put it at the beginning of the program, and it produced the following (afterwards printing the random array, as before):

ArrayFire v3.4.2 (OpenCL, 64-bit Windows, build 2da9967)
[0] INTEL   : Intel(R) HD Graphics, 1374 MB
-1- INTEL   : Intel(R) Pentium(R) CPU  N3540  @ 2.16GHz, 8075 MB

I note that the version of ArrayFire doesn't match the dependency in my Cargo.toml file, but when I set it to arrayfire = "3.4.2", then cargo tells me it can't find a matching version: versions found: 3.4.1, 3.4.0, 3.3.2, .... Should I be looking to download and install the 3.4.1 version of ArrayFire to match the latest available arrayfire crate?

9prady9 commented 7 years ago

We re versioning the rust crate by matching Major.Minor of ArrayFire releases with Major.Minor of crate. Fix release versions doesn't need to match.

ArrayFire Upstream Rust Crate
3.3.x 3.3.x
3.4.x 3.4.x
kenniskoldewyn commented 7 years ago

Indeed, before I saw your reply, I figured I'd give it a shot, and sure enough, downgrading ArrayFire to 3.4.1 and recompiling did not fix the problem.

9prady9 commented 7 years ago

@kenniskoldewyn Does it crash even when you run the example on CPU (device 1) ?

You can set the device in code set_device(1).

kenniskoldewyn commented 7 years ago

Ah ha, in that case there's no crash. I've experimented a bit with placing set_device(1) in my code, and it looks like I can still use device 0 as long as I also use device 1 somewhere. So, for example, both of the following programs do not crash:

fn main() {
    af::set_device(0);
    let a = af::randu::<f32>(af::Dim4::new(&[3, 5, 1, 1]));
    af::print(&a);
    af::set_device(1);
    let b = af::randu::<f32>(af::Dim4::new(&[3, 5, 1, 1]));
    af::print(&b);
}
fn main() {
    af::set_device(1);
    let b = af::randu::<f32>(af::Dim4::new(&[3, 5, 1, 1]));
    af::print(&b);
    af::set_device(0);
    let a = af::randu::<f32>(af::Dim4::new(&[3, 5, 1, 1]));
    af::print(&a);
}

But this one (where I set the device to 1, but don't actually allocate anything on it) does crash:

fn main() {
    af::set_device(0);
    let a = af::randu::<f32>(af::Dim4::new(&[3, 5, 1, 1]));
    af::print(&a);
    af::set_device(1);
//    let b = af::randu::<f32>(af::Dim4::new(&[3, 5, 1, 1]));
//    af::print(&b);
}

I suppose if I benchmark and decide that I want to use device 0 for most of my work that I can also do something innocuous with device 1 to keep the program from crashing, but that seems like a workaround I shouldn't have to do. I've jumped in to using ArrayFire without doing much reading, so perhaps I'm not using it correctly. Is this expected behavior?

9prady9 commented 7 years ago

@kenniskoldewyn You don't need to do anything of that sort in theory. But the fact that it is happening is weird. Can you please try the similar example (given below) in C++ code ?

#include <arrayfire.h>

int main(void)
{
    af::setDevice(0);
    af::array a = af::randu(af::dim4(3, 5));
    af_print(a);
    af::setDevice(1);

    return 0;
}
kenniskoldewyn commented 7 years ago

Yes, I'm getting the same result from the C++ program—it crashes on exit if the allocation is done on device 0, but not if it is done on device 1.

9prady9 commented 7 years ago

Can you run the debugger on C++ executable to find out where the code is crashing ?

kenniskoldewyn commented 7 years ago

Here's what WinDBG shows me:


Microsoft (R) Windows Debugger Version 10.0.10240.9 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: C:\Users\kennis\example\example.exe

************* Symbol Path validation summary **************
Response                         Time (ms)     Location
OK                                             C:\Program Files\ArrayFire\v3\lib
Symbol search path is: C:\Program Files\ArrayFire\v3\lib
Executable search path is: 
ModLoad: 00007ff6`e9c80000 00007ff6`e9c9c000   image00007ff6`e9c80000
ModLoad: 00007ffa`0e100000 00007ffa`0e2d1000   ntdll.dll
ModLoad: 00007ffa`0bed0000 00007ffa`0bf7b000   C:\WINDOWS\System32\KERNEL32.DLL
ModLoad: 00007ffa`0a7c0000 00007ffa`0a9dd000   C:\WINDOWS\System32\KERNELBASE.dll
ModLoad: 00007ff9`e03c0000 00007ff9`e0671000   C:\Users\kennis\example\af.dll
ModLoad: 00007ff9`e4fc0000 00007ff9`e5066000   C:\WINDOWS\SYSTEM32\MSVCP120.dll
ModLoad: 00007ff9`e0c70000 00007ff9`e0d5f000   C:\WINDOWS\SYSTEM32\MSVCR120.dll
(16fc.2160): Break instruction exception - code 80000003 (first chance)
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll - 
ntdll!LdrInitShimEngineDynamic+0x360:
00007ffa`0e1d34e0 cc              int     3
0:000> g
ModLoad: 00007ff9`ca080000 00007ff9`cd506000   C:\Users\kennis\example\afcpu.dll
ModLoad: 00007ff9`e63a0000 00007ff9`e64c3000   C:\WINDOWS\SYSTEM32\OPENGL32.dll
ModLoad: 00007ff9`c86b0000 00007ff9`c92c9000   C:\Users\kennis\example\forge.dll
ModLoad: 00007ff9`c92d0000 00007ff9`ca072000   C:\Users\kennis\example\mkl_rt.dll
ModLoad: 00007ffa`0dda0000 00007ffa`0de0a000   C:\WINDOWS\System32\WS2_32.dll
ModLoad: 00007ff9`f4330000 00007ff9`f4352000   C:\WINDOWS\SYSTEM32\VCOMP120.DLL
ModLoad: 00007ffa`0c2e0000 00007ffa`0c339000   C:\WINDOWS\System32\sechost.dll
ModLoad: 00007ffa`0da20000 00007ffa`0db85000   C:\WINDOWS\System32\USER32.dll
ModLoad: 00007ffa`0dd00000 00007ffa`0dd9e000   C:\WINDOWS\System32\msvcrt.dll
ModLoad: 00007ffa`0aae0000 00007ffa`0aafe000   C:\WINDOWS\System32\win32u.dll
ModLoad: 00007ffa`0de10000 00007ffa`0de44000   C:\WINDOWS\System32\GDI32.dll
ModLoad: 00007ffa`0c350000 00007ffa`0c471000   C:\WINDOWS\System32\RPCRT4.dll
ModLoad: 00007ffa`0b690000 00007ffa`0b732000   C:\WINDOWS\System32\ADVAPI32.dll
ModLoad: 00007ffa`0b2a0000 00007ffa`0b422000   C:\WINDOWS\System32\gdi32full.dll
ModLoad: 00007ffa`0c480000 00007ffa`0d989000   C:\WINDOWS\System32\SHELL32.dll
ModLoad: 00007ffa`0ab00000 00007ffa`0ab42000   C:\WINDOWS\System32\cfgmgr32.dll
ModLoad: 00007ff9`e6370000 00007ff9`e639d000   C:\WINDOWS\SYSTEM32\GLU32.dll
ModLoad: 00007ff9`e5fe0000 00007ff9`e60d7000   C:\WINDOWS\SYSTEM32\DDRAW.dll
ModLoad: 00007ffa`0abc0000 00007ffa`0b29a000   C:\WINDOWS\System32\windows.storage.dll
ModLoad: 00007ffa`0c010000 00007ffa`0c2d8000   C:\WINDOWS\System32\combase.dll
ModLoad: 00007ff9`e9710000 00007ff9`e9718000   C:\WINDOWS\SYSTEM32\DCIMAN32.dll
ModLoad: 00007ffa`0a9e0000 00007ffa`0aad5000   C:\WINDOWS\System32\ucrtbase.dll
ModLoad: 00007ffa`0ab50000 00007ffa`0abba000   C:\WINDOWS\System32\bcryptPrimitives.dll
ModLoad: 00007ffa`0a580000 00007ffa`0a5cc000   C:\WINDOWS\System32\powrprof.dll
ModLoad: 00007ffa`0d9c0000 00007ffa`0da12000   C:\WINDOWS\System32\shlwapi.dll
ModLoad: 00007ffa`0a5e0000 00007ffa`0a5ef000   C:\WINDOWS\System32\kernel.appcore.dll
ModLoad: 00007ffa`0b4d0000 00007ffa`0b579000   C:\WINDOWS\System32\shcore.dll
ModLoad: 00007ffa`0a560000 00007ffa`0a574000   C:\WINDOWS\System32\profapi.dll
ModLoad: 00007ffa`0d990000 00007ffa`0d9be000   C:\WINDOWS\System32\IMM32.DLL
ModLoad: 00007ff9`c3e40000 00007ff9`c86a9000   C:\Users\kennis\example\afopencl.dll
ModLoad: 00007ff9`f23a0000 00007ff9`f23b5000   C:\WINDOWS\SYSTEM32\OpenCL.dll
ModLoad: 00007ff9`9a1c0000 00007ff9`c3e39000   C:\Users\kennis\example\afcuda.dll
ModLoad: 00007ff9`9a1c0000 00007ff9`c3e39000   C:\Program Files\ArrayFire\v3\lib\afcuda.dll
ModLoad: 00007ff9`ebfd0000 00007ff9`ec032000   C:\WINDOWS\SYSTEM32\IntelOpenCL64.dll
ModLoad: 00007ff9`d7910000 00007ff9`d7a0d000   C:\Program Files (x86)\Common Files\Intel\OpenCL\bin\x64\intelocl64.dll
ModLoad: 00007ff9`e5ce0000 00007ff9`e5d56000   C:\Program Files (x86)\Common Files\Intel\OpenCL\bin\x64\task_executor64.dll
ModLoad: 00007ffa`09910000 00007ffa`09942000   C:\WINDOWS\SYSTEM32\ntmarta.dll
ModLoad: 00007ff9`e4320000 00007ff9`e43b5000   C:\Program Files (x86)\Common Files\Intel\OpenCL\bin\x64\cpu_device64.dll
ModLoad: 00007ffa`015f0000 00007ffa`015fa000   C:\WINDOWS\SYSTEM32\VERSION.dll
ModLoad: 00007ff9`e7580000 00007ff9`e75e9000   C:\Program Files (x86)\Common Files\Intel\OpenCL\bin\x64\tbb\tbb.dll
ModLoad: 00007ff9`d62f0000 00007ff9`d64e4000   C:\WINDOWS\SYSTEM32\igdrcl64.dll
ModLoad: 00007ffa`094f0000 00007ffa`0958f000   C:\WINDOWS\SYSTEM32\dxgi.dll
ModLoad: 00007ffa`091d0000 00007ffa`091eb000   C:\WINDOWS\SYSTEM32\resourcepolicyclient.dll
ModLoad: 00007ff9`c2850000 00007ff9`c3e32000   C:\WINDOWS\SYSTEM32\igdfcl64.dll
ModLoad: 00007ffa`06e50000 00007ffa`06fe2000   C:\WINDOWS\SYSTEM32\dbghelp.dll
ModLoad: 00007ff9`e7040000 00007ff9`e709f000   C:\WINDOWS\SYSTEM32\igdbcl64.dll
ModLoad: 00007ffa`05bd0000 00007ffa`06034000   C:\WINDOWS\SYSTEM32\igdusc64.dll
ModLoad: 00007ff9`e6610000 00007ff9`e6658000   C:\Program Files (x86)\Common Files\Intel\OpenCL\bin\x64\tbb\tbbmalloc.dll
ModLoad: 00007ff9`c1f80000 00007ff9`c2844000   C:\Program Files (x86)\Common Files\Intel\OpenCL\bin\x64\OclCpuBackEnd64.dll
ModLoad: 00000001`80000000 00000001`805d4000   C:\Program Files (x86)\Common Files\Intel\OpenCL\bin\x64\__ocl_svml_h8.dll
ModLoad: 00007ffa`08cf0000 00007ffa`08d85000   C:\WINDOWS\system32\uxtheme.dll
ModLoad: 00007ffa`08480000 00007ffa`084a3000   C:\WINDOWS\SYSTEM32\winmm.dll
ModLoad: 00000247`474b0000 00000247`474db000   C:\WINDOWS\SYSTEM32\winmmbase.dll
ModLoad: 00007ffa`08450000 00007ffa`0847b000   C:\WINDOWS\SYSTEM32\winmmbase.dll
ModLoad: 00000247`4aaf0000 00000247`4ab1b000   C:\WINDOWS\SYSTEM32\WINMMBASE.dll
ModLoad: 00007ffa`08260000 00007ffa`08286000   C:\WINDOWS\SYSTEM32\dwmapi.dll
ModLoad: 00007ffa`0dba0000 00007ffa`0dcfb000   C:\WINDOWS\System32\MSCTF.dll
ModLoad: 00007ffa`0bd10000 00007ffa`0bdcf000   C:\WINDOWS\System32\OLEAUT32.dll
ModLoad: 00007ffa`0b430000 00007ffa`0b4cc000   C:\WINDOWS\System32\msvcp_win.dll
ModLoad: 00007ff9`ec870000 00007ff9`ec908000   C:\Program Files\Common Files\microsoft shared\ink\tiptsf.dll
ModLoad: 00007ff9`c1740000 00007ff9`c1f72000   C:\WINDOWS\SYSTEM32\ig7icd64.dll
ModLoad: 00007ffa`07fc0000 00007ffa`07fd3000   C:\WINDOWS\SYSTEM32\WTSAPI32.dll
(16fc.2160): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\SYSTEM32\igdrcl64.dll - 
ntdll!RtlEnterCriticalSection+0xd:
00007ffa`0e130bdd f00fba710800    lock btr dword ptr [rcx+8],0 ds:00000000`00000018=????????

Let me know if Visual Studio would be expected to give me more useful debugging information, and I'll reinstall it and debug it from there.

9prady9 commented 7 years ago

@kenniskoldewyn I was expecting to see the back trace of the program execution when it fails, so that we can find out which function or upstream library call is causing the failure. Could you put a break point at the last statement in your code and step through the code from there ?

kenniskoldewyn commented 7 years ago

Sorry for the delay. It turns out that things are a bit more complicated than I first realized. At first, I had only installed the Microsoft Visual C++ Build Tools 2015 (the minimum required for a successful Rust installation on Windows), and I was compiling and debugging the crashing C++ example using those tools. However, I was a novice at using WinDBG, so when you wanted the full stack trace I installed Visual Studio Community 2015, and when I compiled and ran the C++ example from within Visual Studio, it did not crash.

So I've beefed up my WinDBG skills, and here is the stack trace from the crashing C++ application:

 # Child-SP          RetAddr           Call Site
00 00000016`f68ff320 00007fff`0f466522 ntdll!RtlEnterCriticalSection+0xd
01 00000016`f68ff350 00007fff`0f45f3dd igdrcl64!clSetCommandQueueProperty+0x1df2
02 00000016`f68ff380 00007ffe`fdc19a49 igdrcl64!clReleaseMemObject+0x2d
03 00000016`f68ff3b0 00007ffe`fd8a8dc1 afopencl!opencl::MemoryManager::nativeFree+0x39 [c:\workspace\graphics-inst-src\src\backend\opencl\memory.cpp @ 108]
04 00000016`f68ff960 00007ffe`fdc17e73 afopencl!common::MemoryManager::garbageCollect+0xb1 [c:\workspace\graphics-inst-src\src\backend\memorymanager.cpp @ 85]
05 00000016`f68ff9e0 00007ffe`ff280a94 afopencl!opencl::MemoryManager::~MemoryManager+0x63 [c:\workspace\graphics-inst-src\src\backend\opencl\memory.cpp @ 43]
06 00000016`f68ffa20 00007ffe`ff280d16 afopencl!_CRT_INIT+0xec [f:\dd\vctools\crt\crtw32\dllstuff\crtdll.c @ 416]
07 00000016`f68ffa60 00007fff`4ab1a35f afopencl!__DllMainCRTStartup+0xe2 [f:\dd\vctools\crt\crtw32\dllstuff\crtdll.c @ 522]
08 00000016`f68ffaa0 00007fff`4aaf806b ntdll!RtlDeactivateActivationContextUnsafeFast+0x1bf
09 00000016`f68ffb00 00007fff`4aaf7d94 ntdll!LdrShutdownProcess+0x14b
0a 00000016`f68ffc10 00007fff`4892ce6a ntdll!RtlExitUserProcess+0xb4
0b 00000016`f68ffc40 00007ff7`01fb5960 KERNEL32!ExitProcess+0xa
0c 00000016`f68ffc70 00007ff7`01fb58fc image00007ff7_01fb0000+0x5960
0d 00000016`f68ffca0 00007ff7`01fb13fb image00007ff7_01fb0000+0x58fc
0e 00000016`f68ffcd0 00007fff`48918364 image00007ff7_01fb0000+0x13fb
0f 00000016`f68ffd10 00007fff`4ab570d1 KERNEL32!BaseThreadInitThunk+0x14
10 00000016`f68ffd40 00000000`00000000 ntdll!RtlUserThreadStart+0x21

I can also use WinDBG to get a stack trace from the crashing Rust program, and it looks pretty much exactly the same:

 # Child-SP          RetAddr           Call Site
00 0000002c`ff91f440 00007fff`0f466522 ntdll!RtlEnterCriticalSection+0xd
01 0000002c`ff91f470 00007fff`0f45f3dd igdrcl64!clSetCommandQueueProperty+0x1df2
No .natvis files found at c:\Program Files (x86)\Windows Kits\10\Debuggers\x64\Visualizers.
02 0000002c`ff91f4a0 00007ffe`fdc19a49 igdrcl64!clReleaseMemObject+0x2d
03 0000002c`ff91f4d0 00007ffe`fd8a8dc1 afopencl!opencl::MemoryManager::nativeFree+0x39 [c:\workspace\graphics-inst-src\src\backend\opencl\memory.cpp @ 108]
04 0000002c`ff91fa80 00007ffe`fdc17e73 afopencl!common::MemoryManager::garbageCollect+0xb1 [c:\workspace\graphics-inst-src\src\backend\memorymanager.cpp @ 85]
05 0000002c`ff91fb00 00007ffe`ff280a94 afopencl!opencl::MemoryManager::~MemoryManager+0x63 [c:\workspace\graphics-inst-src\src\backend\opencl\memory.cpp @ 43]
06 0000002c`ff91fb40 00007ffe`ff280d16 afopencl!_CRT_INIT+0xec [f:\dd\vctools\crt\crtw32\dllstuff\crtdll.c @ 416]
07 0000002c`ff91fb80 00007fff`4ab1a35f afopencl!__DllMainCRTStartup+0xe2 [f:\dd\vctools\crt\crtw32\dllstuff\crtdll.c @ 522]
08 0000002c`ff91fbc0 00007fff`4aaf806b ntdll!RtlDeactivateActivationContextUnsafeFast+0x1bf
09 0000002c`ff91fc20 00007fff`4aaf7d94 ntdll!LdrShutdownProcess+0x14b
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\System32\KERNEL32.DLL - 
0a 0000002c`ff91fd30 00007fff`4892ce6a ntdll!RtlExitUserProcess+0xb4
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\System32\ucrtbase.dll - 
0b 0000002c`ff91fd60 00007fff`4717694d KERNEL32!ExitProcess+0xa
0c 0000002c`ff91fd90 00007fff`471768df ucrtbase!exit+0xed
*** WARNING: Unable to verify checksum for example-7ec7f7ef32a23851.exe
0d 0000002c`ff91fdc0 00007ff6`029b3a3f ucrtbase!exit+0x7f
0e 0000002c`ff91fe10 00007fff`48918364 example_7ec7f7ef32a23851!__scrt_common_main_seh+0x12f [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 262]
0f 0000002c`ff91fe50 00007fff`4ab570d1 KERNEL32!BaseThreadInitThunk+0x14
10 0000002c`ff91fe80 00000000`00000000 ntdll!RtlUserThreadStart+0x21

Why would the C++ application crash when I compile it with the Microsoft Visual C++ Build Tools 2015, but not when I compile it with Visual Studio Community 2015? If we can figure that out, then we will likely have figured out why the Rust application is crashing as well.

9prady9 commented 7 years ago

Both the stack traces terminate while releasing a cl_mem object - called from the destructor call of memory manager. I am not sure what is happening if you use build tools, may be some sort of difference in compiler flags ? Or You can find out if there is any dll dependency mismatch from executable generated by build tools and Visual Studio 2015, that can help you see if there is anything special going while using VS 2015.

kenniskoldewyn commented 7 years ago

Sorry for the delay. Once again, I have made a mistake in understanding the situation. I discovered that when running the example program from Visual Studio, I was using the default "solution platform" of CPU_x64. When running that way, there's only one device available to ArrayFire, and it's the CPU, where everything works fine. However, when I run the example program in Visual Studio using the OpenCL_x64 solution platform, it crashes exactly the same way it did with the build tools and with Rust. This is helpful—it means that I have reproducible crash behavior regardless of how I try to use ArrayFire, whether through C++ or Rust, and whether via the build tools, or via Visual Studio.

Since this is not a problem with arrayfire-rust, would you like me to re-open this issue in the arrayfire issues collection (https://github.com/arrayfire/arrayfire/issues)?

9prady9 commented 7 years ago

@kenniskoldewyn Sure, you are welcome to open one. However, at this point i am inclined to believe that it is an issue in Intel OpenCL driver. If that is the case, it can't be fixed in ArrayFire code base.

kenniskoldewyn commented 7 years ago

Based on the stack traces and my experimenting with uninstalling and reinstalling the Intel OpenCL driver, I believe you are correct, so I'm closing this issue. Thank you very much for your help!