{"action":"opened","issue":{"url":"https://api.github.com/repos/vlfeat/matconvnet/issues/254","labels_url":"https://api.github.com/repos/vlfeat/matconvnet/issues/254/labels{/name}","comments_url":"https://api.github.com/repos/vlfeat/matconvnet/issues/254/comments","events_url":"https://api.github.com/repos/vlfeat/matconvnet/issues/254/events","html_url":"https://github.com/vlfeat/matconvnet/issues/254","id":103928877,"number":254,"title":"vl_imreadjpeg seems to be only \"semi\" asynchronous on Linux","user":{"login":"zoharby","id":6084508,"avatar_url":"https://avatars.githubusercontent.com/u/6084508?v=3","gravatar_id":"","url":"https://api.github.com/users/zoharby","html_url":"https://github.com/zoharby","followers_url":"https://api.github.com/users/zoharby/followers","following_url":"https://api.github.com/users/zoharby/following{/other_user}","gists_url":"https://api.github.com/users/zoharby/gists{/gist_id}","starred_url":"https://api.github.com/users/zoharby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoharby/subscriptions","organizations_url":"https://api.github.com/users/zoharby/orgs","repos_url":"https://api.github.com/users/zoharby/repos","events_url":"https://api.github.com/users/zoharby/events{/privacy}","received_events_url":"https://api.github.com/users/zoharby/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-30T14:42:18Z","updated_at":"2015-08-30T14:42:18Z","closed_at":null,"body":"I'm using matconvnet on an Ubuntu 14.04 machine. Currently data is on an HDD, which makes prefetching critical (will probably switch to SSD soon).\r\n\r\nI've added prefetching with vl_imreadjpeg, but it doesn't seem to be working as expected. \r\n\r\nHere's a snippet out of my batch preparation function:\r\n```\r\nif nargout == 0\r\n    % prefetch    \r\n    files = prefetchFiles;\r\n    tic\r\n    vl_imreadjpeg(files,'Prefetch','NumThreads',6,'Verbose') ;\r\n    fprintf('Prefetch: %.3f sec\\n',toc)\r\n    ims = [] ;\r\n    labels = [];\r\n    return ;\r\nend\r\n\r\nfiles = prefetchFiles;\r\ntic\r\nims = vl_imreadjpeg(files,'NumThreads',6,'Verbose') ;\r\nfprintf('Read: %.3f sec\\n',toc)\r\n```\r\n\r\nThe following debug prints illustrate the problem:\r\n```\r\n...\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  20 of 304 ... 0.71 s (140.3 images/s) PD 67.6% FA 32.6%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  21 of 304 ... 0.71 s (141.5 images/s) PD 67.4% FA 32.9%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  22 of 304 ... 0.71 s (141.6 images/s) PD 68.7% FA 32.4%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  23 of 304 ... 0.71 s (141.5 images/s) PD 68.4% FA 31.9%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  24 of 304 ... 0.71 s (141.5 images/s) PD 68.2% FA 31.6%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  25 of 304 ... 0.71 s (141.5 images/s) PD 66.2% FA 30.6%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  26 of 304 ... 0.71 s (141.7 images/s) PD 66.8% FA 30.9%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.002 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  27 of 304 ... 0.74 s (135.8 images/s) PD 67.3% FA 30.6%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  28 of 304 ... 0.71 s (140.3 images/s) PD 67.7% FA 30.6%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.001 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  29 of 304 ... 0.71 s (141.4 images/s) PD 67.4% FA 30.1%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.490 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  30 of 304 ... 1.21 s (82.8 images/s) PD 68.0% FA 30.6%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.390 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  31 of 304 ... 1.11 s (90.3 images/s) PD 68.4% FA 30.3%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.655 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  32 of 304 ... 1.38 s (72.6 images/s) PD 69.0% FA 30.4%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.533 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  33 of 304 ... 1.26 s (79.6 images/s) PD 69.1% FA 29.7%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.563 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  34 of 304 ... 1.29 s (77.7 images/s) PD 68.9% FA 29.1%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.579 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  35 of 304 ... 1.31 s (76.6 images/s) PD 69.5% FA 28.8%\r\nvl_imreadjpeg: numThreads = 6, prefetch = 0, preallocate = 1\r\nRead: 0.000 sec\r\nvl_imreadjpeg: numThreads = 6, prefetch = 1, preallocate = 1\r\nPrefetch: 0.445 sec\r\nCNNfst_w_lr0.01_reg0.0001 | training: epoch 02: done batch  36 of 304 ... 1.18 s (84.9 images/s) PD 69.6% FA 28.3%\r\n...\r\n```\r\n\r\nYou can notice that the \"Read\" time is always 0, indicating prefetching works. But, the \"Prefetch\" time is not always 0. It starts at 0 at the first batches, since another run I made just before caused the OS to cache those files to memory.\r\n\r\nBut, starting from batch 31 (the point where I stopped the previous run) the \"Prefetch\" times suddenly jump to high values.\r\n\r\nMy conclusion here is that only the JPEG decoding part is asynchronous, but reading the files from disk seems to be synchronous even in prefetch mode. \r\n\r\nThis was reproduced both on beta13 and on the devel branch."}}