File size: 3,662 Bytes
3c098f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading parquet files...\n",
      "Processing dataframes...\n",
      "\n",
      "Merging dataframes...\n",
      "\n",
      "Formatting output...\n",
      "\n",
      "Total pairs found: 216775\n",
      "\n",
      "Saving to parquet file...\n",
      "\n",
      "Sample pairs:\n",
      "                                   hip_filename  \\\n",
      "0  fcd394853732933cc2ddcf59fa29d561f0263cb1.hip   \n",
      "1  d654bdeca448d1a413a7cc87ccc3b4b7f18a965d.hip   \n",
      "2  464e3d1584f0013dfda51116d9aaaf21bd91bc13.hip   \n",
      "3  21a2390523ec5438ddf21ad9d91b04ae044ec944.hip   \n",
      "4  2b375ca1064061439fdc87fb32d664cc9434d26e.hip   \n",
      "\n",
      "                                 cuda_filename  \n",
      "0  fcd394853732933cc2ddcf59fa29d561f0263cb1.cu  \n",
      "1  d654bdeca448d1a413a7cc87ccc3b4b7f18a965d.cu  \n",
      "2  464e3d1584f0013dfda51116d9aaaf21bd91bc13.cu  \n",
      "3  21a2390523ec5438ddf21ad9d91b04ae044ec944.cu  \n",
      "4  2b375ca1064061439fdc87fb32d664cc9434d26e.cu  \n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import multiprocessing as mp\n",
    "from tqdm import tqdm\n",
    "\n",
    "def create_paired_dataset(cuda_df, hip_df):\n",
    "    print(\"Processing dataframes...\")\n",
    "    \n",
    "    # Create base names for both dataframes at once\n",
    "    cuda_df['base_name'] = cuda_df['filename'].str.replace(r'\\.cu[h]?$', '', regex=True)\n",
    "    hip_df['base_name'] = hip_df['filename'].str.replace(r'\\.hip$', '', regex=True)\n",
    "    \n",
    "    # Merge dataframes on base_name - this is much faster than iterative matching\n",
    "    print(\"\\nMerging dataframes...\")\n",
    "    paired_df = pd.merge(\n",
    "        hip_df,\n",
    "        cuda_df,\n",
    "        on='base_name',\n",
    "        suffixes=('_hip', '_cuda')\n",
    "    )\n",
    "    \n",
    "    # Rename columns to match desired output format\n",
    "    print(\"\\nFormatting output...\")\n",
    "    result_df = pd.DataFrame({\n",
    "        'hip_filename': paired_df['filename_hip'],\n",
    "        'hip_content': paired_df['content_hip'],\n",
    "        'cuda_filename': paired_df['filename_cuda'],\n",
    "        'cuda_content': paired_df['content_cuda']\n",
    "    })\n",
    "    \n",
    "    print(f\"\\nTotal pairs found: {len(result_df)}\")\n",
    "    \n",
    "    print(\"\\nSaving to parquet file...\")\n",
    "    result_df.to_parquet('cuda_hip_paired.parquet')\n",
    "    \n",
    "    print(\"\\nSample pairs:\")\n",
    "    print(result_df[['hip_filename', 'cuda_filename']].head())\n",
    "    return result_df\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    print(\"Reading parquet files...\")\n",
    "    cuda_df = pd.read_parquet('cuda_files.parquet')\n",
    "    hip_df = pd.read_parquet('hip_files.parquet')\n",
    "    create_paired_dataset(cuda_df, hip_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llava_med_v2",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}