Skip to content

Commit

Permalink
Export map names
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravpandya committed Jan 25, 2025
1 parent aba4b6f commit e7565ae
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ namespace gpudrive
.def("expert_trajectory_tensor", &Manager::expertTrajectoryTensor)
.def("set_maps", &Manager::setMaps)
.def("world_means_tensor", &Manager::worldMeansTensor)
.def("metadata_tensor", &Manager::metadataTensor);
.def("metadata_tensor", &Manager::metadataTensor)
.def("map_name_tensor", &Manager::mapNameTensor);
}

}
2 changes: 2 additions & 0 deletions src/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace gpudrive
uint32_t numRoadSegments;
MapVector2 mean;

char mapName[32];

// Constructor
Map() = default;
};
Expand Down
3 changes: 3 additions & 0 deletions src/json_serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ namespace gpudrive

void from_json(const nlohmann::json &j, Map &map, float polylineReductionThreshold)
{
std::string name = j.at("name").get<std::string>();
std::strncpy(map.mapName, name.c_str(), sizeof(map.mapName));

auto mean = calc_mean(j);
map.mean = {mean.first, mean.second};
map.numObjects = std::min(j.at("objects").size(), static_cast<size_t>(MAX_OBJECTS));
Expand Down
7 changes: 7 additions & 0 deletions src/mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,13 @@ Tensor Manager::expertTrajectoryTensor() const {
{impl_->numWorlds, consts::kMaxAgentCount, TrajectoryExportSize});
}

Tensor Manager::mapNameTensor() const {
return impl_->exportTensor(
ExportID::MapName, TensorElementType::Int32,
{impl_->numWorlds, MapNameExportSize}
);
}

Tensor Manager::metadataTensor() const {
return impl_->exportTensor(
ExportID::MetaData, TensorElementType::Int32,
Expand Down
1 change: 1 addition & 0 deletions src/mgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Manager {
MGR_EXPORT madrona::py::Tensor expertTrajectoryTensor() const;
MGR_EXPORT madrona::py::Tensor worldMeansTensor() const;
MGR_EXPORT madrona::py::Tensor metadataTensor() const;
MGR_EXPORT madrona::py::Tensor mapNameTensor() const;
madrona::py::Tensor rgbTensor() const;
madrona::py::Tensor depthTensor() const;
// These functions are used by the viewer to control the simulation
Expand Down
7 changes: 7 additions & 0 deletions src/sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void Sim::registerTypes(ECSRegistry &registry, const Config &cfg)
registry.registerSingleton<Map>();
registry.registerSingleton<ResetMap>();
registry.registerSingleton<WorldMeans>();
registry.registerSingleton<MapName>();

registry.registerArchetype<Agent>();
registry.registerArchetype<PhysicsEntity>();
Expand All @@ -74,6 +75,7 @@ void Sim::registerTypes(ECSRegistry &registry, const Config &cfg)
registry.exportSingleton<Map>((uint32_t)ExportID::Map);
registry.exportSingleton<ResetMap>((uint32_t)ExportID::ResetMap);
registry.exportSingleton<WorldMeans>((uint32_t)ExportID::WorldMeans);
registry.exportSingleton<MapName>((uint32_t)ExportID::MapName);

registry.exportColumn<AgentInterface, Action>(
(uint32_t)ExportID::Action);
Expand Down Expand Up @@ -878,6 +880,11 @@ Sim::Sim(Engine &ctx,
RenderingSystem::init(ctx, cfg.renderBridge);
}

auto& mapName = ctx.singleton<MapName>();
for (int i = 0; i < sizeof(mapName.mapName); i++) {
mapName.mapName[i] = init.map->mapName[i];
}

auto& map = ctx.singleton<Map>();
map = *(init.map);
// Creates agents, walls, etc.
Expand Down
1 change: 1 addition & 0 deletions src/sim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum class ExportID : uint32_t {
ResetMap,
WorldMeans,
MetaData,
MapName,
NumExports
};

Expand Down
8 changes: 8 additions & 0 deletions src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ namespace gpudrive

static_assert(sizeof(AbsoluteSelfObservation) == sizeof(float) * AbsoluteSelfObservationExportSize);

struct MapName
{
char32_t mapName[32];
};

const size_t MapNameExportSize = 32;
static_assert(sizeof(MapName) == sizeof(char32_t) * MapNameExportSize);

//Metadata struct : using agent IDs.
struct MetaData
{
Expand Down

0 comments on commit e7565ae

Please sign in to comment.