<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Capturing makes it immutable, which unfortunately can't solve this problem.<div class=""><br class=""></div><div class="">-Richard<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 16, 2016, at 02:05, Zhao Xin <<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">I did not test the code. But if you cannot implicitly capture a mutating self, you should do it explicitly, right?</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace" class="">let blockSize = min(512, count)</font></div><div class="gmail_default"><font face="monospace, monospace" class="">let blockCount = (count+blockSize-1)/blockSize</font></div><div class="gmail_default"><font face="monospace, monospace" class="">device.sync { <b class="">[self] () -> () in</b> // Launch CUDA kernel</font></div><div class="gmail_default"><font face="monospace, monospace" class=""> try! fill<<<(blockSize, blockCount)>>>[</font></div><div class="gmail_default"><font face="monospace, monospace" class=""> .pointer(to: &self), .value(value), .value(Int64(count))</font></div><div class="gmail_default"><font face="monospace, monospace" class=""> ]</font></div><div class="gmail_default"><font face="monospace, monospace" class="">}</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">Hope above code works.</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">Zhaoxin</font></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Dec 16, 2016 at 3:46 PM, Richard Wei via swift-users <span dir="ltr" class=""><<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div style="margin:0px;font-size:11px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Hi,</span></div><div style="margin:0px;font-size:11px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin:0px;font-size:11px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Swift 3.0.2 seems to have broken my code due to mutating self capture. But I have to pass inout self to the closure. Any workaround?</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> blockSize = </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af" class="">min</span><span style="font-variant-ligatures:no-common-ligatures" class="">(512, </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af" class="">count</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> blockCount = (</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af" class="">count</span><span style="font-variant-ligatures:no-common-ligatures" class="">+blockSize-1)/blockSize</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af" class="">device</span><span style="font-variant-ligatures:no-common-ligatures" class="">.sync { // Launch CUDA kernel</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff" class="">try</span><span style="font-variant-ligatures:no-common-ligatures" class="">! fill<<<</span><span style="font-variant-ligatures:no-common-ligatures" class="">(blockSize, blockCount)>>>[</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> .pointer(to: &</span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">), .value(value), .value(</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af" class="">Int64</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af" class="">count</span><span style="font-variant-ligatures:no-common-ligatures" class="">))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> ]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span id="cid:609F752C-C004-45F5-8EB2-A1D0ECB1FE58@connectivityu.com"><PastedGraphic-1.png></span></span></div><span class="HOEnZb"><font color="#888888" class=""><div style="margin:0px;line-height:normal" class=""><span style="font-size:11px" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="font-size:11px" class="">-Richard</span></div></font></span></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></body></html>