<div dir="ltr"><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></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">let blockSize = min(512, count)</font></div><div class="gmail_default"><font face="monospace, monospace">let blockCount = (count+blockSize-1)/blockSize</font></div><div class="gmail_default"><font face="monospace, monospace">device.sync { <b>[self] () -> () in</b> // Launch CUDA kernel</font></div><div class="gmail_default"><font face="monospace, monospace"> try! fill<<<(blockSize, blockCount)>>>[</font></div><div class="gmail_default"><font face="monospace, monospace"> .pointer(to: &self), .value(value), .value(Int64(count))</font></div><div class="gmail_default"><font face="monospace, monospace"> ]</font></div><div class="gmail_default"><font face="monospace, monospace">}</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Hope above code works.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Zhaoxin</font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 16, 2016 at 3:46 PM, Richard Wei via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">Hi,</span></div><div style="margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">let</span><span style="font-variant-ligatures:no-common-ligatures"> blockSize = </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">min</span><span style="font-variant-ligatures:no-common-ligatures">(512, </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">count</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">let</span><span style="font-variant-ligatures:no-common-ligatures"> blockCount = (</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">count</span><span style="font-variant-ligatures:no-common-ligatures">+blockSize-1)/blockSize</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">device</span><span style="font-variant-ligatures:no-common-ligatures">.sync { // Launch CUDA kernel</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">try</span><span style="font-variant-ligatures:no-common-ligatures">! fill<<<</span><span style="font-variant-ligatures:no-common-ligatures">(blockSize, blockCount)>>>[</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> .pointer(to: &</span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">self</span><span style="font-variant-ligatures:no-common-ligatures">), .value(value), .value(</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Int64</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">count</span><span style="font-variant-ligatures:no-common-ligatures">))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> ]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><img id="m_-809470760834638155171C69807-0FFC-443D-8B4A-8C4D1A477885" src="cid:609F752C-C004-45F5-8EB2-A1D0ECB1FE58@connectivityu.com"></span></div><span class="HOEnZb"><font color="#888888"><div style="margin:0px;line-height:normal"><span style="font-size:11px"><br></span></div><div style="margin:0px;line-height:normal"><span style="font-size:11px">-Richard</span></div></font></span></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>