Я внедряю полиморфизм на графическом процессоре с помощью std :: cuda :: variant , пока он работает с Circle, Square, Shape :
struct Circle;
struct Square;
using Shape = cuda::std::variant;
auto shape = gpu_allocate(1);
*shape = Circle(); //initialize Shape with Circle
< /code>
Но когда дело доходит до множественного наследования, я не смог найти способ инициализации переменной: < /p>
struct Color {
enum Type { red, blue };
Type type;
};
struct ColoredShape : Color, cuda::std::variant {};
auto colored_shape = gpu_allocate(1);
colored_shape->type = Color::red;
// *colored_shape = Circle(); // error
Итак, мой вопрос: как инициализировать цветную форму переменную с помощью круга ?
Полный код:
#include
struct Circle {
double radius = 0.9;
void init() { radius = 0.3; }
};
struct Square {
double x = -0.1;
double y = -0.3;
void init() {
x = 0.1;
y = 0.3;
}
};
struct Color {
enum Type { red, blue };
Type type;
};
using Shape = cuda::std::variant;
struct ColoredShape : Color, cuda::std::variant {};
template T *gpu_allocate(const size_t num = 1) {
T *data;
const auto size = sizeof(T) * num;
cudaMallocManaged(&data, size);
return data;
}
int main() {
auto shape = gpu_allocate(1);
*shape = Circle();
auto colored_shape = gpu_allocate(1);
colored_shape->type = Color::red;
// *colored_shape = Circle(); // error
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... stdvariant
Инициализировать подкласс Cuda :: std :: ⇐ C++
Программы на C++. Форум разработчиков
1747493280
Anonymous
Я внедряю полиморфизм на графическом процессоре с помощью std :: cuda :: variant , пока он работает с Circle, Square, Shape :
struct Circle;
struct Square;
using Shape = cuda::std::variant;
auto shape = gpu_allocate(1);
*shape = Circle(); //initialize Shape with Circle
< /code>
Но когда дело доходит до множественного наследования, я не смог найти способ инициализации переменной: < /p>
struct Color {
enum Type { red, blue };
Type type;
};
struct ColoredShape : Color, cuda::std::variant {};
auto colored_shape = gpu_allocate(1);
colored_shape->type = Color::red;
// *colored_shape = Circle(); // error
Итак, мой вопрос: как инициализировать цветную форму переменную с помощью круга ?
Полный код:
#include
struct Circle {
double radius = 0.9;
void init() { radius = 0.3; }
};
struct Square {
double x = -0.1;
double y = -0.3;
void init() {
x = 0.1;
y = 0.3;
}
};
struct Color {
enum Type { red, blue };
Type type;
};
using Shape = cuda::std::variant;
struct ColoredShape : Color, cuda::std::variant {};
template T *gpu_allocate(const size_t num = 1) {
T *data;
const auto size = sizeof(T) * num;
cudaMallocManaged(&data, size);
return data;
}
int main() {
auto shape = gpu_allocate(1);
*shape = Circle();
auto colored_shape = gpu_allocate(1);
colored_shape->type = Color::red;
// *colored_shape = Circle(); // error
return 0;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79626155/initialize-subclass-of-cudastdvariant[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия