{"id":5611,"date":"2018-01-03T13:42:03","date_gmt":"2018-01-03T13:42:03","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=5611"},"modified":"2018-01-03T13:42:03","modified_gmt":"2018-01-03T13:42:03","slug":"print-gpu-free-total-memory-java","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/print-gpu-free-total-memory-java\/","title":{"rendered":"Print GPU Free and Total Memory in Java"},"content":{"rendered":"<p>This requires jCUDA. At the time of writing, I wasn&#8217;t able to install through Maven (with a sbt dependency) but this is actively being looked at<sup><a href=\"#footnote_0_5611\" id=\"identifier_0_5611\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/github.com\/jcuda\/jcuda-main\/issues\/22\">1<\/a><\/sup><\/p>\n<pre lang=\"java\">\nlong total[] = { 0L };\nlong free[] = { 0L };\n  \nfor (int i = 0; i < deviceCount; i++)\n{\n  CUdevice device = new CUdevice();\n  cuDeviceGet(device, i);\n\n  cuInit(0);\n  cuDeviceGet(device, 0);\n  CUcontext context = new CUcontext();\n  cuCtxCreate(context, 0, device);\n\n  cuMemGetInfo(total, free);\n  System.out.println(\"Device \" + i + \": \" + name +\n    \" memory, total: \" + total[0] + \", free: \" + free[0]);\n}\n<\/pre>\n<ol class=\"footnotes\"><li id=\"footnote_0_5611\" class=\"footnote\">https:\/\/github.com\/jcuda\/jcuda-main\/issues\/22<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_0_5611\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>Print out GPU device memory in Java<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[131,300],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5611"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=5611"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5611\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=5611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=5611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=5611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}