added autodetection of device number corresonding to preferrable device type (CPU|GPU)