<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Below code should work:</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"> </font></div><div class="gmail_default"><font face="monospace, monospace"> let boxedClosure = { (foo</font><span style="font-family:monospace,monospace">:inout MutableDeviceCollection</span><span style="font-family:monospace,monospace">) -> () in</span></div><div class="gmail_default"><font face="monospace, monospace"> device.sync { // 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: foo), .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="monospace, monospace"> }</font></div><div class="gmail_default"><font face="monospace, monospace"> </font></div><div class="gmail_default"><font face="monospace, monospace"> boxedClosure(&self)</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 5:12 PM, Richard Wei <span dir="ltr"><<a href="mailto:rxrwei@gmail.com" target="_blank">rxrwei@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The original file’s here:<br>
<a href="https://github.com/rxwei/cuda-swift/blob/master/Sources/Warp/CollectionOperations.swift" rel="noreferrer" target="_blank">https://github.com/rxwei/cuda-<wbr>swift/blob/master/Sources/<wbr>Warp/CollectionOperations.<wbr>swift</a><br>
<br>
I’m assuming this change has affected Dispatch users as well. It's not a good idea for such high-level APIs to rely on explicit pointers to pass mutating self for struct types.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Richard<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Dec 16, 2016, at 03:05, Richard Wei <<a href="mailto:rxrwei@gmail.com">rxrwei@gmail.com</a>> wrote:<br>
><br>
> It’s not the correct choice here :)<br>
><br>
>> On Dec 16, 2016, at 03:04, Rien <Rien@Balancingrock.nl> wrote:<br>
>><br>
>> Just because it is called “Unsafe” does not mean it is unsafe :-)<br>
>> It all depends on how you use it.<br>
>><br>
>> Regards,<br>
>> Rien<br>
>><br>
>> Site: <a href="http://balancingrock.nl" rel="noreferrer" target="_blank">http://balancingrock.nl</a><br>
>> Blog: <a href="http://swiftrien.blogspot.com" rel="noreferrer" target="_blank">http://swiftrien.blogspot.com</a><br>
>> Github: <a href="http://github.com/Swiftrien" rel="noreferrer" target="_blank">http://github.com/Swiftrien</a><br>
>> Project: <a href="http://swiftfire.nl" rel="noreferrer" target="_blank">http://swiftfire.nl</a><br>
>><br>
>><br>
>><br>
>><br>
>>> On 16 Dec 2016, at 09:52, Richard Wei <<a href="mailto:rxrwei@gmail.com">rxrwei@gmail.com</a>> wrote:<br>
>>><br>
>>> Zhao, it’s not a class.<br>
>>><br>
>>> Rien, unsafe pointers is the last thing I would ever want to introduce in my library…<br>
>>><br>
>>> Capturing self was clean, working perfectly, until Swift 3.0.2.<br>
>>><br>
>>> -Richard<br>
>>><br>
>>>> On Dec 16, 2016, at 02:49, Zhao Xin <<a href="mailto:owenzx@gmail.com">owenzx@gmail.com</a>> wrote:<br>
>>>><br>
>>>> What is the type of self? If it is a class, try [unowned self].<br>
>>>><br>
>>>> Zhaoxin<br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> On Fri, Dec 16, 2016 at 4:33 PM, Rien via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
>>>> How about using:<br>
>>>><br>
>>>> UnsafeMutablePointer<<wbr>TypeOfSelf><br>
>>>><br>
>>>> ?<br>
>>>><br>
>>>> Regards,<br>
>>>> Rien<br>
>>>><br>
>>>> Site: <a href="http://balancingrock.nl" rel="noreferrer" target="_blank">http://balancingrock.nl</a><br>
>>>> Blog: <a href="http://swiftrien.blogspot.com" rel="noreferrer" target="_blank">http://swiftrien.blogspot.com</a><br>
>>>> Github: <a href="http://github.com/Swiftrien" rel="noreferrer" target="_blank">http://github.com/Swiftrien</a><br>
>>>> Project: <a href="http://swiftfire.nl" rel="noreferrer" target="_blank">http://swiftfire.nl</a><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>>> On 16 Dec 2016, at 09:10, Richard Wei via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
>>>>><br>
>>>>> Capturing makes it immutable, which unfortunately can't solve this problem.<br>
>>>>><br>
>>>>> -Richard<br>
>>>>><br>
>>>>>> On Dec 16, 2016, at 02:05, Zhao Xin <<a href="mailto:owenzx@gmail.com">owenzx@gmail.com</a>> wrote:<br>
>>>>>><br>
>>>>>> I did not test the code. But if you cannot implicitly capture a mutating self, you should do it explicitly, right?<br>
>>>>>><br>
>>>>>> let blockSize = min(512, count)<br>
>>>>>> let blockCount = (count+blockSize-1)/blockSize<br>
>>>>>> device.sync { [self] () -> () in // Launch CUDA kernel<br>
>>>>>> try! fill<<<(blockSize, blockCount)>>>[<br>
>>>>>> .pointer(to: &self), .value(value), .value(Int64(count))<br>
>>>>>> ]<br>
>>>>>> }<br>
>>>>>><br>
>>>>>> Hope above code works.<br>
>>>>>><br>
>>>>>> Zhaoxin<br>
>>>>>><br>
>>>>>> On Fri, Dec 16, 2016 at 3:46 PM, Richard Wei via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
>>>>>> Hi,<br>
>>>>>><br>
>>>>>> 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?<br>
>>>>>><br>
>>>>>> let blockSize = min(512, count)<br>
>>>>>> let blockCount = (count+blockSize-1)/blockSize<br>
>>>>>> device.sync { // Launch CUDA kernel<br>
>>>>>> try! fill<<<(blockSize, blockCount)>>>[<br>
>>>>>> .pointer(to: &self), .value(value), .value(Int64(count))<br>
>>>>>> ]<br>
>>>>>> }<br>
>>>>>><br>
>>>>>> <PastedGraphic-1.png><br>
>>>>>><br>
>>>>>> -Richard<br>
>>>>>><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>
>>>>>><br>
>>>>><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>
>>>> ______________________________<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>
>>><br>
>><br>
><br>
<br>
</div></div></blockquote></div><br></div>