-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DeviceAPI::isAgent() DeviceAPI::isState() #1116
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
97a3fa3
DeviceAPI::isAgent() DeviceAPI::isState()
Robadob 7539dc2
add C test, it's a clone of Python test.
Robadob 6a2672d
Agent python
Robadob 5e15aeb
Unify the implementation of dstrcmp()
Robadob 1a7c2b5
Fix doc ci error
Robadob 86e82ec
C implementation and test fix
Robadob 83234ae
Fix docs CI
Robadob d58bef0
Place dstring.h inside namespace.
Robadob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef INCLUDE_FLAMEGPU_SIMULATION_DETAIL_DEVICESTRINGS_H_ | ||
#define INCLUDE_FLAMEGPU_SIMULATION_DETAIL_DEVICESTRINGS_H_ | ||
|
||
#include <string> | ||
#include <map> | ||
#include <sstream> | ||
|
||
namespace flamegpu { | ||
namespace detail { | ||
/** | ||
* Utility for copying strings to device | ||
*/ | ||
class DeviceStrings { | ||
public: | ||
/** | ||
* Deallocates held device pointers | ||
*/ | ||
~DeviceStrings(); | ||
/** | ||
* Register a device string | ||
*/ | ||
void registerDeviceString(const std::string &host_string); | ||
/** | ||
* Returns a device pointer to the provided string | ||
* @note If reallocation is required, earlier pointers may be invalidated | ||
*/ | ||
const char* getDeviceString(const std::string &host_string); | ||
|
||
private: | ||
std::stringstream host_stream; | ||
// Cache stream in a string to reduce stream->string repeat conversion during sim execution | ||
std::string host_buffer; | ||
// Hold the offset into buffer for all registered strings | ||
std::map<std::string, ptrdiff_t> offsets; | ||
char* device_buffer = nullptr; | ||
size_t device_buffer_occupied = 0; | ||
size_t device_buffer_len = 0; | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace flamegpu | ||
|
||
#endif // INCLUDE_FLAMEGPU_SIMULATION_DETAIL_DEVICESTRINGS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef INCLUDE_FLAMEGPU_UTIL_DSTRING_H_ | ||
#define INCLUDE_FLAMEGPU_UTIL_DSTRING_H_ | ||
|
||
#include <cuda_runtime.h> | ||
|
||
namespace flamegpu { | ||
namespace util { | ||
/** | ||
* Device implementations of required string.h functionality | ||
*/ | ||
|
||
|
||
/** | ||
* strcmp() - Compare two strings, return 0 if equal, otherwise return suggests order | ||
* | ||
* @param s1 First string to be compared | ||
* @param s2 Second string to be compared | ||
* | ||
* @note Implementation based on https://stackoverflow.com/a/34873763/1646387 | ||
*/ | ||
__device__ __forceinline__ int dstrcmp(const char *s1, const char *s2) { | ||
const unsigned char *p1 = (const unsigned char *)s1; | ||
const unsigned char *p2 = (const unsigned char *)s2; | ||
|
||
while (*p1 && *p1 == *p2) ++p1, ++p2; | ||
|
||
return (*p1 > *p2) - (*p2 > *p1); | ||
} | ||
|
||
} // namespace util | ||
} // namespace flamegpu | ||
|
||
#endif // INCLUDE_FLAMEGPU_UTIL_DSTRING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not be resolved at compile time for RTC due to the use of the while loop. If we really wanted to have this resolve at compile time we would have to find a way for this to work with
constexpr
or a through template recursion. I don't think this is necessary though and we should flag that string comparisons are not particularly fast in the docs.