GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added info_string by botev · Pull Request #102 · arrayfire/arrayfire-rust

Conversation

@botev

@botev botev commented Feb 13, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I've just added the linking and interface bit for af_info_string (also af_free_host and af_alloc_host). However, I'm not a 100% sure whether I need to call af_free_host and whether I'm doing that correctly, so definitely someone should take a look at that.

Following the discussion on the forum here in order to make Rust copy the string into rust allocated space I'm using to_str().to_owned() rather than into_string() and freeing the arrayfire buffer.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@botev
Added info_string
103681e
@pavanky

pavanky commented Feb 13, 2017

Copy link
Copy Markdown
Member

@botev While you are at it can you also add af_alloc_host ? It'll also be great if you can reduce the size of the second commit (and put the discussion link in the summary).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@botev
Added alloc_host and changed to use to_str -> to_owned
12d2231
@botev
botev force-pushed the devel branch from 9ac2200 to 12d2231 Compare February 13, 2017 09:15
@botev

botev commented Feb 14, 2017

Copy link
Copy Markdown
Contributor Author

Should be fixed now, I've amended the commit.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 14, 2017

Copy link
Copy Markdown
Member

@botev I don't think @pavanky meant just adding the interface to C-API alone. Shouldn't it be exposed to the crate user as well?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@botev

botev commented Feb 14, 2017

Copy link
Copy Markdown
Contributor Author

Ahh, that's a different story. I personally like the fact that currently the API hides all the messy-ness allocation and is pretty much defacto safe from Rust perspective.

If it is up to me I would not expose this kind of things, as it means that the actor must be aware that he might be messing with allocator space that is not part of the Rust (e.g. malloc vs jemmaloc). It is and why I explicitly copy the string to Rust space.

I guess that is more up to you guys really, but I don't feel in favour of such exposure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 14, 2017

Copy link
Copy Markdown
Member

@botev In that case, it is better to not expose this function at all. @pavanky What do you think ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Feb 14, 2017

Copy link
Copy Markdown
Member

@9prady9 I think it is still useful to keep it around for internal use. There may be some arrayfire functions that require calling this alloc and free.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 14, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@pavanky Do you mean we should expose it to user in rust wrapper ? I didn't understand what did you mean by internal use.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Feb 14, 2017

Copy link
Copy Markdown
Member

@9prady9 leave it inside the wrapper, no reason to expose it in rust as far as I can tell.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 14, 2017

Copy link
Copy Markdown
Member

@pavanky The reason i asked for clarification is - this addition of af_alloc_host in one module (in this case, device) doesn't export this symbol for use across other modules automatically. It would have to be declared again in the respective modules to use this function.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Feb 14, 2017

Copy link
Copy Markdown
Member

@botev @9prady9 hmm af_free_host may need to be called from other modules too. It may require a rust wrapper than. And so will af_alloc_host for consistency.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 14, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@pavanky I think a better way would be to put such functions in an internal module and use it in required modules rather than expose this at the wrapper level itself. This new module containing fns that we want internally will not be exposed to the user.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pavanky

pavanky commented Feb 14, 2017

Copy link
Copy Markdown
Member

@9prady9 That sounds reasonable too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 14, 2017

Copy link
Copy Markdown
Member

@botev Would it be possible for you to add such module and move this af_alloc_host and af_free_host into that module, and create functions alloc_host & free_host and use those functions in info_string ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@botev

botev commented Feb 14, 2017

Copy link
Copy Markdown
Contributor Author

@9prady9 sure that's fine. could you point me out where you want the module to be placed and how should I name it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 15, 2017

Copy link
Copy Markdown
Member

@botev At the same level (<arrayfire-rust>/src) as other modules except don't expose it in src/lib.rs using pub use. There is a header among arrayfire header files, therefore i want to refrain from using that name in this context just in case we might add the functions from that header in future.

If there is no keyword in rust such as private, lets go with module name private, otherwise use hidden.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@botev

botev commented Feb 15, 2017

Copy link
Copy Markdown
Contributor Author

@9prady9 So one option is to put in util but not expose via pub use in the main library. Or as you suggested private works fine, but I think util could fit the bill.

Also the DimT in array module is private, while I need it for af_alloc_host. I can either redefine it, use directly long long, however maybe that should not be private?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 15, 2017

Copy link
Copy Markdown
Member

@botev Sure, util will also do the job. Lets put it in util module.

Do you mean the type alias DimT ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@botev

botev commented Feb 15, 2017

Copy link
Copy Markdown
Contributor Author

Yes, currently this is how it looks:

// This is private in array
// use array::DimT;
type DimT = self::libc::c_longlong;

extern {
    fn af_alloc_host(ptr: *mut *mut c_void, bytes: DimT) -> c_int;
    fn af_free_host(ptr: *mut c_void) -> c_int;
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 15, 2017

Copy link
Copy Markdown
Member

This discussion about DimT made me think about the other type aliases in the project. Most of the modules do this type aliasing. May be we can abstract all the aliases into defines module and use them from there.

For this PR, you can declare the alias in the device module where you need it right now.

May be in a different PR we can move all type aliases into defines module and use them from there. It will be a tedious and time taking change. I can take care of it but If you want to take care it you can do it in this PR itself. Please let me know if you want to.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@botev
botev force-pushed the devel branch from 545ee8a to aa375fc Compare February 15, 2017 13:58
@botev
Added wrappers around af_alloc_host and af_free_host in the util …
1d80171
…module.
@botev
botev force-pushed the devel branch from aa375fc to 1d80171 Compare February 15, 2017 14:06
@botev

botev commented Feb 15, 2017

Copy link
Copy Markdown
Contributor Author

Ok so I think this should be done now. For any case please review the code that I'm not doing anything strange (for instance in af_alloc_host I'm not sure if the signature *mut *const c_void is correct).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9

9prady9 commented Feb 16, 2017

Copy link
Copy Markdown
Member

*const T in rust is equivalent of const T* in C, indicating a pointer to constant data. So, i think *mut *const c_void is just an address of a pointer to constant data and that should be valid usage in our case.

Sorry for the another request, but can you please replace 0 as *const T and 0 and *mut T with ptr::null().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@botev
Changed 0 as * to ::std::ptr::null.
80bfb4e
@botev

botev commented Feb 16, 2017

Copy link
Copy Markdown
Contributor Author

That should have it all fixed

9prady9 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@9prady9
9prady9 merged commit 33627c7 into arrayfire:devel Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@botev @pavanky @9prady9
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.